Mercurial > minori
annotate src/track/media.cc @ 118:39521c47c7a3
*: another huge megacommit, SORRY
The torrents page works a lot better now
Added the edit option to the anime list right click menu
Vectorized currently playing files
Available player and extensions are now loaded at runtime
from files in (dotpath)/players.json and (dotpath)/extensions.json
These paths are not permanent and will likely be moved to
(dotpath)/recognition
...
...
...
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Tue, 07 Nov 2023 23:40:54 -0500 |
parents | ab191e28e69d |
children | 0a458cb26ff4 |
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" | |
118
39521c47c7a3
*: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
7 #include "core/session.h" |
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> |
118
39521c47c7a3
*: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
11 #include <iostream> |
64 | 12 |
13 namespace Track { | |
14 namespace Media { | |
15 | |
118
39521c47c7a3
*: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
16 std::vector<Filesystem::Path> GetCurrentlyPlayingFiles() { |
64 | 17 /* getting all open files */ |
118
39521c47c7a3
*: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
18 std::vector<Filesystem::Path> ret; |
39521c47c7a3
*: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
19 |
64 | 20 std::vector<int> pids = Animia::get_all_pids(); |
118
39521c47c7a3
*: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
21 for (int pid : pids) { |
39521c47c7a3
*: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
22 for (const Types::MediaPlayer& player : session.recognition.players) { |
39521c47c7a3
*: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
23 if (!player.GetEnabled() || Animia::get_process_name(pid) != player.GetExecutable()) |
108 | 24 continue; |
118
39521c47c7a3
*: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
25 |
39521c47c7a3
*: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
26 for (const std::string& file : Animia::filter_system_files(Animia::get_open_files(pid))) { |
39521c47c7a3
*: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
27 const Filesystem::Path path(file); |
39521c47c7a3
*: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
28 |
39521c47c7a3
*: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
29 for (const Types::MediaExtension& ext : session.recognition.extensions) |
39521c47c7a3
*: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
30 if (path.Extension() == ext.GetExtension()) |
39521c47c7a3
*: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
31 ret.push_back(path); |
64 | 32 } |
33 } | |
34 } | |
118
39521c47c7a3
*: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
35 |
39521c47c7a3
*: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
36 return ret; |
39521c47c7a3
*: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
37 } |
39521c47c7a3
*: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
38 |
39521c47c7a3
*: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
39 Filesystem::Path GetCurrentPlaying() { |
39521c47c7a3
*: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
40 /* getting all open files */ |
39521c47c7a3
*: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
41 std::vector<Filesystem::Path> paths = GetCurrentlyPlayingFiles(); |
39521c47c7a3
*: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
42 if (paths.size()) |
39521c47c7a3
*: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents:
114
diff
changeset
|
43 return paths.at(0); |
64 | 44 return Filesystem::Path(); |
45 } | |
46 | |
80 | 47 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
|
48 /* there are way more than this in anitomy, but we only need basic information |
80 | 49 I also just prefer using maps than using the ".get()" stuff which is why I'm doing this */ |
50 std::unordered_map<std::string, std::string> ret; | |
51 | |
52 ret["title"] = Strings::ToUtf8String(elements.get(anitomy::kElementAnimeTitle)); | |
53 ret["filename"] = Strings::ToUtf8String(elements.get(anitomy::kElementFileName)); | |
54 ret["language"] = Strings::ToUtf8String(elements.get(anitomy::kElementLanguage)); | |
55 ret["group"] = Strings::ToUtf8String(elements.get(anitomy::kElementReleaseGroup)); | |
56 ret["episode"] = Strings::ToUtf8String(elements.get(anitomy::kElementEpisodeNumber)); | |
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
57 ret["resolution"] = Strings::ToUtf8String(elements.get(anitomy::kElementVideoResolution)); |
80 | 58 |
59 return ret; | |
60 } | |
61 | |
114
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
62 std::unordered_map<std::string, std::string> GetFileElements(std::string basename) { |
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
63 anitomy::Anitomy anitomy; |
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
64 anitomy.Parse(Strings::ToWstring(basename)); |
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
65 |
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
66 return GetMapFromElements(anitomy.elements()); |
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
67 } |
ab191e28e69d
*: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents:
108
diff
changeset
|
68 |
80 | 69 std::unordered_map<std::string, std::string> GetFileElements(Filesystem::Path path) { |
64 | 70 anitomy::Anitomy anitomy; |
71 anitomy.Parse(Strings::ToWstring(path.Basename())); | |
72 | |
80 | 73 return GetMapFromElements(anitomy.elements()); |
64 | 74 } |
75 | |
76 } // namespace Media | |
77 } // namespace Track |