Mercurial > minori
view src/track/media.cc @ 137:69db40272acd
dep/animia: [WIP] huge refactor
this WILL NOT compile, because lots of code has been changed
and every API in the original codebase has been removed.
note that this api setup is not exactly permanent...
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Fri, 10 Nov 2023 13:52:47 -0500 |
parents | 0a458cb26ff4 |
children | 28842a8d0c6b |
line wrap: on
line source
#include "track/media.h" #include "track/constants.h" #include "animia.h" #include "anitomy/anitomy.h" #include "core/filesystem.h" #include "core/strings.h" #include "core/session.h" #include <string> #include <unordered_map> #include <vector> #include <iostream> namespace Track { namespace Media { std::vector<std::filesystem::path> GetCurrentlyPlayingFiles() { /* getting all open files */ std::vector<std::filesystem::path> ret; std::vector<int> pids = Animia::get_all_pids(); for (int pid : pids) { for (const Types::MediaPlayer& player : session.recognition.players) { if (!player.GetEnabled() || Animia::get_process_name(pid) != player.GetExecutable()) continue; for (const std::string& file : Animia::filter_system_files(Animia::get_open_files(pid))) { const std::filesystem::path path(file); for (const Types::MediaExtension& ext : session.recognition.extensions) if (path.extension() == ext.GetExtension()) ret.push_back(path); } } } return ret; } std::filesystem::path GetCurrentPlaying() { /* getting all open files */ std::vector<std::filesystem::path> paths = GetCurrentlyPlayingFiles(); if (paths.size()) return paths.at(0); return std::filesystem::path(); } std::unordered_map<std::string, std::string> GetMapFromElements(const anitomy::Elements& elements) { /* there are way more than this in anitomy, but we only need basic information I also just prefer using maps than using the ".get()" stuff which is why I'm doing this */ std::unordered_map<std::string, std::string> ret; ret["title"] = Strings::ToUtf8String(elements.get(anitomy::kElementAnimeTitle)); ret["filename"] = Strings::ToUtf8String(elements.get(anitomy::kElementFileName)); ret["language"] = Strings::ToUtf8String(elements.get(anitomy::kElementLanguage)); ret["group"] = Strings::ToUtf8String(elements.get(anitomy::kElementReleaseGroup)); ret["episode"] = Strings::ToUtf8String(elements.get(anitomy::kElementEpisodeNumber)); ret["resolution"] = Strings::ToUtf8String(elements.get(anitomy::kElementVideoResolution)); return ret; } std::unordered_map<std::string, std::string> GetFileElements(const std::string& basename) { anitomy::Anitomy anitomy; anitomy.Parse(Strings::ToWstring(basename)); return GetMapFromElements(anitomy.elements()); } std::unordered_map<std::string, std::string> GetFileElements(const std::filesystem::path& path) { anitomy::Anitomy anitomy; anitomy.Parse(path.filename().wstring()); return GetMapFromElements(anitomy.elements()); } } // namespace Media } // namespace Track