Mercurial > minori
view src/library/library.cc @ 328:71396ecb6f7e
library: convert to class + database
it also stores std::filesystem::paths now...
author | Paper <paper@paper.us.eu.org> |
---|---|
date | Fri, 14 Jun 2024 00:37:45 -0400 |
parents | d928ec7b6a0d |
children | a0aa8c8c4307 |
line wrap: on
line source
#include "library/library.h" #include "core/anime_db.h" #include "core/session.h" #include "core/strings.h" #include "anitomy/anitomy.h" #include <filesystem> #include <string> #include <unordered_map> #include <iostream> namespace Library { void Database::Refresh() { items.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.LookupAnimeTitle(title); if (id <= 0) continue; const int episode = Strings::ToInt<int>(Strings::ToUtf8String(elements.get(anitomy::kElementEpisodeNumber))); // we have an ID now! items[id][episode] = path; } } } Database db; } // namespace Library