Mercurial > minori
diff src/library/library.cc @ 222:b9f111d84d95
*: move to semver, remove old macos build, add library files
I'm retarded and can't commit files right
author | Paper <paper@paper.us.eu.org> |
---|---|
date | Mon, 08 Jan 2024 13:22:09 -0500 |
parents | |
children | 84e0a3c4737a |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/library/library.cc Mon Jan 08 13:22:09 2024 -0500 @@ -0,0 +1,43 @@ +#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(); + } + } +}