annotate src/track/media.cc @ 101:c537996cf67b

*: multitude of config changes 1. theme is now configurable from the settings menu (but you have to restart for it to apply) 2. config is now stored in an INI file, with no method of conversion from json (this repo is private-ish anyway)
author Paper <mrpapersonic@gmail.com>
date Fri, 03 Nov 2023 14:06:02 -0400
parents 8b65c417c225
children 2004b41d4a59
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
1 #include "track/media.h"
82
8b65c417c225 *: fix old stuff, make video players and extensions constants
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
2 #include "track/constants.h"
76
3364fadc8a36 *: format source code
Paper <mrpapersonic@gmail.com>
parents: 64
diff changeset
3 #include "animia.h"
3364fadc8a36 *: format source code
Paper <mrpapersonic@gmail.com>
parents: 64
diff changeset
4 #include "anitomy/anitomy.h"
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
5 #include "core/filesystem.h"
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
6 #include "core/strings.h"
82
8b65c417c225 *: fix old stuff, make video players and extensions constants
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
7 #include <QDebug>
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
8 #include <string>
82
8b65c417c225 *: fix old stuff, make video players and extensions constants
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
9 #include <unordered_map>
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
10 #include <vector>
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
11
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
12 namespace Track {
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
13 namespace Media {
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
14
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
15 Filesystem::Path GetCurrentPlaying() {
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
16 /* getting all open files */
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
17 std::vector<int> pids = Animia::get_all_pids();
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
18 for (int i : pids) {
82
8b65c417c225 *: fix old stuff, make video players and extensions constants
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
19 for (const std::string& player : media_players) {
8b65c417c225 *: fix old stuff, make video players and extensions constants
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
20 if (Animia::get_process_name(i) == player) {
8b65c417c225 *: fix old stuff, make video players and extensions constants
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
21 std::vector<std::string> files = Animia::filter_system_files(Animia::get_open_files(i));
8b65c417c225 *: fix old stuff, make video players and extensions constants
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
22 for (const std::string& f : files) {
8b65c417c225 *: fix old stuff, make video players and extensions constants
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
23 Filesystem::Path p(f);
8b65c417c225 *: fix old stuff, make video players and extensions constants
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
24 for (const std::string& ext : media_extensions) {
8b65c417c225 *: fix old stuff, make video players and extensions constants
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
25 if (p.Extension() == ext)
8b65c417c225 *: fix old stuff, make video players and extensions constants
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
26 return p;
8b65c417c225 *: fix old stuff, make video players and extensions constants
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
27 }
8b65c417c225 *: fix old stuff, make video players and extensions constants
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
28 }
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
29 }
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
30 }
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
31 }
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
32 return Filesystem::Path();
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
33 }
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
34
80
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 78
diff changeset
35 std::unordered_map<std::string, std::string> GetMapFromElements(const anitomy::Elements& elements) {
82
8b65c417c225 *: fix old stuff, make video players and extensions constants
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
36 /* there are way more than this in anitomy, but we only need basic information
80
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 78
diff changeset
37 I also just prefer using maps than using the ".get()" stuff which is why I'm doing this */
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 78
diff changeset
38 std::unordered_map<std::string, std::string> ret;
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 78
diff changeset
39
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 78
diff changeset
40 ret["title"] = Strings::ToUtf8String(elements.get(anitomy::kElementAnimeTitle));
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 78
diff changeset
41 ret["filename"] = Strings::ToUtf8String(elements.get(anitomy::kElementFileName));
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 78
diff changeset
42 ret["language"] = Strings::ToUtf8String(elements.get(anitomy::kElementLanguage));
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 78
diff changeset
43 ret["group"] = Strings::ToUtf8String(elements.get(anitomy::kElementReleaseGroup));
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 78
diff changeset
44 ret["episode"] = Strings::ToUtf8String(elements.get(anitomy::kElementEpisodeNumber));
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 78
diff changeset
45
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 78
diff changeset
46 return ret;
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 78
diff changeset
47 }
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 78
diff changeset
48
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 78
diff changeset
49 std::unordered_map<std::string, std::string> GetFileElements(Filesystem::Path path) {
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
50 anitomy::Anitomy anitomy;
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
51 anitomy.Parse(Strings::ToWstring(path.Basename()));
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
52
80
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 78
diff changeset
53 return GetMapFromElements(anitomy.elements());
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
54 }
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
55
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
56 } // namespace Media
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
57 } // namespace Track