annotate src/track/media.cc @ 139:478f3b366199

dep/animia: separate lots of things, use base class for OS stuff
author Paper <mrpapersonic@gmail.com>
date Sun, 12 Nov 2023 16:43:07 -0500
parents 28842a8d0c6b
children 6fdf0632c003
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>
138
28842a8d0c6b dep/animia: huge refactor (again...)
Paper <mrpapersonic@gmail.com>
parents: 135
diff changeset
12 #include <QFile>
139
478f3b366199 dep/animia: separate lots of things, use base class for OS stuff
Paper <mrpapersonic@gmail.com>
parents: 138
diff changeset
13 #include <QTextStream>
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
14
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
15 namespace Track {
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
16 namespace Media {
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
17
138
28842a8d0c6b dep/animia: huge refactor (again...)
Paper <mrpapersonic@gmail.com>
parents: 135
diff changeset
18 static bool GetCurrentlyPlayingResults(std::vector<animia::Result>& results) {
28842a8d0c6b dep/animia: huge refactor (again...)
Paper <mrpapersonic@gmail.com>
parents: 135
diff changeset
19 std::vector<animia::Player> players;
28842a8d0c6b dep/animia: huge refactor (again...)
Paper <mrpapersonic@gmail.com>
parents: 135
diff changeset
20
28842a8d0c6b dep/animia: huge refactor (again...)
Paper <mrpapersonic@gmail.com>
parents: 135
diff changeset
21 {
28842a8d0c6b dep/animia: huge refactor (again...)
Paper <mrpapersonic@gmail.com>
parents: 135
diff changeset
22 QFile f(":/players.anisthesia");
28842a8d0c6b dep/animia: huge refactor (again...)
Paper <mrpapersonic@gmail.com>
parents: 135
diff changeset
23 if (!f.exists())
28842a8d0c6b dep/animia: huge refactor (again...)
Paper <mrpapersonic@gmail.com>
parents: 135
diff changeset
24 return false;
28842a8d0c6b dep/animia: huge refactor (again...)
Paper <mrpapersonic@gmail.com>
parents: 135
diff changeset
25
28842a8d0c6b dep/animia: huge refactor (again...)
Paper <mrpapersonic@gmail.com>
parents: 135
diff changeset
26 f.open(QFile::ReadOnly | QFile::Text);
28842a8d0c6b dep/animia: huge refactor (again...)
Paper <mrpapersonic@gmail.com>
parents: 135
diff changeset
27 QTextStream ts(&f);
28842a8d0c6b dep/animia: huge refactor (again...)
Paper <mrpapersonic@gmail.com>
parents: 135
diff changeset
28
28842a8d0c6b dep/animia: huge refactor (again...)
Paper <mrpapersonic@gmail.com>
parents: 135
diff changeset
29 if (!animia::ParsePlayersData(Strings::ToUtf8String(ts.readAll()), players))
28842a8d0c6b dep/animia: huge refactor (again...)
Paper <mrpapersonic@gmail.com>
parents: 135
diff changeset
30 return false;
28842a8d0c6b dep/animia: huge refactor (again...)
Paper <mrpapersonic@gmail.com>
parents: 135
diff changeset
31 }
28842a8d0c6b dep/animia: huge refactor (again...)
Paper <mrpapersonic@gmail.com>
parents: 135
diff changeset
32
28842a8d0c6b dep/animia: huge refactor (again...)
Paper <mrpapersonic@gmail.com>
parents: 135
diff changeset
33 if (!animia::GetResults(players, results))
28842a8d0c6b dep/animia: huge refactor (again...)
Paper <mrpapersonic@gmail.com>
parents: 135
diff changeset
34 return false;
118
39521c47c7a3 *: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents: 114
diff changeset
35
138
28842a8d0c6b dep/animia: huge refactor (again...)
Paper <mrpapersonic@gmail.com>
parents: 135
diff changeset
36 return true;
28842a8d0c6b dep/animia: huge refactor (again...)
Paper <mrpapersonic@gmail.com>
parents: 135
diff changeset
37 }
28842a8d0c6b dep/animia: huge refactor (again...)
Paper <mrpapersonic@gmail.com>
parents: 135
diff changeset
38
28842a8d0c6b dep/animia: huge refactor (again...)
Paper <mrpapersonic@gmail.com>
parents: 135
diff changeset
39 /* meh */
28842a8d0c6b dep/animia: huge refactor (again...)
Paper <mrpapersonic@gmail.com>
parents: 135
diff changeset
40 bool GetCurrentlyPlaying(std::vector<std::string>& vec) {
28842a8d0c6b dep/animia: huge refactor (again...)
Paper <mrpapersonic@gmail.com>
parents: 135
diff changeset
41 std::vector<animia::Result> results;
118
39521c47c7a3 *: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents: 114
diff changeset
42
138
28842a8d0c6b dep/animia: huge refactor (again...)
Paper <mrpapersonic@gmail.com>
parents: 135
diff changeset
43 if (!GetCurrentlyPlayingResults(results))
28842a8d0c6b dep/animia: huge refactor (again...)
Paper <mrpapersonic@gmail.com>
parents: 135
diff changeset
44 return false;
28842a8d0c6b dep/animia: huge refactor (again...)
Paper <mrpapersonic@gmail.com>
parents: 135
diff changeset
45
28842a8d0c6b dep/animia: huge refactor (again...)
Paper <mrpapersonic@gmail.com>
parents: 135
diff changeset
46 bool success = false;
118
39521c47c7a3 *: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents: 114
diff changeset
47
138
28842a8d0c6b dep/animia: huge refactor (again...)
Paper <mrpapersonic@gmail.com>
parents: 135
diff changeset
48 for (const auto& result : results) {
28842a8d0c6b dep/animia: huge refactor (again...)
Paper <mrpapersonic@gmail.com>
parents: 135
diff changeset
49 for (const auto& media : result.media) {
28842a8d0c6b dep/animia: huge refactor (again...)
Paper <mrpapersonic@gmail.com>
parents: 135
diff changeset
50 for (const auto& info : media.information) {
28842a8d0c6b dep/animia: huge refactor (again...)
Paper <mrpapersonic@gmail.com>
parents: 135
diff changeset
51 vec.push_back(info.value);
28842a8d0c6b dep/animia: huge refactor (again...)
Paper <mrpapersonic@gmail.com>
parents: 135
diff changeset
52 success |= true;
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
53 }
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
54 }
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
55 }
118
39521c47c7a3 *: another huge megacommit, SORRY
Paper <mrpapersonic@gmail.com>
parents: 114
diff changeset
56
138
28842a8d0c6b dep/animia: huge refactor (again...)
Paper <mrpapersonic@gmail.com>
parents: 135
diff changeset
57 return success;
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
58 }
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
59
80
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 78
diff changeset
60 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
61 /* 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
62 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
63 std::unordered_map<std::string, std::string> ret;
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 78
diff changeset
64
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 78
diff changeset
65 ret["title"] = Strings::ToUtf8String(elements.get(anitomy::kElementAnimeTitle));
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 78
diff changeset
66 ret["filename"] = Strings::ToUtf8String(elements.get(anitomy::kElementFileName));
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 78
diff changeset
67 ret["language"] = Strings::ToUtf8String(elements.get(anitomy::kElementLanguage));
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 78
diff changeset
68 ret["group"] = Strings::ToUtf8String(elements.get(anitomy::kElementReleaseGroup));
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 78
diff changeset
69 ret["episode"] = Strings::ToUtf8String(elements.get(anitomy::kElementEpisodeNumber));
114
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 108
diff changeset
70 ret["resolution"] = Strings::ToUtf8String(elements.get(anitomy::kElementVideoResolution));
80
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 78
diff changeset
71
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 78
diff changeset
72 return ret;
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 78
diff changeset
73 }
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 78
diff changeset
74
135
0a458cb26ff4 filesystem: move to using std::filesystem after C++17 switch
Paper <mrpapersonic@gmail.com>
parents: 118
diff changeset
75 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
76 anitomy::Anitomy anitomy;
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 108
diff changeset
77 anitomy.Parse(Strings::ToWstring(basename));
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 108
diff changeset
78
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 108
diff changeset
79 return GetMapFromElements(anitomy.elements());
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 108
diff changeset
80 }
ab191e28e69d *: add initial torrent stuff
Paper <mrpapersonic@gmail.com>
parents: 108
diff changeset
81
135
0a458cb26ff4 filesystem: move to using std::filesystem after C++17 switch
Paper <mrpapersonic@gmail.com>
parents: 118
diff changeset
82 std::unordered_map<std::string, std::string> GetFileElements(const std::filesystem::path& path) {
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
83 anitomy::Anitomy anitomy;
135
0a458cb26ff4 filesystem: move to using std::filesystem after C++17 switch
Paper <mrpapersonic@gmail.com>
parents: 118
diff changeset
84 anitomy.Parse(path.filename().wstring());
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
85
80
825506f0e221 [UNFINISHED]: stuff
Paper <mrpapersonic@gmail.com>
parents: 78
diff changeset
86 return GetMapFromElements(anitomy.elements());
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
87 }
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
88
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
89 } // namespace Media
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
90 } // namespace Track