annotate src/core/anime_db.cc @ 314:76d7315504c4

README: remove mention of nonexistant /docs directory
author Paper <paper@paper.us.eu.org>
date Tue, 11 Jun 2024 13:29:45 -0400
parents 53e3c015a973
children b1f4d1867ab1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
1 #include "core/anime_db.h"
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
2 #include "core/anime.h"
258
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 254
diff changeset
3 #include "core/filesystem.h"
173
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
4 #include "core/json.h"
258
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 254
diff changeset
5 #include "core/strings.h"
173
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
6
258
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 254
diff changeset
7 #include "gui/translate/anilist.h"
174
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
8 #include "gui/translate/anime.h"
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
9
187
9613d72b097e *: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents: 177
diff changeset
10 #include <QDate>
9613d72b097e *: multiple performance improvements
Paper <mrpapersonic@gmail.com>
parents: 177
diff changeset
11
174
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
12 #include <fstream>
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
13
258
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 254
diff changeset
14 #include <exception>
176
121c2d5b321f anime/db: finalize anime db cache
Paper <mrpapersonic@gmail.com>
parents: 175
diff changeset
15 #include <iostream>
121c2d5b321f anime/db: finalize anime db cache
Paper <mrpapersonic@gmail.com>
parents: 175
diff changeset
16
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
17 namespace Anime {
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
18
177
122fad646f81 anime/db: upgrade to c++17 style, make things easier to read
Paper <mrpapersonic@gmail.com>
parents: 176
diff changeset
19 size_t Database::GetTotalAnimeAmount() {
122fad646f81 anime/db: upgrade to c++17 style, make things easier to read
Paper <mrpapersonic@gmail.com>
parents: 176
diff changeset
20 size_t total = 0;
122fad646f81 anime/db: upgrade to c++17 style, make things easier to read
Paper <mrpapersonic@gmail.com>
parents: 176
diff changeset
21
122fad646f81 anime/db: upgrade to c++17 style, make things easier to read
Paper <mrpapersonic@gmail.com>
parents: 176
diff changeset
22 for (const auto& [id, anime] : items)
122fad646f81 anime/db: upgrade to c++17 style, make things easier to read
Paper <mrpapersonic@gmail.com>
parents: 176
diff changeset
23 if (anime.IsInUserList())
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
24 total++;
177
122fad646f81 anime/db: upgrade to c++17 style, make things easier to read
Paper <mrpapersonic@gmail.com>
parents: 176
diff changeset
25
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
26 return total;
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
27 }
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
28
177
122fad646f81 anime/db: upgrade to c++17 style, make things easier to read
Paper <mrpapersonic@gmail.com>
parents: 176
diff changeset
29 size_t Database::GetListsAnimeAmount(ListStatus status) {
279
657fda1b9cac *: clean up enums
Paper <paper@paper.us.eu.org>
parents: 264
diff changeset
30 if (status == ListStatus::NotInList)
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
31 return 0;
177
122fad646f81 anime/db: upgrade to c++17 style, make things easier to read
Paper <mrpapersonic@gmail.com>
parents: 176
diff changeset
32
122fad646f81 anime/db: upgrade to c++17 style, make things easier to read
Paper <mrpapersonic@gmail.com>
parents: 176
diff changeset
33 size_t total = 0;
122fad646f81 anime/db: upgrade to c++17 style, make things easier to read
Paper <mrpapersonic@gmail.com>
parents: 176
diff changeset
34
122fad646f81 anime/db: upgrade to c++17 style, make things easier to read
Paper <mrpapersonic@gmail.com>
parents: 176
diff changeset
35 for (const auto& [id, anime] : items)
122fad646f81 anime/db: upgrade to c++17 style, make things easier to read
Paper <mrpapersonic@gmail.com>
parents: 176
diff changeset
36 if (anime.IsInUserList() && anime.GetUserStatus() == status)
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
37 total++;
177
122fad646f81 anime/db: upgrade to c++17 style, make things easier to read
Paper <mrpapersonic@gmail.com>
parents: 176
diff changeset
38
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
39 return total;
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
40 }
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
41
177
122fad646f81 anime/db: upgrade to c++17 style, make things easier to read
Paper <mrpapersonic@gmail.com>
parents: 176
diff changeset
42 size_t Database::GetTotalEpisodeAmount() {
122fad646f81 anime/db: upgrade to c++17 style, make things easier to read
Paper <mrpapersonic@gmail.com>
parents: 176
diff changeset
43 size_t total = 0;
122fad646f81 anime/db: upgrade to c++17 style, make things easier to read
Paper <mrpapersonic@gmail.com>
parents: 176
diff changeset
44
122fad646f81 anime/db: upgrade to c++17 style, make things easier to read
Paper <mrpapersonic@gmail.com>
parents: 176
diff changeset
45 for (const auto& [id, anime] : items)
122fad646f81 anime/db: upgrade to c++17 style, make things easier to read
Paper <mrpapersonic@gmail.com>
parents: 176
diff changeset
46 if (anime.IsInUserList())
122fad646f81 anime/db: upgrade to c++17 style, make things easier to read
Paper <mrpapersonic@gmail.com>
parents: 176
diff changeset
47 total += anime.GetUserRewatchedTimes() * anime.GetEpisodes() + anime.GetUserProgress();
122fad646f81 anime/db: upgrade to c++17 style, make things easier to read
Paper <mrpapersonic@gmail.com>
parents: 176
diff changeset
48
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
49 return total;
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
50 }
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
51
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
52 /* Returns the total watched amount in minutes. */
177
122fad646f81 anime/db: upgrade to c++17 style, make things easier to read
Paper <mrpapersonic@gmail.com>
parents: 176
diff changeset
53 size_t Database::GetTotalWatchedAmount() {
122fad646f81 anime/db: upgrade to c++17 style, make things easier to read
Paper <mrpapersonic@gmail.com>
parents: 176
diff changeset
54 size_t total = 0;
122fad646f81 anime/db: upgrade to c++17 style, make things easier to read
Paper <mrpapersonic@gmail.com>
parents: 176
diff changeset
55
122fad646f81 anime/db: upgrade to c++17 style, make things easier to read
Paper <mrpapersonic@gmail.com>
parents: 176
diff changeset
56 for (const auto& [id, anime] : items)
122fad646f81 anime/db: upgrade to c++17 style, make things easier to read
Paper <mrpapersonic@gmail.com>
parents: 176
diff changeset
57 if (anime.IsInUserList())
258
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 254
diff changeset
58 total += anime.GetDuration() * anime.GetUserProgress() +
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 254
diff changeset
59 anime.GetEpisodes() * anime.GetDuration() * anime.GetUserRewatchedTimes();
177
122fad646f81 anime/db: upgrade to c++17 style, make things easier to read
Paper <mrpapersonic@gmail.com>
parents: 176
diff changeset
60
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
61 return total;
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
62 }
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
63
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
64 /* Returns the total planned amount in minutes.
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
65 Note that we should probably limit progress to the
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
66 amount of episodes, as AniList will let you
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
67 set episode counts up to 32768. But that should
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
68 rather be handled elsewhere. */
177
122fad646f81 anime/db: upgrade to c++17 style, make things easier to read
Paper <mrpapersonic@gmail.com>
parents: 176
diff changeset
69 size_t Database::GetTotalPlannedAmount() {
122fad646f81 anime/db: upgrade to c++17 style, make things easier to read
Paper <mrpapersonic@gmail.com>
parents: 176
diff changeset
70 size_t total = 0;
122fad646f81 anime/db: upgrade to c++17 style, make things easier to read
Paper <mrpapersonic@gmail.com>
parents: 176
diff changeset
71
122fad646f81 anime/db: upgrade to c++17 style, make things easier to read
Paper <mrpapersonic@gmail.com>
parents: 176
diff changeset
72 for (const auto& [id, anime] : items)
122fad646f81 anime/db: upgrade to c++17 style, make things easier to read
Paper <mrpapersonic@gmail.com>
parents: 176
diff changeset
73 if (anime.IsInUserList())
122fad646f81 anime/db: upgrade to c++17 style, make things easier to read
Paper <mrpapersonic@gmail.com>
parents: 176
diff changeset
74 total += anime.GetDuration() * (anime.GetEpisodes() - anime.GetUserProgress());
122fad646f81 anime/db: upgrade to c++17 style, make things easier to read
Paper <mrpapersonic@gmail.com>
parents: 176
diff changeset
75
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
76 return total;
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
77 }
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
78
177
122fad646f81 anime/db: upgrade to c++17 style, make things easier to read
Paper <mrpapersonic@gmail.com>
parents: 176
diff changeset
79 /* In Taiga this is called the mean, but "average" is
83
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
80 what's primarily used in conversation, at least
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
81 in the U.S. */
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
82 double Database::GetAverageScore() {
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
83 double avg = 0;
177
122fad646f81 anime/db: upgrade to c++17 style, make things easier to read
Paper <mrpapersonic@gmail.com>
parents: 176
diff changeset
84 size_t amt = 0;
122fad646f81 anime/db: upgrade to c++17 style, make things easier to read
Paper <mrpapersonic@gmail.com>
parents: 176
diff changeset
85
122fad646f81 anime/db: upgrade to c++17 style, make things easier to read
Paper <mrpapersonic@gmail.com>
parents: 176
diff changeset
86 for (const auto& [id, anime] : items) {
122fad646f81 anime/db: upgrade to c++17 style, make things easier to read
Paper <mrpapersonic@gmail.com>
parents: 176
diff changeset
87 if (anime.IsInUserList() && anime.GetUserScore()) {
122fad646f81 anime/db: upgrade to c++17 style, make things easier to read
Paper <mrpapersonic@gmail.com>
parents: 176
diff changeset
88 avg += anime.GetUserScore();
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
89 amt++;
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
90 }
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
91 }
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
92 return avg / amt;
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
93 }
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
94
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
95 double Database::GetScoreDeviation() {
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
96 double squares_sum = 0, avg = GetAverageScore();
177
122fad646f81 anime/db: upgrade to c++17 style, make things easier to read
Paper <mrpapersonic@gmail.com>
parents: 176
diff changeset
97 size_t amt = 0;
122fad646f81 anime/db: upgrade to c++17 style, make things easier to read
Paper <mrpapersonic@gmail.com>
parents: 176
diff changeset
98
122fad646f81 anime/db: upgrade to c++17 style, make things easier to read
Paper <mrpapersonic@gmail.com>
parents: 176
diff changeset
99 for (const auto& [id, anime] : items) {
122fad646f81 anime/db: upgrade to c++17 style, make things easier to read
Paper <mrpapersonic@gmail.com>
parents: 176
diff changeset
100 if (anime.IsInUserList() && anime.GetUserScore()) {
122fad646f81 anime/db: upgrade to c++17 style, make things easier to read
Paper <mrpapersonic@gmail.com>
parents: 176
diff changeset
101 squares_sum += std::pow(static_cast<double>(anime.GetUserScore()) - avg, 2);
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
102 amt++;
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
103 }
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
104 }
177
122fad646f81 anime/db: upgrade to c++17 style, make things easier to read
Paper <mrpapersonic@gmail.com>
parents: 176
diff changeset
105
10
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
106 return (amt > 0) ? std::sqrt(squares_sum / amt) : 0;
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
107 }
Paper <mrpapersonic@gmail.com>
parents: 9
diff changeset
108
258
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 254
diff changeset
109 /*
254
d14f8e0e40c3 [UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents: 236
diff changeset
110 * TODO: separate this from the anime DB,
d14f8e0e40c3 [UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents: 236
diff changeset
111 * provide *some* sort of normalization
258
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 254
diff changeset
112 */
83
d02fdf1d6708 *: huuuge update
Paper <mrpapersonic@gmail.com>
parents: 81
diff changeset
113 int Database::GetAnimeFromTitle(const std::string& title) {
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 11
diff changeset
114 if (title.empty())
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 11
diff changeset
115 return 0;
173
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
116
264
9a04802848c0 *: improve multiple things
Paper <paper@paper.us.eu.org>
parents: 260
diff changeset
117 std::string title_n(title);
9a04802848c0 *: improve multiple things
Paper <paper@paper.us.eu.org>
parents: 260
diff changeset
118 Strings::NormalizeAnimeTitle(title_n);
9a04802848c0 *: improve multiple things
Paper <paper@paper.us.eu.org>
parents: 260
diff changeset
119
173
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
120 for (const auto& [id, anime] : items) {
260
dd211ff68b36 pages/seasons: add initial functionality
Paper <paper@paper.us.eu.org>
parents: 258
diff changeset
121 std::vector<std::string> synonyms(anime.GetTitleSynonyms());
dd211ff68b36 pages/seasons: add initial functionality
Paper <paper@paper.us.eu.org>
parents: 258
diff changeset
122 synonyms.push_back(anime.GetUserPreferredTitle());
173
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
123
264
9a04802848c0 *: improve multiple things
Paper <paper@paper.us.eu.org>
parents: 260
diff changeset
124 for (auto& synonym : synonyms) {
9a04802848c0 *: improve multiple things
Paper <paper@paper.us.eu.org>
parents: 260
diff changeset
125 Strings::NormalizeAnimeTitle(synonym);
9a04802848c0 *: improve multiple things
Paper <paper@paper.us.eu.org>
parents: 260
diff changeset
126 if (synonym == title_n)
254
d14f8e0e40c3 [UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents: 236
diff changeset
127 return id;
260
dd211ff68b36 pages/seasons: add initial functionality
Paper <paper@paper.us.eu.org>
parents: 258
diff changeset
128 }
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 11
diff changeset
129 }
173
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
130
254
d14f8e0e40c3 [UNFINISHED] *: update anime button
Paper <paper@paper.us.eu.org>
parents: 236
diff changeset
131 return 0;
64
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 11
diff changeset
132 }
fe719c109dbc *: update
Paper <mrpapersonic@gmail.com>
parents: 11
diff changeset
133
173
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
134 static bool GetListDataAsJSON(const Anime& anime, nlohmann::json& json) {
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
135 if (!anime.IsInUserList())
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
136 return false;
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
137
177
122fad646f81 anime/db: upgrade to c++17 style, make things easier to read
Paper <mrpapersonic@gmail.com>
parents: 176
diff changeset
138 // clang-format off
173
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
139 json = {
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
140 {"status", Translate::ToString(anime.GetUserStatus())},
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
141 {"progress", anime.GetUserProgress()},
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
142 {"score", anime.GetUserScore()},
174
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
143 {"started", anime.GetUserDateStarted().GetAsAniListJson()},
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
144 {"completed", anime.GetUserDateCompleted().GetAsAniListJson()},
173
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
145 {"private", anime.GetUserIsPrivate()},
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
146 {"rewatched_times", anime.GetUserRewatchedTimes()},
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
147 {"rewatching", anime.GetUserIsRewatching()},
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
148 {"updated", anime.GetUserTimeUpdated()},
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
149 {"notes", anime.GetUserNotes()}
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
150 };
177
122fad646f81 anime/db: upgrade to c++17 style, make things easier to read
Paper <mrpapersonic@gmail.com>
parents: 176
diff changeset
151 // clang-format on
174
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
152
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
153 return true;
173
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
154 }
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
155
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
156 static bool GetAnimeAsJSON(const Anime& anime, nlohmann::json& json) {
177
122fad646f81 anime/db: upgrade to c++17 style, make things easier to read
Paper <mrpapersonic@gmail.com>
parents: 176
diff changeset
157 // clang-format off
173
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
158 json = {
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
159 {"id", anime.GetId()},
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
160 {"synonyms", anime.GetTitleSynonyms()},
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
161 {"episodes", anime.GetEpisodes()},
174
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
162 {"airing_status", Translate::ToString(anime.GetAiringStatus())},
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
163 {"air_date", anime.GetAirDate().GetAsAniListJson()},
173
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
164 {"genres", anime.GetGenres()},
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
165 {"producers", anime.GetProducers()},
174
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
166 {"format", Translate::ToString(anime.GetFormat())},
279
657fda1b9cac *: clean up enums
Paper <paper@paper.us.eu.org>
parents: 264
diff changeset
167 // {"season", Translate::ToString(anime.GetSeason())},
173
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
168 {"audience_score", anime.GetAudienceScore()},
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
169 {"synopsis", anime.GetSynopsis()},
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
170 {"duration", anime.GetDuration()},
174
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
171 {"poster_url", anime.GetPosterUrl()}
173
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
172 };
177
122fad646f81 anime/db: upgrade to c++17 style, make things easier to read
Paper <mrpapersonic@gmail.com>
parents: 176
diff changeset
173 // clang-format on
173
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
174
284
e66ffc338d82 anime: refactor title structure to a map
Paper <paper@paper.us.eu.org>
parents: 279
diff changeset
175 /* now for dynamically-filled stuff */
e66ffc338d82 anime: refactor title structure to a map
Paper <paper@paper.us.eu.org>
parents: 279
diff changeset
176 for (const auto& lang : TitleLanguages) {
e66ffc338d82 anime: refactor title structure to a map
Paper <paper@paper.us.eu.org>
parents: 279
diff changeset
177 std::optional<std::string> title = anime.GetTitle(lang);
e66ffc338d82 anime: refactor title structure to a map
Paper <paper@paper.us.eu.org>
parents: 279
diff changeset
178 if (title.has_value())
e66ffc338d82 anime: refactor title structure to a map
Paper <paper@paper.us.eu.org>
parents: 279
diff changeset
179 json["title"][Strings::ToLower(Translate::ToString(lang))] = title.value();
e66ffc338d82 anime: refactor title structure to a map
Paper <paper@paper.us.eu.org>
parents: 279
diff changeset
180 }
e66ffc338d82 anime: refactor title structure to a map
Paper <paper@paper.us.eu.org>
parents: 279
diff changeset
181
286
53e3c015a973 anime: initial cross-service support
Paper <paper@paper.us.eu.org>
parents: 284
diff changeset
182 for (const auto& service : Services) {
53e3c015a973 anime: initial cross-service support
Paper <paper@paper.us.eu.org>
parents: 284
diff changeset
183 std::optional<std::string> id = anime.GetServiceId(service);
53e3c015a973 anime: initial cross-service support
Paper <paper@paper.us.eu.org>
parents: 284
diff changeset
184 if (id.has_value())
53e3c015a973 anime: initial cross-service support
Paper <paper@paper.us.eu.org>
parents: 284
diff changeset
185 json["ids"][Strings::ToLower(Translate::ToString(service))] = id.value();
53e3c015a973 anime: initial cross-service support
Paper <paper@paper.us.eu.org>
parents: 284
diff changeset
186 }
53e3c015a973 anime: initial cross-service support
Paper <paper@paper.us.eu.org>
parents: 284
diff changeset
187
173
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
188 nlohmann::json user;
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
189 if (GetListDataAsJSON(anime, user))
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
190 json.push_back({"list_data", user});
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
191
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
192 return true;
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
193 }
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
194
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
195 bool Database::GetDatabaseAsJSON(nlohmann::json& json) {
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
196 for (const auto& [id, anime] : items) {
174
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
197 nlohmann::json anime_json = {};
173
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
198 GetAnimeAsJSON(anime, anime_json);
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
199 json.push_back(anime_json);
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
200 }
174
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
201
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
202 return true;
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
203 }
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
204
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
205 bool Database::SaveDatabaseToDisk() {
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
206 std::filesystem::path db_path = Filesystem::GetAnimeDBPath();
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
207 Filesystem::CreateDirectories(db_path);
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
208
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
209 std::ofstream db_file(db_path);
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
210 if (!db_file)
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
211 return false;
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
212
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
213 nlohmann::json json = {};
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
214 if (!GetDatabaseAsJSON(json))
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
215 return false;
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
216
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
217 db_file << std::setw(4) << json << std::endl;
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
218 return true;
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
219 }
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
220
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
221 static bool ParseAnimeUserInfoJSON(const nlohmann::json& json, Anime& anime) {
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
222 if (!anime.IsInUserList())
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
223 anime.AddToUserList();
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
224
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
225 anime.SetUserStatus(Translate::ToListStatus(JSON::GetString<std::string>(json, "/status"_json_pointer, "")));
175
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 174
diff changeset
226 anime.SetUserProgress(JSON::GetNumber(json, "/progress"_json_pointer, 0));
174
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
227 anime.SetUserScore(JSON::GetNumber(json, "/score"_json_pointer, 0));
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
228 anime.SetUserDateStarted(Date(JSON::GetValue(json, "/started"_json_pointer)));
197
c4ca035c565d *: misc. patches
Paper <mrpapersonic@gmail.com>
parents: 187
diff changeset
229 anime.SetUserDateCompleted(Date(JSON::GetValue(json, "/completed"_json_pointer)));
174
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
230 anime.SetUserIsPrivate(JSON::GetBoolean(json, "/private"_json_pointer, false));
175
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 174
diff changeset
231 anime.SetUserRewatchedTimes(JSON::GetNumber(json, "/rewatched_times"_json_pointer, 0));
174
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
232 anime.SetUserIsRewatching(JSON::GetBoolean(json, "/rewatching"_json_pointer, false));
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
233 anime.SetUserTimeUpdated(JSON::GetNumber(json, "/updated"_json_pointer, 0));
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
234 anime.SetUserNotes(JSON::GetString<std::string>(json, "/notes"_json_pointer, ""));
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
235
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
236 return true;
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
237 }
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
238
177
122fad646f81 anime/db: upgrade to c++17 style, make things easier to read
Paper <mrpapersonic@gmail.com>
parents: 176
diff changeset
239 static bool ParseAnimeInfoJSON(const nlohmann::json& json, Database& database) {
174
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
240 int id = JSON::GetNumber(json, "/id"_json_pointer, 0);
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
241 if (!id)
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
242 return false;
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
243
177
122fad646f81 anime/db: upgrade to c++17 style, make things easier to read
Paper <mrpapersonic@gmail.com>
parents: 176
diff changeset
244 Anime& anime = database.items[id];
174
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
245
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
246 anime.SetId(id);
284
e66ffc338d82 anime: refactor title structure to a map
Paper <paper@paper.us.eu.org>
parents: 279
diff changeset
247 for (const auto& lang : TitleLanguages) {
e66ffc338d82 anime: refactor title structure to a map
Paper <paper@paper.us.eu.org>
parents: 279
diff changeset
248 nlohmann::json::json_pointer p("/title/" + Strings::ToLower(Translate::ToString(lang)));
e66ffc338d82 anime: refactor title structure to a map
Paper <paper@paper.us.eu.org>
parents: 279
diff changeset
249
e66ffc338d82 anime: refactor title structure to a map
Paper <paper@paper.us.eu.org>
parents: 279
diff changeset
250 if (json.contains(p) && json[p].is_string())
e66ffc338d82 anime: refactor title structure to a map
Paper <paper@paper.us.eu.org>
parents: 279
diff changeset
251 anime.SetTitle(lang, json[p].get<std::string>());
e66ffc338d82 anime: refactor title structure to a map
Paper <paper@paper.us.eu.org>
parents: 279
diff changeset
252 }
174
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
253 anime.SetTitleSynonyms(JSON::GetArray<std::vector<std::string>>(json, "/synonyms"_json_pointer, {}));
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
254 anime.SetEpisodes(JSON::GetNumber(json, "/episodes"_json_pointer, 0));
258
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 254
diff changeset
255 anime.SetAiringStatus(
862d0d8619f6 *: HUUUGE changes
Paper <paper@paper.us.eu.org>
parents: 254
diff changeset
256 Translate::ToSeriesStatus(JSON::GetString<std::string>(json, "/airing_status"_json_pointer, "")));
174
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
257 anime.SetAirDate(Date(JSON::GetValue(json, "/air_date"_json_pointer)));
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
258 anime.SetGenres(JSON::GetArray<std::vector<std::string>>(json, "/genres"_json_pointer, {}));
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
259 anime.SetProducers(JSON::GetArray<std::vector<std::string>>(json, "/producers"_json_pointer, {}));
175
9b10175be389 dep/json: update to v3.11.3
Paper <mrpapersonic@gmail.com>
parents: 174
diff changeset
260 anime.SetFormat(Translate::ToSeriesFormat(JSON::GetString<std::string>(json, "/format"_json_pointer, "")));
279
657fda1b9cac *: clean up enums
Paper <paper@paper.us.eu.org>
parents: 264
diff changeset
261 // anime.SetSeason(Translate::ToSeriesSeason(JSON::GetString<std::string>(json, "/season"_json_pointer, "")));
174
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
262 anime.SetAudienceScore(JSON::GetNumber(json, "/audience_score"_json_pointer, 0));
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
263 anime.SetSynopsis(JSON::GetString<std::string>(json, "/synopsis"_json_pointer, ""));
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
264 anime.SetDuration(JSON::GetNumber(json, "/duration"_json_pointer, 0));
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
265 anime.SetPosterUrl(JSON::GetString<std::string>(json, "/poster_url"_json_pointer, ""));
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
266
176
121c2d5b321f anime/db: finalize anime db cache
Paper <mrpapersonic@gmail.com>
parents: 175
diff changeset
267 if (json.contains("/list_data"_json_pointer) && json.at("/list_data"_json_pointer).is_object())
121c2d5b321f anime/db: finalize anime db cache
Paper <mrpapersonic@gmail.com>
parents: 175
diff changeset
268 ParseAnimeUserInfoJSON(json.at("/list_data"_json_pointer), anime);
174
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
269
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
270 return true;
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
271 }
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
272
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
273 bool Database::ParseDatabaseJSON(const nlohmann::json& json) {
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
274 for (const auto& anime_json : json)
177
122fad646f81 anime/db: upgrade to c++17 style, make things easier to read
Paper <mrpapersonic@gmail.com>
parents: 176
diff changeset
275 ParseAnimeInfoJSON(anime_json, *this);
174
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
276
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
277 return true;
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
278 }
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
279
177
122fad646f81 anime/db: upgrade to c++17 style, make things easier to read
Paper <mrpapersonic@gmail.com>
parents: 176
diff changeset
280 bool Database::LoadDatabaseFromDisk() {
174
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
281 std::filesystem::path db_path = Filesystem::GetAnimeDBPath();
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
282 Filesystem::CreateDirectories(db_path);
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
283
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
284 std::ifstream db_file(db_path);
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
285 if (!db_file)
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
286 return false;
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
287
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
288 /* When parsing, do NOT throw exceptions */
176
121c2d5b321f anime/db: finalize anime db cache
Paper <mrpapersonic@gmail.com>
parents: 175
diff changeset
289 nlohmann::json json;
121c2d5b321f anime/db: finalize anime db cache
Paper <mrpapersonic@gmail.com>
parents: 175
diff changeset
290 try {
121c2d5b321f anime/db: finalize anime db cache
Paper <mrpapersonic@gmail.com>
parents: 175
diff changeset
291 json = json.parse(db_file);
121c2d5b321f anime/db: finalize anime db cache
Paper <mrpapersonic@gmail.com>
parents: 175
diff changeset
292 } catch (std::exception const& ex) {
121c2d5b321f anime/db: finalize anime db cache
Paper <mrpapersonic@gmail.com>
parents: 175
diff changeset
293 std::cerr << "[anime/db] Failed to parse JSON! " << ex.what() << std::endl;
121c2d5b321f anime/db: finalize anime db cache
Paper <mrpapersonic@gmail.com>
parents: 175
diff changeset
294 return false;
121c2d5b321f anime/db: finalize anime db cache
Paper <mrpapersonic@gmail.com>
parents: 175
diff changeset
295 }
174
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
296
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
297 if (!ParseDatabaseJSON(json)) /* How */
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
298 return false;
f88eda79c60a anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents: 173
diff changeset
299
173
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
300 return true;
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
301 }
de0a8d2f28b3 WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents: 83
diff changeset
302
11
fc1bf97c528b *: use C++11 standard
Paper <mrpapersonic@gmail.com>
parents: 10
diff changeset
303 Database db;
fc1bf97c528b *: use C++11 standard
Paper <mrpapersonic@gmail.com>
parents: 10
diff changeset
304
279
657fda1b9cac *: clean up enums
Paper <paper@paper.us.eu.org>
parents: 264
diff changeset
305 } // namespace Anime