Mercurial > minori
annotate src/track/media.cc @ 117:2c1b6782e1d0
pages/torrents: work around conversion error on Linux
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Tue, 07 Nov 2023 16:06:17 -0500 |
parents | ab191e28e69d |
children | 39521c47c7a3 |
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" | |
7 #include <string> | |
82
8b65c417c225
*: fix old stuff, make video players and extensions constants
Paper <mrpapersonic@gmail.com>
parents:
81
diff
changeset
|
8 #include <unordered_map> |
64 | 9 #include <vector> |
10 | |
11 namespace Track { | |
12 namespace Media { | |
13 | |
14 Filesystem::Path GetCurrentPlaying() { | |
15 /* getting all open files */ | |
16 std::vector<int> pids = Animia::get_all_pids(); | |
17 for (int i : pids) { | |
82
8b65c417c225
*: fix old stuff, make video players and extensions constants
Paper <mrpapersonic@gmail.com>
parents:
81
diff
changeset
|
18 for (const std::string& player : media_players) { |
108 | 19 if (Animia::get_process_name(i) != player) |
20 continue; | |
21 for (const std::string& f : Animia::filter_system_files(Animia::get_open_files(i))) { | |
22 Filesystem::Path p(f); | |
23 for (const std::string& ext : media_extensions) { | |
24 if (p.Extension() == ext) | |
25 return p; | |
82
8b65c417c225
*: fix old stuff, make video players and extensions constants
Paper <mrpapersonic@gmail.com>
parents:
81
diff
changeset
|
26 } |
64 | 27 } |
28 } | |
29 } | |
30 return Filesystem::Path(); | |
31 } | |
32 | |
80 | 33 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
|
34 /* there are way more than this in anitomy, but we only need basic information |
80 | 35 I also just prefer using maps than using the ".get()" stuff which is why I'm doing this */ |
36 std::unordered_map<std::string, std::string> ret; | |
37 | |
38 ret["title"] = Strings::ToUtf8String(elements.get(anitomy::kElementAnimeTitle)); | |
39 ret["filename"] = Strings::ToUtf8String(elements.get(anitomy::kElementFileName)); | |
40 ret["language"] = Strings::ToUtf8String(elements.get(anitomy::kElementLanguage)); | |
41 ret["group"] = Strings::ToUtf8String(elements.get(anitomy::kElementReleaseGroup)); | |
42 ret["episode"] = Strings::ToUtf8String(elements.get(anitomy::kElementEpisodeNumber)); | |
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
43 ret["resolution"] = Strings::ToUtf8String(elements.get(anitomy::kElementVideoResolution)); |
80 | 44 |
45 return ret; | |
46 } | |
47 | |
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
48 std::unordered_map<std::string, std::string> GetFileElements(std::string basename) { |
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
49 anitomy::Anitomy anitomy; |
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
50 anitomy.Parse(Strings::ToWstring(basename)); |
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
51 |
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
52 return GetMapFromElements(anitomy.elements()); |
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
53 } |
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
54 |
80 | 55 std::unordered_map<std::string, std::string> GetFileElements(Filesystem::Path path) { |
64 | 56 anitomy::Anitomy anitomy; |
57 anitomy.Parse(Strings::ToWstring(path.Basename())); | |
58 | |
80 | 59 return GetMapFromElements(anitomy.elements()); |
64 | 60 } |
61 | |
62 } // namespace Media | |
63 } // namespace Track |