Mercurial > minori
view src/library/library.cc @ 241:06d6c351925c
*: reorganize resources, +docs, build translations with autotools
author | Paper <paper@paper.us.eu.org> |
---|---|
date | Mon, 22 Jan 2024 16:36:19 -0500 |
parents | d030b30526d5 |
children | 862d0d8619f6 |
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& folder : session.config.library.paths) { for (const auto& entry : std::filesystem::recursive_directory_iterator(folder)) { const std::filesystem::path path = entry.path(); if (!std::filesystem::is_regular_file(path)) continue; const std::string basename = path.filename().u8string(); 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] = path.u8string(); } } } }