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
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"
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
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
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
9 #include <vector>
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
10
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
11 namespace Track {
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
12 namespace Media {
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
13
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
14 Filesystem::Path GetCurrentPlaying() {
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
15 /* getting all open files */
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
16 std::vector<int> pids = Animia::get_all_pids();
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
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
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 82
diff changeset
19 if (Animia::get_process_name(i) != player)
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 82
diff changeset
20 continue;
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 82
diff changeset
21 for (const std::string& f : Animia::filter_system_files(Animia::get_open_files(i))) {
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 82
diff changeset
22 Filesystem::Path p(f);
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 82
diff changeset
23 for (const std::string& ext : media_extensions) {
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 82
diff changeset
24 if (p.Extension() == ext)
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 82
diff changeset
25 return p;
82
8b65c417c225 *: fix old stuff, make video players and extensions constants
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
26 }
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
27 }
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
28 }
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
29 }
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
30 return Filesystem::Path();
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
31 }
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
32
80
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 78
diff changeset
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
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 78
diff changeset
35 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
36 std::unordered_map<std::string, std::string> ret;
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 78
diff changeset
37
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 78
diff changeset
38 ret["title"] = Strings::ToUtf8String(elements.get(anitomy::kElementAnimeTitle));
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 78
diff changeset
39 ret["filename"] = Strings::ToUtf8String(elements.get(anitomy::kElementFileName));
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 78
diff changeset
40 ret["language"] = Strings::ToUtf8String(elements.get(anitomy::kElementLanguage));
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 78
diff changeset
41 ret["group"] = Strings::ToUtf8String(elements.get(anitomy::kElementReleaseGroup));
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 78
diff changeset
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
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 78
diff changeset
44
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 78
diff changeset
45 return ret;
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 78
diff changeset
46 }
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 78
diff changeset
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
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 78
diff changeset
55 std::unordered_map<std::string, std::string> GetFileElements(Filesystem::Path path) {
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
56 anitomy::Anitomy anitomy;
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
57 anitomy.Parse(Strings::ToWstring(path.Basename()));
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
58
80
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 78
diff changeset
59 return GetMapFromElements(anitomy.elements());
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
60 }
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
61
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
62 } // namespace Media
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
63 } // namespace Track