Mercurial > minori
comparison src/library/library.cc @ 366:886f66775f31
animone: add preliminary AT-SPI stuff
anime_list: finish the regular singular right click menu
author | Paper <paper@tflc.us> |
---|---|
date | Sun, 17 Nov 2024 19:56:01 -0500 |
parents | a0aa8c8c4307 |
children |
comparison
equal
deleted
inserted
replaced
365:f81bed4e04ac | 366:886f66775f31 |
---|---|
11 | 11 |
12 #include <iostream> | 12 #include <iostream> |
13 | 13 |
14 namespace Library { | 14 namespace Library { |
15 | 15 |
16 void Database::Refresh() { | 16 std::optional<std::filesystem::path> Database::GetAnimeFolder(int id) { |
17 // this function sucks, but it's the most I can really do for now. | |
18 // | |
19 // in the future the Refresh() function should look for directories | |
20 // as well that fit the anime name and *also* have episodes in them. | |
21 // it should give each of these directories a rating by how many | |
22 // episodes are contained in them. whichever directory has more episodes | |
23 // wins, or the first found if there is an equal amount. | |
24 | |
25 for (const auto& [anime_id, episodes] : items) { | |
26 if (id != anime_id) | |
27 continue; | |
28 | |
29 for (const auto& [episode, path] : episodes) { | |
30 return path.parent_path(); | |
31 break; | |
32 } | |
33 | |
34 break; | |
35 } | |
36 | |
37 return std::nullopt; | |
38 } | |
39 | |
40 void Database::Refresh(std::optional<int> find_id) { | |
17 items.clear(); | 41 items.clear(); |
18 | 42 |
19 for (const auto& folder : session.config.library.paths) { | 43 for (const auto& folder : session.config.library.paths) { |
20 for (const auto& entry : std::filesystem::recursive_directory_iterator(folder)) { | 44 for (const auto& entry : std::filesystem::recursive_directory_iterator(folder)) { |
21 const std::filesystem::path path = entry.path(); | 45 const std::filesystem::path path = entry.path(); |
30 const auto& elements = anitomy.elements(); | 54 const auto& elements = anitomy.elements(); |
31 | 55 |
32 const std::string title = Strings::ToUtf8String(elements.get(anitomy::kElementAnimeTitle)); | 56 const std::string title = Strings::ToUtf8String(elements.get(anitomy::kElementAnimeTitle)); |
33 | 57 |
34 const int id = Anime::db.LookupAnimeTitle(title); | 58 const int id = Anime::db.LookupAnimeTitle(title); |
35 if (id <= 0) | 59 if (id <= 0 || (find_id && find_id.value() != id)) |
36 continue; | 60 continue; |
37 | 61 |
38 const int episode = Strings::ToInt<int>(Strings::ToUtf8String(elements.get(anitomy::kElementEpisodeNumber))); | 62 const int episode = Strings::ToInt<int>(Strings::ToUtf8String(elements.get(anitomy::kElementEpisodeNumber))); |
39 | 63 |
40 // we have an ID now! | 64 // we have an ID now! |
41 items[id][episode] = path; | 65 items[id][episode] = path; |
42 } | 66 } |
43 } | 67 } |
44 } | 68 } |
45 | 69 |
70 void Database::Refresh() { | |
71 Refresh(std::nullopt); | |
72 } | |
73 | |
74 void Database::Refresh(int id) { | |
75 Refresh(std::optional<int>(id)); | |
76 } | |
77 | |
78 // TODO export to JSON | |
79 | |
46 Database db; | 80 Database db; |
47 | 81 |
48 } // namespace Library | 82 } // namespace Library |