Mercurial > minori
annotate src/core/anime.cc @ 281:3ede7be4f449
anime_season: forgot these
author | Paper <paper@paper.us.eu.org> |
---|---|
date | Mon, 06 May 2024 17:44:16 -0400 |
parents | 9b6e12c14a1e |
children | e66ffc338d82 |
rev | line source |
---|---|
9 | 1 /* |
2 * anime.cpp: defining of custom anime-related | |
3 * datatypes & variables | |
4 */ | |
5 #include "core/anime.h" | |
279 | 6 #include "core/anime_season.h" |
9 | 7 #include "core/date.h" |
8 #include "core/session.h" | |
211
7cf53145de11
strings: use templates for ToInt, std::to_string -> Strings::ToUtf8String
Paper <mrpapersonic@gmail.com>
parents:
195
diff
changeset
|
9 #include "core/strings.h" |
178
bc8d2ccff09c
win32/dark: use existing STL classes for dwmapi
Paper <mrpapersonic@gmail.com>
parents:
81
diff
changeset
|
10 |
9 | 11 #include <algorithm> |
12 #include <string> | |
13 #include <vector> | |
275
22f9aacf6ac1
osx: don't dereference NULL pointers
Paper <paper@paper.us.eu.org>
parents:
265
diff
changeset
|
14 #include <cassert> |
9 | 15 |
16 namespace Anime { | |
17 | |
18 /* User list data */ | |
19 bool Anime::IsInUserList() const { | |
264 | 20 if (list_info_.has_value()) |
9 | 21 return true; |
22 return false; | |
23 } | |
24 | |
25 void Anime::AddToUserList() { | |
265
ff0b2052b234
*: add missing utf8proc files
Paper <paper@paper.us.eu.org>
parents:
264
diff
changeset
|
26 ListInformation list; |
264 | 27 list_info_.emplace(list); |
9 | 28 } |
29 | |
30 void Anime::RemoveFromUserList() { | |
31 list_info_.reset(); | |
32 } | |
33 | |
34 ListStatus Anime::GetUserStatus() const { | |
264 | 35 assert(list_info_.has_value()); |
9 | 36 return list_info_->status; |
37 } | |
38 | |
39 int Anime::GetUserProgress() const { | |
264 | 40 assert(list_info_.has_value()); |
9 | 41 return list_info_->progress; |
42 } | |
43 | |
44 int Anime::GetUserScore() const { | |
264 | 45 assert(list_info_.has_value()); |
9 | 46 return list_info_->score; |
47 } | |
48 | |
185
62e336597bb7
anime list: add support for different score formats
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
49 std::string Anime::GetUserPresentableScore() const { |
264 | 50 assert(list_info_.has_value()); |
279 | 51 |
185
62e336597bb7
anime list: add support for different score formats
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
52 const int score = list_info_->score; |
62e336597bb7
anime list: add support for different score formats
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
53 if (score == 0) |
62e336597bb7
anime list: add support for different score formats
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
54 return ""; |
62e336597bb7
anime list: add support for different score formats
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
55 |
62e336597bb7
anime list: add support for different score formats
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
56 switch (session.config.anime_list.score_format) { |
279 | 57 case ScoreFormat::Point10Decimal: |
211
7cf53145de11
strings: use templates for ToInt, std::to_string -> Strings::ToUtf8String
Paper <mrpapersonic@gmail.com>
parents:
195
diff
changeset
|
58 return Strings::ToUtf8String(score / 10) + "." + Strings::ToUtf8String(score % 10); |
279 | 59 case ScoreFormat::Point10: return Strings::ToUtf8String(score / 10); |
60 case ScoreFormat::Point5: { | |
185
62e336597bb7
anime list: add support for different score formats
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
61 std::string stars = ""; |
62e336597bb7
anime list: add support for different score formats
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
62 |
62e336597bb7
anime list: add support for different score formats
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
63 for (int i = 0; i < 100; i += 20) |
62e336597bb7
anime list: add support for different score formats
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
64 stars.append((i <= score) ? "★" : "☆"); |
62e336597bb7
anime list: add support for different score formats
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
65 |
62e336597bb7
anime list: add support for different score formats
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
66 return stars; |
62e336597bb7
anime list: add support for different score formats
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
67 } |
279 | 68 case ScoreFormat::Point3: { |
185
62e336597bb7
anime list: add support for different score formats
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
69 if (score >= 100) |
62e336597bb7
anime list: add support for different score formats
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
70 return ":)"; |
62e336597bb7
anime list: add support for different score formats
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
71 else if (score >= 66) |
62e336597bb7
anime list: add support for different score formats
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
72 return ":|"; |
62e336597bb7
anime list: add support for different score formats
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
73 else if (score >= 33) |
62e336597bb7
anime list: add support for different score formats
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
74 return ":("; |
62e336597bb7
anime list: add support for different score formats
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
75 else |
62e336597bb7
anime list: add support for different score formats
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
76 return ""; |
62e336597bb7
anime list: add support for different score formats
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
77 } |
62e336597bb7
anime list: add support for different score formats
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
78 default: |
279 | 79 case ScoreFormat::Point100: return Strings::ToUtf8String(score); |
185
62e336597bb7
anime list: add support for different score formats
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
80 } |
62e336597bb7
anime list: add support for different score formats
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
81 } |
62e336597bb7
anime list: add support for different score formats
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
82 |
9 | 83 Date Anime::GetUserDateStarted() const { |
264 | 84 assert(list_info_.has_value()); |
9 | 85 return list_info_->started; |
86 } | |
87 | |
88 Date Anime::GetUserDateCompleted() const { | |
264 | 89 assert(list_info_.has_value()); |
9 | 90 return list_info_->completed; |
91 } | |
92 | |
93 bool Anime::GetUserIsPrivate() const { | |
264 | 94 assert(list_info_.has_value()); |
9 | 95 return list_info_->is_private; |
96 } | |
97 | |
98 unsigned int Anime::GetUserRewatchedTimes() const { | |
264 | 99 assert(list_info_.has_value()); |
9 | 100 return list_info_->rewatched_times; |
101 } | |
102 | |
103 bool Anime::GetUserIsRewatching() const { | |
264 | 104 assert(list_info_.has_value()); |
9 | 105 return list_info_->rewatching; |
106 } | |
107 | |
108 uint64_t Anime::GetUserTimeUpdated() const { | |
264 | 109 assert(list_info_.has_value()); |
9 | 110 return list_info_->updated; |
111 } | |
112 | |
113 std::string Anime::GetUserNotes() const { | |
264 | 114 assert(list_info_.has_value()); |
9 | 115 return list_info_->notes; |
116 } | |
117 | |
118 void Anime::SetUserStatus(ListStatus status) { | |
264 | 119 assert(list_info_.has_value()); |
9 | 120 list_info_->status = status; |
121 } | |
122 | |
10 | 123 void Anime::SetUserScore(int score) { |
264 | 124 assert(list_info_.has_value()); |
10 | 125 list_info_->score = score; |
126 } | |
127 | |
9 | 128 void Anime::SetUserProgress(int progress) { |
264 | 129 assert(list_info_.has_value()); |
9 | 130 list_info_->progress = progress; |
131 } | |
132 | |
133 void Anime::SetUserDateStarted(Date const& started) { | |
264 | 134 assert(list_info_.has_value()); |
9 | 135 list_info_->started = started; |
136 } | |
137 | |
138 void Anime::SetUserDateCompleted(Date const& completed) { | |
264 | 139 assert(list_info_.has_value()); |
9 | 140 list_info_->completed = completed; |
141 } | |
142 | |
143 void Anime::SetUserIsPrivate(bool is_private) { | |
264 | 144 assert(list_info_.has_value()); |
9 | 145 list_info_->is_private = is_private; |
146 } | |
147 | |
148 void Anime::SetUserRewatchedTimes(int rewatched) { | |
264 | 149 assert(list_info_.has_value()); |
9 | 150 list_info_->rewatched_times = rewatched; |
151 } | |
152 | |
153 void Anime::SetUserIsRewatching(bool rewatching) { | |
264 | 154 assert(list_info_.has_value()); |
9 | 155 list_info_->rewatching = rewatching; |
156 } | |
157 | |
158 void Anime::SetUserTimeUpdated(uint64_t updated) { | |
264 | 159 assert(list_info_.has_value()); |
9 | 160 list_info_->updated = updated; |
161 } | |
162 | |
163 void Anime::SetUserNotes(std::string const& notes) { | |
264 | 164 assert(list_info_.has_value()); |
9 | 165 list_info_->notes = notes; |
166 } | |
167 | |
168 /* Series data */ | |
169 int Anime::GetId() const { | |
170 return info_.id; | |
171 } | |
172 | |
173 std::string Anime::GetRomajiTitle() const { | |
174 return info_.title.romaji; | |
175 } | |
176 | |
177 std::string Anime::GetEnglishTitle() const { | |
178 return info_.title.english; | |
179 } | |
180 | |
181 std::string Anime::GetNativeTitle() const { | |
182 return info_.title.native; | |
183 } | |
184 | |
185 std::vector<std::string> Anime::GetTitleSynonyms() const { | |
186 std::vector<std::string> result; | |
195
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
186
diff
changeset
|
187 |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
186
diff
changeset
|
188 auto add_to_synonyms = [this](std::vector<std::string>& vec, std::string key) { |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
186
diff
changeset
|
189 if (!key.empty() && !std::count(vec.begin(), vec.end(), key) && key != GetUserPreferredTitle()) |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
186
diff
changeset
|
190 vec.push_back(key); |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
186
diff
changeset
|
191 }; |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
186
diff
changeset
|
192 |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
186
diff
changeset
|
193 add_to_synonyms(result, info_.title.english); |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
186
diff
changeset
|
194 add_to_synonyms(result, info_.title.romaji); |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
186
diff
changeset
|
195 add_to_synonyms(result, info_.title.native); |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
186
diff
changeset
|
196 |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
186
diff
changeset
|
197 for (auto& synonym : info_.synonyms) |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
186
diff
changeset
|
198 add_to_synonyms(result, synonym); |
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
186
diff
changeset
|
199 |
9 | 200 return result; |
201 } | |
202 | |
203 int Anime::GetEpisodes() const { | |
204 return info_.episodes; | |
205 } | |
206 | |
207 SeriesStatus Anime::GetAiringStatus() const { | |
208 return info_.status; | |
209 } | |
210 | |
211 Date Anime::GetAirDate() const { | |
212 return info_.air_date; | |
213 } | |
214 | |
215 std::vector<std::string> Anime::GetGenres() const { | |
216 return info_.genres; | |
217 } | |
218 | |
219 std::vector<std::string> Anime::GetProducers() const { | |
220 return info_.producers; | |
221 } | |
222 | |
223 SeriesFormat Anime::GetFormat() const { | |
224 return info_.format; | |
225 } | |
226 | |
227 SeriesSeason Anime::GetSeason() const { | |
279 | 228 std::optional<Date::Month> month = info_.air_date.GetMonth(); |
229 return (month.has_value() ? GetSeasonForMonth(month.value()) : SeriesSeason::Unknown); | |
9 | 230 } |
231 | |
232 int Anime::GetAudienceScore() const { | |
233 return info_.audience_score; | |
234 } | |
235 | |
236 std::string Anime::GetSynopsis() const { | |
237 return info_.synopsis; | |
238 } | |
239 | |
240 int Anime::GetDuration() const { | |
241 return info_.duration; | |
242 } | |
243 | |
66
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
36
diff
changeset
|
244 std::string Anime::GetPosterUrl() const { |
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
36
diff
changeset
|
245 return info_.poster_url; |
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
36
diff
changeset
|
246 } |
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
36
diff
changeset
|
247 |
67
442065432549
poster: make posters link to AniList
Paper <mrpapersonic@gmail.com>
parents:
66
diff
changeset
|
248 std::string Anime::GetServiceUrl() const { |
183
01d259b9c89f
pages/torrents.cc: parse feed descriptions separately
Paper <mrpapersonic@gmail.com>
parents:
178
diff
changeset
|
249 /* todo: add support for other services... */ |
279 | 250 switch (session.config.service) { |
251 case Service::AniList: return "https://anilist.co/anime/" + Strings::ToUtf8String(GetId()); | |
252 default: return ""; | |
253 } | |
67
442065432549
poster: make posters link to AniList
Paper <mrpapersonic@gmail.com>
parents:
66
diff
changeset
|
254 } |
442065432549
poster: make posters link to AniList
Paper <mrpapersonic@gmail.com>
parents:
66
diff
changeset
|
255 |
9 | 256 void Anime::SetId(int id) { |
257 info_.id = id; | |
258 } | |
259 | |
260 void Anime::SetRomajiTitle(std::string const& title) { | |
261 info_.title.romaji = title; | |
262 } | |
263 | |
264 void Anime::SetEnglishTitle(std::string const& title) { | |
265 info_.title.english = title; | |
266 } | |
267 | |
268 void Anime::SetNativeTitle(std::string const& title) { | |
269 info_.title.native = title; | |
270 } | |
271 | |
272 void Anime::SetTitleSynonyms(std::vector<std::string> const& synonyms) { | |
273 info_.synonyms = synonyms; | |
274 } | |
275 | |
276 void Anime::AddTitleSynonym(std::string const& synonym) { | |
277 info_.synonyms.push_back(synonym); | |
278 } | |
279 | |
280 void Anime::SetEpisodes(int episodes) { | |
281 info_.episodes = episodes; | |
282 } | |
283 | |
284 void Anime::SetAiringStatus(SeriesStatus status) { | |
285 info_.status = status; | |
286 } | |
287 | |
288 void Anime::SetAirDate(Date const& date) { | |
289 info_.air_date = date; | |
290 } | |
291 | |
292 void Anime::SetGenres(std::vector<std::string> const& genres) { | |
293 info_.genres = genres; | |
294 } | |
295 | |
296 void Anime::SetProducers(std::vector<std::string> const& producers) { | |
297 info_.producers = producers; | |
298 } | |
299 | |
300 void Anime::SetFormat(SeriesFormat format) { | |
301 info_.format = format; | |
302 } | |
303 | |
304 void Anime::SetAudienceScore(int audience_score) { | |
305 info_.audience_score = audience_score; | |
306 } | |
307 | |
308 void Anime::SetSynopsis(std::string synopsis) { | |
309 info_.synopsis = synopsis; | |
310 } | |
311 | |
312 void Anime::SetDuration(int duration) { | |
313 info_.duration = duration; | |
314 } | |
315 | |
66
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
36
diff
changeset
|
316 void Anime::SetPosterUrl(std::string url) { |
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
36
diff
changeset
|
317 info_.poster_url = url; |
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
36
diff
changeset
|
318 } |
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
36
diff
changeset
|
319 |
9 | 320 std::string Anime::GetUserPreferredTitle() const { |
321 switch (session.config.anime_list.language) { | |
279 | 322 case TitleLanguage::Native: return (GetNativeTitle().empty()) ? GetRomajiTitle() : GetNativeTitle(); |
323 case TitleLanguage::Romaji: return (GetEnglishTitle().empty()) ? GetRomajiTitle() : GetEnglishTitle(); | |
9 | 324 default: break; |
325 } | |
326 return GetRomajiTitle(); | |
327 } | |
328 | |
329 } // namespace Anime |