Mercurial > minori
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 134:54c9d36207db | 135:0a458cb26ff4 |
|---|---|
| 11 #include <iostream> | 11 #include <iostream> |
| 12 | 12 |
| 13 namespace Track { | 13 namespace Track { |
| 14 namespace Media { | 14 namespace Media { |
| 15 | 15 |
| 16 std::vector<Filesystem::Path> GetCurrentlyPlayingFiles() { | 16 std::vector<std::filesystem::path> GetCurrentlyPlayingFiles() { |
| 17 /* getting all open files */ | 17 /* getting all open files */ |
| 18 std::vector<Filesystem::Path> ret; | 18 std::vector<std::filesystem::path> ret; |
| 19 | 19 |
| 20 std::vector<int> pids = Animia::get_all_pids(); | 20 std::vector<int> pids = Animia::get_all_pids(); |
| 21 for (int pid : pids) { | 21 for (int pid : pids) { |
| 22 for (const Types::MediaPlayer& player : session.recognition.players) { | 22 for (const Types::MediaPlayer& player : session.recognition.players) { |
| 23 if (!player.GetEnabled() || Animia::get_process_name(pid) != player.GetExecutable()) | 23 if (!player.GetEnabled() || Animia::get_process_name(pid) != player.GetExecutable()) |
| 24 continue; | 24 continue; |
| 25 | 25 |
| 26 for (const std::string& file : Animia::filter_system_files(Animia::get_open_files(pid))) { | 26 for (const std::string& file : Animia::filter_system_files(Animia::get_open_files(pid))) { |
| 27 const Filesystem::Path path(file); | 27 const std::filesystem::path path(file); |
| 28 | 28 |
| 29 for (const Types::MediaExtension& ext : session.recognition.extensions) | 29 for (const Types::MediaExtension& ext : session.recognition.extensions) |
| 30 if (path.Extension() == ext.GetExtension()) | 30 if (path.extension() == ext.GetExtension()) |
| 31 ret.push_back(path); | 31 ret.push_back(path); |
| 32 } | 32 } |
| 33 } | 33 } |
| 34 } | 34 } |
| 35 | 35 |
| 36 return ret; | 36 return ret; |
| 37 } | 37 } |
| 38 | 38 |
| 39 Filesystem::Path GetCurrentPlaying() { | 39 std::filesystem::path GetCurrentPlaying() { |
| 40 /* getting all open files */ | 40 /* getting all open files */ |
| 41 std::vector<Filesystem::Path> paths = GetCurrentlyPlayingFiles(); | 41 std::vector<std::filesystem::path> paths = GetCurrentlyPlayingFiles(); |
| 42 if (paths.size()) | 42 if (paths.size()) |
| 43 return paths.at(0); | 43 return paths.at(0); |
| 44 return Filesystem::Path(); | 44 return std::filesystem::path(); |
| 45 } | 45 } |
| 46 | 46 |
| 47 std::unordered_map<std::string, std::string> GetMapFromElements(const anitomy::Elements& elements) { | 47 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 | 48 /* 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 */ | 49 I also just prefer using maps than using the ".get()" stuff which is why I'm doing this */ |
| 57 ret["resolution"] = Strings::ToUtf8String(elements.get(anitomy::kElementVideoResolution)); | 57 ret["resolution"] = Strings::ToUtf8String(elements.get(anitomy::kElementVideoResolution)); |
| 58 | 58 |
| 59 return ret; | 59 return ret; |
| 60 } | 60 } |
| 61 | 61 |
| 62 std::unordered_map<std::string, std::string> GetFileElements(std::string basename) { | 62 std::unordered_map<std::string, std::string> GetFileElements(const std::string& basename) { |
| 63 anitomy::Anitomy anitomy; | 63 anitomy::Anitomy anitomy; |
| 64 anitomy.Parse(Strings::ToWstring(basename)); | 64 anitomy.Parse(Strings::ToWstring(basename)); |
| 65 | 65 |
| 66 return GetMapFromElements(anitomy.elements()); | 66 return GetMapFromElements(anitomy.elements()); |
| 67 } | 67 } |
| 68 | 68 |
| 69 std::unordered_map<std::string, std::string> GetFileElements(Filesystem::Path path) { | 69 std::unordered_map<std::string, std::string> GetFileElements(const std::filesystem::path& path) { |
| 70 anitomy::Anitomy anitomy; | 70 anitomy::Anitomy anitomy; |
| 71 anitomy.Parse(Strings::ToWstring(path.Basename())); | 71 anitomy.Parse(path.filename().wstring()); |
| 72 | 72 |
| 73 return GetMapFromElements(anitomy.elements()); | 73 return GetMapFromElements(anitomy.elements()); |
| 74 } | 74 } |
| 75 | 75 |
| 76 } // namespace Media | 76 } // namespace Media |
