comparison 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
comparison
equal deleted inserted replaced
221:53211cb1e7f5 222:b9f111d84d95
1 #include "library/library.h"
2 #include "core/anime_db.h"
3 #include "core/strings.h"
4 #include "core/session.h"
5
6 #include "anitomy/anitomy.h"
7
8 #include <filesystem>
9 #include <unordered_map>
10 #include <string>
11
12 // int = anime id, map = episode, paths
13 std::unordered_map<int, std::unordered_map<int, std::string>> library;
14
15 void SearchLibraryFolders() {
16 library.clear();
17
18 for (const auto& spath : session.config.library.paths) {
19 const std::filesystem::path path(spath);
20 for (const auto& entry : std::filesystem::recursive_directory_iterator(path)) {
21 if (!std::filesystem::is_regular_file(entry.path()))
22 continue;
23
24 const std::string basename = path.filename();
25
26 anitomy::Anitomy anitomy;
27 anitomy.Parse(Strings::ToWstring(basename));
28
29 const auto& elements = anitomy.elements();
30
31 const std::string title = Strings::ToUtf8String(elements.get(anitomy::kElementAnimeTitle));
32
33 const int id = Anime::db.GetAnimeFromTitle(title);
34 if (id <= 0)
35 continue;
36
37 const int episode = Strings::ToInt(Strings::ToUtf8String(elements.get(anitomy::kElementAnimeTitle)));
38
39 // we have an ID now!
40 library[id][episode] = entry.path();
41 }
42 }
43 }