Mercurial > minori
comparison src/track/media.cc @ 138:28842a8d0c6b
dep/animia: huge refactor (again...)
but this time, it actually compiles! and it WORKS! (on win32... not sure about
other platforms...)
configuring players is still not supported: at some point I'll prune something
up...
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Sun, 12 Nov 2023 04:53:19 -0500 |
parents | 0a458cb26ff4 |
children | 478f3b366199 |
comparison
equal
deleted
inserted
replaced
137:69db40272acd | 138:28842a8d0c6b |
---|---|
7 #include "core/session.h" | 7 #include "core/session.h" |
8 #include <string> | 8 #include <string> |
9 #include <unordered_map> | 9 #include <unordered_map> |
10 #include <vector> | 10 #include <vector> |
11 #include <iostream> | 11 #include <iostream> |
12 #include <QFile> | |
12 | 13 |
13 namespace Track { | 14 namespace Track { |
14 namespace Media { | 15 namespace Media { |
15 | 16 |
16 std::vector<std::filesystem::path> GetCurrentlyPlayingFiles() { | 17 static bool GetCurrentlyPlayingResults(std::vector<animia::Result>& results) { |
17 /* getting all open files */ | 18 std::vector<animia::Player> players; |
18 std::vector<std::filesystem::path> ret; | |
19 | 19 |
20 std::vector<int> pids = Animia::get_all_pids(); | 20 { |
21 for (int pid : pids) { | 21 QFile f(":/players.anisthesia"); |
22 for (const Types::MediaPlayer& player : session.recognition.players) { | 22 if (!f.exists()) |
23 if (!player.GetEnabled() || Animia::get_process_name(pid) != player.GetExecutable()) | 23 return false; |
24 continue; | |
25 | 24 |
26 for (const std::string& file : Animia::filter_system_files(Animia::get_open_files(pid))) { | 25 f.open(QFile::ReadOnly | QFile::Text); |
27 const std::filesystem::path path(file); | 26 QTextStream ts(&f); |
28 | 27 |
29 for (const Types::MediaExtension& ext : session.recognition.extensions) | 28 if (!animia::ParsePlayersData(Strings::ToUtf8String(ts.readAll()), players)) |
30 if (path.extension() == ext.GetExtension()) | 29 return false; |
31 ret.push_back(path); | 30 } |
31 | |
32 if (!animia::GetResults(players, results)) | |
33 return false; | |
34 | |
35 return true; | |
36 } | |
37 | |
38 /* meh */ | |
39 bool GetCurrentlyPlaying(std::vector<std::string>& vec) { | |
40 std::vector<animia::Result> results; | |
41 | |
42 if (!GetCurrentlyPlayingResults(results)) | |
43 return false; | |
44 | |
45 bool success = false; | |
46 | |
47 for (const auto& result : results) { | |
48 for (const auto& media : result.media) { | |
49 for (const auto& info : media.information) { | |
50 vec.push_back(info.value); | |
51 success |= true; | |
32 } | 52 } |
33 } | 53 } |
34 } | 54 } |
35 | 55 |
36 return ret; | 56 return success; |
37 } | |
38 | |
39 std::filesystem::path GetCurrentPlaying() { | |
40 /* getting all open files */ | |
41 std::vector<std::filesystem::path> paths = GetCurrentlyPlayingFiles(); | |
42 if (paths.size()) | |
43 return paths.at(0); | |
44 return std::filesystem::path(); | |
45 } | 57 } |
46 | 58 |
47 std::unordered_map<std::string, std::string> GetMapFromElements(const anitomy::Elements& elements) { | 59 std::unordered_map<std::string, std::string> GetMapFromElements(const anitomy::Elements& elements) { |
48 /* there are way more than this in anitomy, but we only need basic information | 60 /* there are way more than this in anitomy, but we only need basic information |
49 I also just prefer using maps than using the ".get()" stuff which is why I'm doing this */ | 61 I also just prefer using maps than using the ".get()" stuff which is why I'm doing this */ |