annotate src/track/media.cc @ 135:0a458cb26ff4

filesystem: move to using std::filesystem after C++17 switch old compilers will croak compiling this, but it's not like we *really* need to support them (they probably croak compiling Qt as well)
author Paper <mrpapersonic@gmail.com>
date Thu, 09 Nov 2023 18:01:56 -0500
parents 39521c47c7a3
children 28842a8d0c6b
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"
118
39521c47c7a3 *: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents: 114
diff changeset
7 #include "core/session.h"
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>
118
39521c47c7a3 *: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents: 114
diff changeset
11 #include <iostream>
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
12
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
13 namespace Track {
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
14 namespace Media {
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
15
135
0a458cb26ff4 filesystem: move to using std::filesystem after C++17 switch
Paper <mrpapersonic@gmail.com>
parents: 118
diff changeset
16 std::vector<std::filesystem::path> GetCurrentlyPlayingFiles() {
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
17 /* getting all open files */
135
0a458cb26ff4 filesystem: move to using std::filesystem after C++17 switch
Paper <mrpapersonic@gmail.com>
parents: 118
diff changeset
18 std::vector<std::filesystem::path> ret;
118
39521c47c7a3 *: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents: 114
diff changeset
19
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
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
2004b41d4a59 *: huge commit
Paper <mrpapersonic@gmail.com>
parents: 82
diff changeset
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))) {
135
0a458cb26ff4 filesystem: move to using std::filesystem after C++17 switch
Paper <mrpapersonic@gmail.com>
parents: 118
diff changeset
27 const std::filesystem::path path(file);
118
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)
135
0a458cb26ff4 filesystem: move to using std::filesystem after C++17 switch
Paper <mrpapersonic@gmail.com>
parents: 118
diff changeset
30 if (path.extension() == ext.GetExtension())
118
39521c47c7a3 *: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents: 114
diff changeset
31 ret.push_back(path);
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
32 }
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
33 }
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
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
135
0a458cb26ff4 filesystem: move to using std::filesystem after C++17 switch
Paper <mrpapersonic@gmail.com>
parents: 118
diff changeset
39 std::filesystem::path GetCurrentPlaying() {
118
39521c47c7a3 *: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents: 114
diff changeset
40 /* getting all open files */
135
0a458cb26ff4 filesystem: move to using std::filesystem after C++17 switch
Paper <mrpapersonic@gmail.com>
parents: 118
diff changeset
41 std::vector<std::filesystem::path> paths = GetCurrentlyPlayingFiles();
118
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);
135
0a458cb26ff4 filesystem: move to using std::filesystem after C++17 switch
Paper <mrpapersonic@gmail.com>
parents: 118
diff changeset
44 return std::filesystem::path();
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
45 }
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
46
80
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 78
diff changeset
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
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 78
diff changeset
49 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
50 std::unordered_map<std::string, std::string> ret;
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 78
diff changeset
51
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 78
diff changeset
52 ret["title"] = Strings::ToUtf8String(elements.get(anitomy::kElementAnimeTitle));
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 78
diff changeset
53 ret["filename"] = Strings::ToUtf8String(elements.get(anitomy::kElementFileName));
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 78
diff changeset
54 ret["language"] = Strings::ToUtf8String(elements.get(anitomy::kElementLanguage));
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 78
diff changeset
55 ret["group"] = Strings::ToUtf8String(elements.get(anitomy::kElementReleaseGroup));
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 78
diff changeset
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
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 78
diff changeset
58
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 78
diff changeset
59 return ret;
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 78
diff changeset
60 }
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 78
diff changeset
61
135
0a458cb26ff4 filesystem: move to using std::filesystem after C++17 switch
Paper <mrpapersonic@gmail.com>
parents: 118
diff changeset
62 std::unordered_map<std::string, std::string> GetFileElements(const std::string& basename) {
114
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
135
0a458cb26ff4 filesystem: move to using std::filesystem after C++17 switch
Paper <mrpapersonic@gmail.com>
parents: 118
diff changeset
69 std::unordered_map<std::string, std::string> GetFileElements(const std::filesystem::path& path) {
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
70 anitomy::Anitomy anitomy;
135
0a458cb26ff4 filesystem: move to using std::filesystem after C++17 switch
Paper <mrpapersonic@gmail.com>
parents: 118
diff changeset
71 anitomy.Parse(path.filename().wstring());
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
72
80
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 78
diff changeset
73 return GetMapFromElements(anitomy.elements());
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
74 }
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
75
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
76 } // namespace Media
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
77 } // namespace Track