Mercurial > minori
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 |
rev | line source |
---|---|
64 | 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 | 3 #include "animia.h" |
4 #include "anitomy/anitomy.h" | |
64 | 5 #include "core/filesystem.h" |
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 | 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 | 10 #include <vector> |
11 | |
12 namespace Track { | |
13 namespace Media { | |
14 | |
15 Filesystem::Path GetCurrentPlaying() { | |
16 /* getting all open files */ | |
17 std::vector<int> pids = Animia::get_all_pids(); | |
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 | 29 } |
30 } | |
31 } | |
32 return Filesystem::Path(); | |
33 } | |
34 | |
80 | 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 | 37 I also just prefer using maps than using the ".get()" stuff which is why I'm doing this */ |
38 std::unordered_map<std::string, std::string> ret; | |
39 | |
40 ret["title"] = Strings::ToUtf8String(elements.get(anitomy::kElementAnimeTitle)); | |
41 ret["filename"] = Strings::ToUtf8String(elements.get(anitomy::kElementFileName)); | |
42 ret["language"] = Strings::ToUtf8String(elements.get(anitomy::kElementLanguage)); | |
43 ret["group"] = Strings::ToUtf8String(elements.get(anitomy::kElementReleaseGroup)); | |
44 ret["episode"] = Strings::ToUtf8String(elements.get(anitomy::kElementEpisodeNumber)); | |
45 | |
46 return ret; | |
47 } | |
48 | |
49 std::unordered_map<std::string, std::string> GetFileElements(Filesystem::Path path) { | |
64 | 50 anitomy::Anitomy anitomy; |
51 anitomy.Parse(Strings::ToWstring(path.Basename())); | |
52 | |
80 | 53 return GetMapFromElements(anitomy.elements()); |
64 | 54 } |
55 | |
56 } // namespace Media | |
57 } // namespace Track |