Mercurial > minori
comparison src/library/library.cc @ 231:69f4768a820c
chore: merge divergent branches
| author | Paper <paper@paper.us.eu.org> |
|---|---|
| date | Sat, 13 Jan 2024 09:43:41 -0500 |
| parents | d030b30526d5 |
| children | 862d0d8619f6 |
comparison
equal
deleted
inserted
replaced
| 230:2f5a9247e501 | 231:69f4768a820c |
|---|---|
| 7 | 7 |
| 8 #include <filesystem> | 8 #include <filesystem> |
| 9 #include <unordered_map> | 9 #include <unordered_map> |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include <iostream> | |
| 13 | |
| 14 namespace Library { | |
| 15 | |
| 12 // int = anime id, map = episode, paths | 16 // int = anime id, map = episode, paths |
| 13 std::unordered_map<int, std::unordered_map<int, std::string>> library; | 17 std::unordered_map<int, std::unordered_map<int, std::string>> library; |
| 14 | 18 |
| 15 void SearchLibraryFolders() { | 19 void SearchLibraryFolders() { |
| 16 library.clear(); | 20 library.clear(); |
| 17 | 21 |
| 18 for (const auto& spath : session.config.library.paths) { | 22 for (const auto& folder : session.config.library.paths) { |
| 19 const std::filesystem::path path(spath); | 23 for (const auto& entry : std::filesystem::recursive_directory_iterator(folder)) { |
| 20 for (const auto& entry : std::filesystem::recursive_directory_iterator(path)) { | 24 const std::filesystem::path path = entry.path(); |
| 21 if (!std::filesystem::is_regular_file(entry.path())) | 25 if (!std::filesystem::is_regular_file(path)) |
| 22 continue; | 26 continue; |
| 23 | 27 |
| 24 const std::string basename = path.filename(); | 28 const std::string basename = path.filename().u8string(); |
| 25 | 29 |
| 26 anitomy::Anitomy anitomy; | 30 anitomy::Anitomy anitomy; |
| 27 anitomy.Parse(Strings::ToWstring(basename)); | 31 anitomy.Parse(Strings::ToWstring(basename)); |
| 28 | 32 |
| 29 const auto& elements = anitomy.elements(); | 33 const auto& elements = anitomy.elements(); |
| 32 | 36 |
| 33 const int id = Anime::db.GetAnimeFromTitle(title); | 37 const int id = Anime::db.GetAnimeFromTitle(title); |
| 34 if (id <= 0) | 38 if (id <= 0) |
| 35 continue; | 39 continue; |
| 36 | 40 |
| 37 const int episode = Strings::ToInt(Strings::ToUtf8String(elements.get(anitomy::kElementAnimeTitle))); | 41 const int episode = Strings::ToInt(Strings::ToUtf8String(elements.get(anitomy::kElementEpisodeNumber))); |
| 38 | 42 |
| 39 // we have an ID now! | 43 // we have an ID now! |
| 40 library[id][episode] = entry.path(); | 44 library[id][episode] = path.u8string(); |
| 41 } | 45 } |
| 42 } | 46 } |
| 43 } | 47 } |
| 48 | |
| 49 } |
