annotate src/library/library.cc @ 367:8d45d892be88 default tip

*: instead of pugixml, use Qt XML features this means we have one extra Qt dependency though...
author Paper <paper@tflc.us>
date Sun, 17 Nov 2024 22:55:47 -0500
parents 886f66775f31
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 228
diff changeset
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
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 228
diff changeset
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
366
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents: 347
diff changeset
16 std::optional<std::filesystem::path> Database::GetAnimeFolder(int id) {
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents: 347
diff changeset
17 // this function sucks, but it's the most I can really do for now.
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents: 347
diff changeset
18 //
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents: 347
diff changeset
19 // in the future the Refresh() function should look for directories
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents: 347
diff changeset
20 // as well that fit the anime name and *also* have episodes in them.
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents: 347
diff changeset
21 // it should give each of these directories a rating by how many
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents: 347
diff changeset
22 // episodes are contained in them. whichever directory has more episodes
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents: 347
diff changeset
23 // wins, or the first found if there is an equal amount.
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents: 347
diff changeset
24
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents: 347
diff changeset
25 for (const auto& [anime_id, episodes] : items) {
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents: 347
diff changeset
26 if (id != anime_id)
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents: 347
diff changeset
27 continue;
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents: 347
diff changeset
28
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents: 347
diff changeset
29 for (const auto& [episode, path] : episodes) {
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents: 347
diff changeset
30 return path.parent_path();
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents: 347
diff changeset
31 break;
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents: 347
diff changeset
32 }
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents: 347
diff changeset
33
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents: 347
diff changeset
34 break;
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents: 347
diff changeset
35 }
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents: 347
diff changeset
36
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents: 347
diff changeset
37 return std::nullopt;
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents: 347
diff changeset
38 }
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents: 347
diff changeset
39
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents: 347
diff changeset
40 void Database::Refresh(std::optional<int> find_id) {
328
71396ecb6f7e library: convert to class + database
Paper <paper@paper.us.eu.org>
parents: 319
diff changeset
41 items.clear();
222
b9f111d84d95 *: move to semver, remove old macos build, add library files
Paper <paper@paper.us.eu.org>
parents:
diff changeset
42
228
d030b30526d5 config: remove unused username parameter from anilist auth
Paper <mrpapersonic@gmail.com>
parents: 227
diff changeset
43 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
44 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
45 const std::filesystem::path path = entry.path();
d030b30526d5 config: remove unused username parameter from anilist auth
Paper <mrpapersonic@gmail.com>
parents: 227
diff changeset
46 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
47 continue;
b9f111d84d95 *: move to semver, remove old macos build, add library files
Paper <paper@paper.us.eu.org>
parents:
diff changeset
48
228
d030b30526d5 config: remove unused username parameter from anilist auth
Paper <mrpapersonic@gmail.com>
parents: 227
diff changeset
49 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
50
b9f111d84d95 *: move to semver, remove old macos build, add library files
Paper <paper@paper.us.eu.org>
parents:
diff changeset
51 anitomy::Anitomy anitomy;
347
a0aa8c8c4307 dep/anitomy: port to use UCS-4 rather than wide strings
Paper <paper@paper.us.eu.org>
parents: 328
diff changeset
52 anitomy.Parse(basename);
222
b9f111d84d95 *: move to semver, remove old macos build, add library files
Paper <paper@paper.us.eu.org>
parents:
diff changeset
53
b9f111d84d95 *: move to semver, remove old macos build, add library files
Paper <paper@paper.us.eu.org>
parents:
diff changeset
54 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
55
b9f111d84d95 *: move to semver, remove old macos build, add library files
Paper <paper@paper.us.eu.org>
parents:
diff changeset
56 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
57
319
d928ec7b6a0d services/kitsu: implement GetAnimeList()
Paper <paper@paper.us.eu.org>
parents: 258
diff changeset
58 const int id = Anime::db.LookupAnimeTitle(title);
366
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents: 347
diff changeset
59 if (id <= 0 || (find_id && find_id.value() != id))
222
b9f111d84d95 *: move to semver, remove old macos build, add library files
Paper <paper@paper.us.eu.org>
parents:
diff changeset
60 continue;
b9f111d84d95 *: move to semver, remove old macos build, add library files
Paper <paper@paper.us.eu.org>
parents:
diff changeset
61
328
71396ecb6f7e library: convert to class + database
Paper <paper@paper.us.eu.org>
parents: 319
diff changeset
62 const int episode = Strings::ToInt<int>(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
63
b9f111d84d95 *: move to semver, remove old macos build, add library files
Paper <paper@paper.us.eu.org>
parents:
diff changeset
64 // we have an ID now!
328
71396ecb6f7e library: convert to class + database
Paper <paper@paper.us.eu.org>
parents: 319
diff changeset
65 items[id][episode] = path;
222
b9f111d84d95 *: move to semver, remove old macos build, add library files
Paper <paper@paper.us.eu.org>
parents:
diff changeset
66 }
b9f111d84d95 *: move to semver, remove old macos build, add library files
Paper <paper@paper.us.eu.org>
parents:
diff changeset
67 }
b9f111d84d95 *: move to semver, remove old macos build, add library files
Paper <paper@paper.us.eu.org>
parents:
diff changeset
68 }
223
84e0a3c4737a library: implement menu bar buttons
Paper <mrpapersonic@gmail.com>
parents: 222
diff changeset
69
366
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents: 347
diff changeset
70 void Database::Refresh() {
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents: 347
diff changeset
71 Refresh(std::nullopt);
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents: 347
diff changeset
72 }
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents: 347
diff changeset
73
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents: 347
diff changeset
74 void Database::Refresh(int id) {
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents: 347
diff changeset
75 Refresh(std::optional<int>(id));
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents: 347
diff changeset
76 }
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents: 347
diff changeset
77
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents: 347
diff changeset
78 // TODO export to JSON
886f66775f31 animone: add preliminary AT-SPI stuff
Paper <paper@tflc.us>
parents: 347
diff changeset
79
328
71396ecb6f7e library: convert to class + database
Paper <paper@paper.us.eu.org>
parents: 319
diff changeset
80 Database db;
71396ecb6f7e library: convert to class + database
Paper <paper@paper.us.eu.org>
parents: 319
diff changeset
81
258
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 228
diff changeset
82 } // namespace Library