comparison src/track/media.cc @ 82:8b65c417c225

*: fix old stuff, make video players and extensions constants
author Paper <mrpapersonic@gmail.com>
date Mon, 23 Oct 2023 13:37:42 -0400
parents 9b2b41f83a5e
children 2004b41d4a59
comparison
equal deleted inserted replaced
81:9b2b41f83a5e 82:8b65c417c225
1 #include "track/media.h" 1 #include "track/media.h"
2 #include "track/constants.h"
2 #include "animia.h" 3 #include "animia.h"
3 #include "anitomy/anitomy.h" 4 #include "anitomy/anitomy.h"
4 #include "core/filesystem.h" 5 #include "core/filesystem.h"
5 #include "core/strings.h" 6 #include "core/strings.h"
7 #include <QDebug>
6 #include <string> 8 #include <string>
9 #include <unordered_map>
7 #include <vector> 10 #include <vector>
8 #include <unordered_map>
9 #include <QDebug>
10 11
11 namespace Track { 12 namespace Track {
12 namespace Media { 13 namespace Media {
13 14
14 Filesystem::Path GetCurrentPlaying() { 15 Filesystem::Path GetCurrentPlaying() {
15 /* getting all open files */ 16 /* getting all open files */
16 std::vector<int> pids = Animia::get_all_pids(); 17 std::vector<int> pids = Animia::get_all_pids();
17 for (int i : pids) { 18 for (int i : pids) {
18 if (Animia::get_process_name(i) == "vlc") { 19 for (const std::string& player : media_players) {
19 std::vector<std::string> files = Animia::filter_system_files(Animia::get_open_files(i)); 20 if (Animia::get_process_name(i) == player) {
20 for (std::string s : files) { 21 std::vector<std::string> files = Animia::filter_system_files(Animia::get_open_files(i));
21 qDebug() << Strings::ToQString(s); 22 for (const std::string& f : files) {
22 Filesystem::Path p(s); 23 Filesystem::Path p(f);
23 if (p.Extension() == "mp4") 24 for (const std::string& ext : media_extensions) {
24 return p; 25 if (p.Extension() == ext)
26 return p;
27 }
28 }
25 } 29 }
26 } 30 }
27 } 31 }
28 return Filesystem::Path(); 32 return Filesystem::Path();
29 } 33 }
30 34
31 std::unordered_map<std::string, std::string> GetMapFromElements(const anitomy::Elements& elements) { 35 std::unordered_map<std::string, std::string> GetMapFromElements(const anitomy::Elements& elements) {
32 /* there are way more than this in anitomy, but we only need basic information 36 /* there are way more than this in anitomy, but we only need basic information
33 I also just prefer using maps than using the ".get()" stuff which is why I'm doing this */ 37 I also just prefer using maps than using the ".get()" stuff which is why I'm doing this */
34 std::unordered_map<std::string, std::string> ret; 38 std::unordered_map<std::string, std::string> ret;
35 39
36 ret["title"] = Strings::ToUtf8String(elements.get(anitomy::kElementAnimeTitle)); 40 ret["title"] = Strings::ToUtf8String(elements.get(anitomy::kElementAnimeTitle));
37 ret["filename"] = Strings::ToUtf8String(elements.get(anitomy::kElementFileName)); 41 ret["filename"] = Strings::ToUtf8String(elements.get(anitomy::kElementFileName));