Mercurial > minori
annotate src/core/anime_db.cc @ 248:cf47a8f687c0
cmake: remove cmake
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Wed, 24 Jan 2024 20:18:14 -0500 |
parents | 4d461ef7d424 |
children | d14f8e0e40c3 |
rev | line source |
---|---|
10 | 1 #include "core/anime_db.h" |
2 #include "core/anime.h" | |
64 | 3 #include "core/strings.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" |
174
f88eda79c60a
anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents:
173
diff
changeset
|
5 #include "core/filesystem.h" |
173
de0a8d2f28b3
WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents:
83
diff
changeset
|
6 |
174
f88eda79c60a
anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents:
173
diff
changeset
|
7 #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
|
8 #include "gui/translate/anilist.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 | 13 |
176
121c2d5b321f
anime/db: finalize anime db cache
Paper <mrpapersonic@gmail.com>
parents:
175
diff
changeset
|
14 #include <iostream> |
121c2d5b321f
anime/db: finalize anime db cache
Paper <mrpapersonic@gmail.com>
parents:
175
diff
changeset
|
15 #include <exception> |
121c2d5b321f
anime/db: finalize anime db cache
Paper <mrpapersonic@gmail.com>
parents:
175
diff
changeset
|
16 |
10 | 17 namespace Anime { |
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 | 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 | 26 return total; |
27 } | |
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) { |
10 | 30 if (status == ListStatus::NOT_IN_LIST) |
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 | 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 | 39 return total; |
40 } | |
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 | 49 return total; |
50 } | |
51 | |
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()) |
122fad646f81
anime/db: upgrade to c++17 style, make things easier to read
Paper <mrpapersonic@gmail.com>
parents:
176
diff
changeset
|
58 total += anime.GetDuration() * anime.GetUserProgress() |
122fad646f81
anime/db: upgrade to c++17 style, make things easier to read
Paper <mrpapersonic@gmail.com>
parents:
176
diff
changeset
|
59 + anime.GetEpisodes() * anime.GetDuration() * anime.GetUserRewatchedTimes(); |
122fad646f81
anime/db: upgrade to c++17 style, make things easier to read
Paper <mrpapersonic@gmail.com>
parents:
176
diff
changeset
|
60 |
10 | 61 return total; |
62 } | |
63 | |
64 /* Returns the total planned amount in minutes. | |
65 Note that we should probably limit progress to the | |
66 amount of episodes, as AniList will let you | |
67 set episode counts up to 32768. But that should | |
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 | 76 return total; |
77 } | |
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 | 80 what's primarily used in conversation, at least |
81 in the U.S. */ | |
10 | 82 double Database::GetAverageScore() { |
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 | 89 amt++; |
90 } | |
91 } | |
92 return avg / amt; | |
93 } | |
94 | |
95 double Database::GetScoreDeviation() { | |
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 | 102 amt++; |
103 } | |
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 | 106 return (amt > 0) ? std::sqrt(squares_sum / amt) : 0; |
107 } | |
108 | |
177
122fad646f81
anime/db: upgrade to c++17 style, make things easier to read
Paper <mrpapersonic@gmail.com>
parents:
176
diff
changeset
|
109 template<typename T, typename U> |
83 | 110 static T get_lowest_in_map(const std::unordered_map<T, U>& map) { |
111 if (map.size() <= 0) | |
112 return 0; | |
173
de0a8d2f28b3
WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents:
83
diff
changeset
|
113 |
de0a8d2f28b3
WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents:
83
diff
changeset
|
114 T id = 0; |
83 | 115 U ret = std::numeric_limits<U>::max(); |
116 for (const auto& t : map) { | |
117 if (t.second < ret) { | |
118 ret = t.second; | |
119 id = t.first; | |
120 } | |
121 } | |
122 return id; | |
123 } | |
124 | |
198
bc1ae1810855
dep/animia: switch from using classes to global functions
Paper <mrpapersonic@gmail.com>
parents:
197
diff
changeset
|
125 /* |
bc1ae1810855
dep/animia: switch from using classes to global functions
Paper <mrpapersonic@gmail.com>
parents:
197
diff
changeset
|
126 * This fairly basic algorithm is only in effect because |
bc1ae1810855
dep/animia: switch from using classes to global functions
Paper <mrpapersonic@gmail.com>
parents:
197
diff
changeset
|
127 * there are some special cases, e.g. Another and Re:ZERO, where |
bc1ae1810855
dep/animia: switch from using classes to global functions
Paper <mrpapersonic@gmail.com>
parents:
197
diff
changeset
|
128 * we get the wrong match, so we have to create Advanced Techniques |
bc1ae1810855
dep/animia: switch from using classes to global functions
Paper <mrpapersonic@gmail.com>
parents:
197
diff
changeset
|
129 * to solve this |
bc1ae1810855
dep/animia: switch from using classes to global functions
Paper <mrpapersonic@gmail.com>
parents:
197
diff
changeset
|
130 * |
bc1ae1810855
dep/animia: switch from using classes to global functions
Paper <mrpapersonic@gmail.com>
parents:
197
diff
changeset
|
131 * This algorithm: |
bc1ae1810855
dep/animia: switch from using classes to global functions
Paper <mrpapersonic@gmail.com>
parents:
197
diff
changeset
|
132 * 1. searches each anime item for a match to the preferred title |
bc1ae1810855
dep/animia: switch from using classes to global functions
Paper <mrpapersonic@gmail.com>
parents:
197
diff
changeset
|
133 * AND all synonyms and marks those matches with |
bc1ae1810855
dep/animia: switch from using classes to global functions
Paper <mrpapersonic@gmail.com>
parents:
197
diff
changeset
|
134 * `synonym.length() - (synonym.find(needle) + needle.length());` |
bc1ae1810855
dep/animia: switch from using classes to global functions
Paper <mrpapersonic@gmail.com>
parents:
197
diff
changeset
|
135 * which should never be less than zero and will be zero if, and only if |
bc1ae1810855
dep/animia: switch from using classes to global functions
Paper <mrpapersonic@gmail.com>
parents:
197
diff
changeset
|
136 * the titles match exactly. |
bc1ae1810855
dep/animia: switch from using classes to global functions
Paper <mrpapersonic@gmail.com>
parents:
197
diff
changeset
|
137 * 2. returns the id of the match that is the lowest, which will most |
bc1ae1810855
dep/animia: switch from using classes to global functions
Paper <mrpapersonic@gmail.com>
parents:
197
diff
changeset
|
138 * definitely match anything that exactly matches the title of the |
bc1ae1810855
dep/animia: switch from using classes to global functions
Paper <mrpapersonic@gmail.com>
parents:
197
diff
changeset
|
139 * filename |
bc1ae1810855
dep/animia: switch from using classes to global functions
Paper <mrpapersonic@gmail.com>
parents:
197
diff
changeset
|
140 */ |
83 | 141 int Database::GetAnimeFromTitle(const std::string& title) { |
64 | 142 if (title.empty()) |
143 return 0; | |
173
de0a8d2f28b3
WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents:
83
diff
changeset
|
144 |
de0a8d2f28b3
WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents:
83
diff
changeset
|
145 std::unordered_map<int, size_t> map; |
de0a8d2f28b3
WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents:
83
diff
changeset
|
146 |
198
bc1ae1810855
dep/animia: switch from using classes to global functions
Paper <mrpapersonic@gmail.com>
parents:
197
diff
changeset
|
147 static const auto process_title = [&map](const Anime& anime, const std::string& title, const std::string& needle) -> bool { |
236
4d461ef7d424
HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents:
198
diff
changeset
|
148 const std::string title_l = Strings::ToLower(title), needle_l = Strings::ToLower(needle); |
4d461ef7d424
HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents:
198
diff
changeset
|
149 size_t ret = title_l.find(needle_l); |
173
de0a8d2f28b3
WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents:
83
diff
changeset
|
150 if (ret == std::string::npos) |
de0a8d2f28b3
WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents:
83
diff
changeset
|
151 return false; |
de0a8d2f28b3
WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents:
83
diff
changeset
|
152 |
de0a8d2f28b3
WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents:
83
diff
changeset
|
153 map[anime.GetId()] = title.length() - (ret + needle.length()); |
de0a8d2f28b3
WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents:
83
diff
changeset
|
154 return true; |
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 |
de0a8d2f28b3
WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents:
83
diff
changeset
|
157 for (const auto& [id, anime] : items) { |
de0a8d2f28b3
WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents:
83
diff
changeset
|
158 if (process_title(anime, anime.GetUserPreferredTitle(), title)) |
83 | 159 continue; |
173
de0a8d2f28b3
WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents:
83
diff
changeset
|
160 |
de0a8d2f28b3
WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents:
83
diff
changeset
|
161 for (const auto& synonym : anime.GetTitleSynonyms()) |
de0a8d2f28b3
WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents:
83
diff
changeset
|
162 if (process_title(anime, synonym, title)) |
83 | 163 continue; |
64 | 164 } |
173
de0a8d2f28b3
WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents:
83
diff
changeset
|
165 |
83 | 166 return get_lowest_in_map(map); |
64 | 167 } |
168 | |
173
de0a8d2f28b3
WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents:
83
diff
changeset
|
169 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
|
170 if (!anime.IsInUserList()) |
de0a8d2f28b3
WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents:
83
diff
changeset
|
171 return false; |
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 off |
173
de0a8d2f28b3
WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents:
83
diff
changeset
|
174 json = { |
de0a8d2f28b3
WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents:
83
diff
changeset
|
175 {"status", Translate::ToString(anime.GetUserStatus())}, |
de0a8d2f28b3
WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents:
83
diff
changeset
|
176 {"progress", anime.GetUserProgress()}, |
de0a8d2f28b3
WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents:
83
diff
changeset
|
177 {"score", anime.GetUserScore()}, |
174
f88eda79c60a
anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents:
173
diff
changeset
|
178 {"started", anime.GetUserDateStarted().GetAsAniListJson()}, |
f88eda79c60a
anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents:
173
diff
changeset
|
179 {"completed", anime.GetUserDateCompleted().GetAsAniListJson()}, |
173
de0a8d2f28b3
WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents:
83
diff
changeset
|
180 {"private", anime.GetUserIsPrivate()}, |
de0a8d2f28b3
WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents:
83
diff
changeset
|
181 {"rewatched_times", anime.GetUserRewatchedTimes()}, |
de0a8d2f28b3
WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents:
83
diff
changeset
|
182 {"rewatching", anime.GetUserIsRewatching()}, |
de0a8d2f28b3
WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents:
83
diff
changeset
|
183 {"updated", anime.GetUserTimeUpdated()}, |
de0a8d2f28b3
WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents:
83
diff
changeset
|
184 {"notes", anime.GetUserNotes()} |
de0a8d2f28b3
WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents:
83
diff
changeset
|
185 }; |
177
122fad646f81
anime/db: upgrade to c++17 style, make things easier to read
Paper <mrpapersonic@gmail.com>
parents:
176
diff
changeset
|
186 // clang-format on |
174
f88eda79c60a
anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents:
173
diff
changeset
|
187 |
f88eda79c60a
anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents:
173
diff
changeset
|
188 return true; |
173
de0a8d2f28b3
WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents:
83
diff
changeset
|
189 } |
de0a8d2f28b3
WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents:
83
diff
changeset
|
190 |
de0a8d2f28b3
WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents:
83
diff
changeset
|
191 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
|
192 // clang-format off |
173
de0a8d2f28b3
WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents:
83
diff
changeset
|
193 json = { |
de0a8d2f28b3
WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents:
83
diff
changeset
|
194 {"id", anime.GetId()}, |
de0a8d2f28b3
WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents:
83
diff
changeset
|
195 {"title", { |
de0a8d2f28b3
WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents:
83
diff
changeset
|
196 {"native", anime.GetNativeTitle()}, |
de0a8d2f28b3
WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents:
83
diff
changeset
|
197 {"romaji", anime.GetRomajiTitle()}, |
de0a8d2f28b3
WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents:
83
diff
changeset
|
198 {"english", anime.GetEnglishTitle()} |
de0a8d2f28b3
WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents:
83
diff
changeset
|
199 }}, |
de0a8d2f28b3
WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents:
83
diff
changeset
|
200 {"synonyms", anime.GetTitleSynonyms()}, |
de0a8d2f28b3
WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents:
83
diff
changeset
|
201 {"episodes", anime.GetEpisodes()}, |
174
f88eda79c60a
anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents:
173
diff
changeset
|
202 {"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
|
203 {"air_date", anime.GetAirDate().GetAsAniListJson()}, |
173
de0a8d2f28b3
WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents:
83
diff
changeset
|
204 {"genres", anime.GetGenres()}, |
de0a8d2f28b3
WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents:
83
diff
changeset
|
205 {"producers", anime.GetProducers()}, |
174
f88eda79c60a
anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents:
173
diff
changeset
|
206 {"format", Translate::ToString(anime.GetFormat())}, |
f88eda79c60a
anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents:
173
diff
changeset
|
207 {"season", Translate::ToString(anime.GetSeason())}, |
173
de0a8d2f28b3
WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents:
83
diff
changeset
|
208 {"audience_score", anime.GetAudienceScore()}, |
de0a8d2f28b3
WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents:
83
diff
changeset
|
209 {"synopsis", anime.GetSynopsis()}, |
de0a8d2f28b3
WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents:
83
diff
changeset
|
210 {"duration", anime.GetDuration()}, |
174
f88eda79c60a
anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents:
173
diff
changeset
|
211 {"poster_url", anime.GetPosterUrl()} |
173
de0a8d2f28b3
WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents:
83
diff
changeset
|
212 }; |
177
122fad646f81
anime/db: upgrade to c++17 style, make things easier to read
Paper <mrpapersonic@gmail.com>
parents:
176
diff
changeset
|
213 // clang-format on |
173
de0a8d2f28b3
WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents:
83
diff
changeset
|
214 |
de0a8d2f28b3
WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents:
83
diff
changeset
|
215 nlohmann::json user; |
de0a8d2f28b3
WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents:
83
diff
changeset
|
216 if (GetListDataAsJSON(anime, user)) |
de0a8d2f28b3
WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents:
83
diff
changeset
|
217 json.push_back({"list_data", user}); |
de0a8d2f28b3
WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents:
83
diff
changeset
|
218 |
de0a8d2f28b3
WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents:
83
diff
changeset
|
219 return true; |
de0a8d2f28b3
WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents:
83
diff
changeset
|
220 } |
de0a8d2f28b3
WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents:
83
diff
changeset
|
221 |
de0a8d2f28b3
WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents:
83
diff
changeset
|
222 bool Database::GetDatabaseAsJSON(nlohmann::json& json) { |
de0a8d2f28b3
WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents:
83
diff
changeset
|
223 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
|
224 nlohmann::json anime_json = {}; |
173
de0a8d2f28b3
WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents:
83
diff
changeset
|
225 GetAnimeAsJSON(anime, anime_json); |
de0a8d2f28b3
WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents:
83
diff
changeset
|
226 json.push_back(anime_json); |
de0a8d2f28b3
WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents:
83
diff
changeset
|
227 } |
174
f88eda79c60a
anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents:
173
diff
changeset
|
228 |
f88eda79c60a
anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents:
173
diff
changeset
|
229 return true; |
f88eda79c60a
anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents:
173
diff
changeset
|
230 } |
f88eda79c60a
anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents:
173
diff
changeset
|
231 |
f88eda79c60a
anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents:
173
diff
changeset
|
232 bool Database::SaveDatabaseToDisk() { |
f88eda79c60a
anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents:
173
diff
changeset
|
233 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
|
234 Filesystem::CreateDirectories(db_path); |
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 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
|
237 if (!db_file) |
f88eda79c60a
anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents:
173
diff
changeset
|
238 return false; |
f88eda79c60a
anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents:
173
diff
changeset
|
239 |
f88eda79c60a
anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents:
173
diff
changeset
|
240 nlohmann::json json = {}; |
f88eda79c60a
anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents:
173
diff
changeset
|
241 if (!GetDatabaseAsJSON(json)) |
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 |
f88eda79c60a
anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents:
173
diff
changeset
|
244 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
|
245 return true; |
f88eda79c60a
anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents:
173
diff
changeset
|
246 } |
f88eda79c60a
anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents:
173
diff
changeset
|
247 |
f88eda79c60a
anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents:
173
diff
changeset
|
248 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
|
249 if (!anime.IsInUserList()) |
f88eda79c60a
anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents:
173
diff
changeset
|
250 anime.AddToUserList(); |
f88eda79c60a
anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents:
173
diff
changeset
|
251 |
f88eda79c60a
anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents:
173
diff
changeset
|
252 anime.SetUserStatus(Translate::ToListStatus(JSON::GetString<std::string>(json, "/status"_json_pointer, ""))); |
175 | 253 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
|
254 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
|
255 anime.SetUserDateStarted(Date(JSON::GetValue(json, "/started"_json_pointer))); |
197 | 256 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
|
257 anime.SetUserIsPrivate(JSON::GetBoolean(json, "/private"_json_pointer, false)); |
175 | 258 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
|
259 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
|
260 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
|
261 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
|
262 |
f88eda79c60a
anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents:
173
diff
changeset
|
263 return true; |
f88eda79c60a
anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents:
173
diff
changeset
|
264 } |
f88eda79c60a
anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents:
173
diff
changeset
|
265 |
177
122fad646f81
anime/db: upgrade to c++17 style, make things easier to read
Paper <mrpapersonic@gmail.com>
parents:
176
diff
changeset
|
266 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
|
267 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
|
268 if (!id) |
f88eda79c60a
anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents:
173
diff
changeset
|
269 return false; |
f88eda79c60a
anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents:
173
diff
changeset
|
270 |
177
122fad646f81
anime/db: upgrade to c++17 style, make things easier to read
Paper <mrpapersonic@gmail.com>
parents:
176
diff
changeset
|
271 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
|
272 |
f88eda79c60a
anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents:
173
diff
changeset
|
273 anime.SetId(id); |
f88eda79c60a
anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents:
173
diff
changeset
|
274 anime.SetNativeTitle(JSON::GetString<std::string>(json, "/title/native"_json_pointer, "")); |
f88eda79c60a
anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents:
173
diff
changeset
|
275 anime.SetRomajiTitle(JSON::GetString<std::string>(json, "/title/romaji"_json_pointer, "")); |
f88eda79c60a
anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents:
173
diff
changeset
|
276 anime.SetEnglishTitle(JSON::GetString<std::string>(json, "/title/english"_json_pointer, "")); |
f88eda79c60a
anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents:
173
diff
changeset
|
277 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
|
278 anime.SetEpisodes(JSON::GetNumber(json, "/episodes"_json_pointer, 0)); |
175 | 279 anime.SetAiringStatus(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
|
280 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
|
281 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
|
282 anime.SetProducers(JSON::GetArray<std::vector<std::string>>(json, "/producers"_json_pointer, {})); |
175 | 283 anime.SetFormat(Translate::ToSeriesFormat(JSON::GetString<std::string>(json, "/format"_json_pointer, ""))); |
284 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
|
285 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
|
286 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
|
287 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
|
288 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
|
289 |
176
121c2d5b321f
anime/db: finalize anime db cache
Paper <mrpapersonic@gmail.com>
parents:
175
diff
changeset
|
290 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
|
291 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
|
292 |
f88eda79c60a
anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents:
173
diff
changeset
|
293 return true; |
f88eda79c60a
anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents:
173
diff
changeset
|
294 } |
f88eda79c60a
anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents:
173
diff
changeset
|
295 |
f88eda79c60a
anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents:
173
diff
changeset
|
296 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
|
297 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
|
298 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
|
299 |
f88eda79c60a
anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents:
173
diff
changeset
|
300 return true; |
f88eda79c60a
anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents:
173
diff
changeset
|
301 } |
f88eda79c60a
anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents:
173
diff
changeset
|
302 |
177
122fad646f81
anime/db: upgrade to c++17 style, make things easier to read
Paper <mrpapersonic@gmail.com>
parents:
176
diff
changeset
|
303 bool Database::LoadDatabaseFromDisk() { |
174
f88eda79c60a
anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents:
173
diff
changeset
|
304 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
|
305 Filesystem::CreateDirectories(db_path); |
f88eda79c60a
anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents:
173
diff
changeset
|
306 |
f88eda79c60a
anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents:
173
diff
changeset
|
307 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
|
308 if (!db_file) |
f88eda79c60a
anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents:
173
diff
changeset
|
309 return false; |
f88eda79c60a
anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents:
173
diff
changeset
|
310 |
f88eda79c60a
anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents:
173
diff
changeset
|
311 /* When parsing, do NOT throw exceptions */ |
176
121c2d5b321f
anime/db: finalize anime db cache
Paper <mrpapersonic@gmail.com>
parents:
175
diff
changeset
|
312 nlohmann::json json; |
121c2d5b321f
anime/db: finalize anime db cache
Paper <mrpapersonic@gmail.com>
parents:
175
diff
changeset
|
313 try { |
121c2d5b321f
anime/db: finalize anime db cache
Paper <mrpapersonic@gmail.com>
parents:
175
diff
changeset
|
314 json = json.parse(db_file); |
121c2d5b321f
anime/db: finalize anime db cache
Paper <mrpapersonic@gmail.com>
parents:
175
diff
changeset
|
315 } catch (std::exception const& ex) { |
121c2d5b321f
anime/db: finalize anime db cache
Paper <mrpapersonic@gmail.com>
parents:
175
diff
changeset
|
316 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
|
317 return false; |
121c2d5b321f
anime/db: finalize anime db cache
Paper <mrpapersonic@gmail.com>
parents:
175
diff
changeset
|
318 } |
174
f88eda79c60a
anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents:
173
diff
changeset
|
319 |
f88eda79c60a
anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents:
173
diff
changeset
|
320 if (!ParseDatabaseJSON(json)) /* How */ |
f88eda79c60a
anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents:
173
diff
changeset
|
321 return false; |
f88eda79c60a
anime/db: add some more json functionality, still doesn't compile :/
Paper <mrpapersonic@gmail.com>
parents:
173
diff
changeset
|
322 |
173
de0a8d2f28b3
WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents:
83
diff
changeset
|
323 return true; |
de0a8d2f28b3
WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents:
83
diff
changeset
|
324 } |
de0a8d2f28b3
WILL NOT COMPILE: sample export ability for anime db
Paper <mrpapersonic@gmail.com>
parents:
83
diff
changeset
|
325 |
11 | 326 Database db; |
327 | |
9 | 328 } // namespace Anime |