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