Mercurial > minori
annotate src/library/library.cc @ 319:d928ec7b6a0d
services/kitsu: implement GetAnimeList()
it finally works!
author | Paper <paper@paper.us.eu.org> |
---|---|
date | Wed, 12 Jun 2024 17:52:26 -0400 |
parents | 862d0d8619f6 |
children | 71396ecb6f7e |
rev | line source |
---|---|
222
b9f111d84d95
*: move to semver, remove old macos build, add library files
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
1 #include "library/library.h" |
b9f111d84d95
*: move to semver, remove old macos build, add library files
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
2 #include "core/anime_db.h" |
258 | 3 #include "core/session.h" |
222
b9f111d84d95
*: move to semver, remove old macos build, add library files
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
4 #include "core/strings.h" |
b9f111d84d95
*: move to semver, remove old macos build, add library files
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
5 |
b9f111d84d95
*: move to semver, remove old macos build, add library files
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
6 #include "anitomy/anitomy.h" |
b9f111d84d95
*: move to semver, remove old macos build, add library files
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
7 |
b9f111d84d95
*: move to semver, remove old macos build, add library files
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
8 #include <filesystem> |
258 | 9 #include <string> |
222
b9f111d84d95
*: move to semver, remove old macos build, add library files
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
10 #include <unordered_map> |
b9f111d84d95
*: move to semver, remove old macos build, add library files
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
11 |
223
84e0a3c4737a
library: implement menu bar buttons
Paper <mrpapersonic@gmail.com>
parents:
222
diff
changeset
|
12 #include <iostream> |
84e0a3c4737a
library: implement menu bar buttons
Paper <mrpapersonic@gmail.com>
parents:
222
diff
changeset
|
13 |
84e0a3c4737a
library: implement menu bar buttons
Paper <mrpapersonic@gmail.com>
parents:
222
diff
changeset
|
14 namespace Library { |
84e0a3c4737a
library: implement menu bar buttons
Paper <mrpapersonic@gmail.com>
parents:
222
diff
changeset
|
15 |
222
b9f111d84d95
*: move to semver, remove old macos build, add library files
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
16 // int = anime id, map = episode, paths |
b9f111d84d95
*: move to semver, remove old macos build, add library files
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
17 std::unordered_map<int, std::unordered_map<int, std::string>> library; |
b9f111d84d95
*: move to semver, remove old macos build, add library files
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
18 |
b9f111d84d95
*: move to semver, remove old macos build, add library files
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
19 void SearchLibraryFolders() { |
b9f111d84d95
*: move to semver, remove old macos build, add library files
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
20 library.clear(); |
b9f111d84d95
*: move to semver, remove old macos build, add library files
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
21 |
228
d030b30526d5
config: remove unused username parameter from anilist auth
Paper <mrpapersonic@gmail.com>
parents:
227
diff
changeset
|
22 for (const auto& folder : session.config.library.paths) { |
d030b30526d5
config: remove unused username parameter from anilist auth
Paper <mrpapersonic@gmail.com>
parents:
227
diff
changeset
|
23 for (const auto& entry : std::filesystem::recursive_directory_iterator(folder)) { |
d030b30526d5
config: remove unused username parameter from anilist auth
Paper <mrpapersonic@gmail.com>
parents:
227
diff
changeset
|
24 const std::filesystem::path path = entry.path(); |
d030b30526d5
config: remove unused username parameter from anilist auth
Paper <mrpapersonic@gmail.com>
parents:
227
diff
changeset
|
25 if (!std::filesystem::is_regular_file(path)) |
222
b9f111d84d95
*: move to semver, remove old macos build, add library files
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
26 continue; |
b9f111d84d95
*: move to semver, remove old macos build, add library files
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
27 |
228
d030b30526d5
config: remove unused username parameter from anilist auth
Paper <mrpapersonic@gmail.com>
parents:
227
diff
changeset
|
28 const std::string basename = path.filename().u8string(); |
222
b9f111d84d95
*: move to semver, remove old macos build, add library files
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
29 |
b9f111d84d95
*: move to semver, remove old macos build, add library files
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
30 anitomy::Anitomy anitomy; |
b9f111d84d95
*: move to semver, remove old macos build, add library files
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
31 anitomy.Parse(Strings::ToWstring(basename)); |
b9f111d84d95
*: move to semver, remove old macos build, add library files
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
32 |
b9f111d84d95
*: move to semver, remove old macos build, add library files
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
33 const auto& elements = anitomy.elements(); |
b9f111d84d95
*: move to semver, remove old macos build, add library files
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
34 |
b9f111d84d95
*: move to semver, remove old macos build, add library files
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
35 const std::string title = Strings::ToUtf8String(elements.get(anitomy::kElementAnimeTitle)); |
b9f111d84d95
*: move to semver, remove old macos build, add library files
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
36 |
319
d928ec7b6a0d
services/kitsu: implement GetAnimeList()
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
37 const int id = Anime::db.LookupAnimeTitle(title); |
222
b9f111d84d95
*: move to semver, remove old macos build, add library files
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
38 if (id <= 0) |
b9f111d84d95
*: move to semver, remove old macos build, add library files
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
39 continue; |
b9f111d84d95
*: move to semver, remove old macos build, add library files
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
40 |
223
84e0a3c4737a
library: implement menu bar buttons
Paper <mrpapersonic@gmail.com>
parents:
222
diff
changeset
|
41 const int episode = Strings::ToInt(Strings::ToUtf8String(elements.get(anitomy::kElementEpisodeNumber))); |
222
b9f111d84d95
*: move to semver, remove old macos build, add library files
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
42 |
b9f111d84d95
*: move to semver, remove old macos build, add library files
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
43 // we have an ID now! |
228
d030b30526d5
config: remove unused username parameter from anilist auth
Paper <mrpapersonic@gmail.com>
parents:
227
diff
changeset
|
44 library[id][episode] = path.u8string(); |
222
b9f111d84d95
*: move to semver, remove old macos build, add library files
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
45 } |
b9f111d84d95
*: move to semver, remove old macos build, add library files
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
46 } |
b9f111d84d95
*: move to semver, remove old macos build, add library files
Paper <paper@paper.us.eu.org>
parents:
diff
changeset
|
47 } |
223
84e0a3c4737a
library: implement menu bar buttons
Paper <mrpapersonic@gmail.com>
parents:
222
diff
changeset
|
48 |
258 | 49 } // namespace Library |