Mercurial > minori
view src/library/library.cc @ 230:2f5a9247e501
torrents: implement download button
erg
author | Paper <paper@paper.us.eu.org> |
---|---|
date | Sat, 13 Jan 2024 09:42:02 -0500 |
parents | b9f111d84d95 |
children | 84e0a3c4737a |
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> // 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 = 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::kElementAnimeTitle))); // we have an ID now! library[id][episode] = entry.path(); } } }