Mercurial > minori
view src/library/library.cc @ 224:7ca56c4ac0bc
about: don't abuse QCoreApplication:tr
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Mon, 08 Jan 2024 17:05:08 -0500 |
parents | 84e0a3c4737a |
children | c4f03f83b252 |
line wrap: on
line source
#include "library/library.h" #include "core/anime_db.h" #include "core/strings.h" #include "core/session.h" #include "anitomy/anitomy.h" #include <filesystem> #include <unordered_map> #include <string> #include <iostream> namespace Library { // int = anime id, map = episode, paths std::unordered_map<int, std::unordered_map<int, std::string>> library; void SearchLibraryFolders() { library.clear(); for (const auto& spath : session.config.library.paths) { const std::filesystem::path path(spath); for (const auto& entry : std::filesystem::recursive_directory_iterator(path)) { if (!std::filesystem::is_regular_file(entry.path())) continue; const std::string basename = entry.path().filename(); anitomy::Anitomy anitomy; anitomy.Parse(Strings::ToWstring(basename)); const auto& elements = anitomy.elements(); const std::string title = Strings::ToUtf8String(elements.get(anitomy::kElementAnimeTitle)); const int id = Anime::db.GetAnimeFromTitle(title); if (id <= 0) continue; const int episode = Strings::ToInt(Strings::ToUtf8String(elements.get(anitomy::kElementEpisodeNumber))); // we have an ID now! library[id][episode] = entry.path(); } } } }