Mercurial > minori
annotate src/core/anime.cc @ 258:862d0d8619f6
*: HUUUGE changes
animia has been renamed to animone, so instead of thinking of a
health condition, you think of a beautiful flower :)
I've also edited some of the code for animone, but I have no idea
if it even works or not because I don't have a mac or windows
machine lying around. whoops!
... anyway, all of the changes divergent from Anisthesia are now
licensed under BSD. it's possible that I could even rewrite most
of the code to where I don't even have to keep the MIT license,
but that's thinking too far into the future
I've been slacking off on implementing the anime seasons page,
mostly out of laziness. I think I'd have to create another db file
specifically for the seasons
anyway, this code is being pushed *primarily* because the hard drive
it's on is failing! yay :)
| author | Paper <paper@paper.us.eu.org> |
|---|---|
| date | Mon, 01 Apr 2024 02:43:44 -0400 |
| parents | 7cf53145de11 |
| children | 9a04802848c0 |
| 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 { | |
| 18 if (list_info_.get()) | |
| 19 return true; | |
| 20 return false; | |
| 21 } | |
| 22 | |
| 23 void Anime::AddToUserList() { | |
| 24 list_info_.reset(new ListInformation); | |
| 25 } | |
| 26 | |
| 27 void Anime::RemoveFromUserList() { | |
| 28 list_info_.reset(); | |
| 29 } | |
| 30 | |
| 31 ListStatus Anime::GetUserStatus() const { | |
| 32 assert(list_info_.get()); | |
| 33 return list_info_->status; | |
| 34 } | |
| 35 | |
| 36 int Anime::GetUserProgress() const { | |
| 37 assert(list_info_.get()); | |
| 38 return list_info_->progress; | |
| 39 } | |
| 40 | |
| 41 int Anime::GetUserScore() const { | |
| 42 assert(list_info_.get()); | |
| 43 return list_info_->score; | |
| 44 } | |
| 45 | |
|
185
62e336597bb7
anime list: add support for different score formats
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
46 std::string Anime::GetUserPresentableScore() const { |
|
62e336597bb7
anime list: add support for different score formats
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
47 assert(list_info_.get()); |
|
62e336597bb7
anime list: add support for different score formats
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
48 const int score = list_info_->score; |
|
62e336597bb7
anime list: add support for different score formats
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
49 if (score == 0) |
|
62e336597bb7
anime list: add support for different score formats
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
50 return ""; |
|
62e336597bb7
anime list: add support for different score formats
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
51 |
|
62e336597bb7
anime list: add support for different score formats
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
52 switch (session.config.anime_list.score_format) { |
|
186
6ef31dbb90ca
anime: no unnecessary conversion to floating point
Paper <mrpapersonic@gmail.com>
parents:
185
diff
changeset
|
53 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
|
54 return Strings::ToUtf8String(score / 10) + "." + Strings::ToUtf8String(score % 10); |
| 258 | 55 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
|
56 case ScoreFormat::POINT_5: { |
|
62e336597bb7
anime list: add support for different score formats
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
57 std::string stars = ""; |
|
62e336597bb7
anime list: add support for different score formats
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
58 |
|
62e336597bb7
anime list: add support for different score formats
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
59 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
|
60 stars.append((i <= score) ? "★" : "☆"); |
|
62e336597bb7
anime list: add support for different score formats
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
61 |
|
62e336597bb7
anime list: add support for different score formats
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
62 return stars; |
|
62e336597bb7
anime list: add support for different score formats
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
63 } |
|
62e336597bb7
anime list: add support for different score formats
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
64 case ScoreFormat::POINT_3: { |
|
62e336597bb7
anime list: add support for different score formats
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
65 if (score >= 100) |
|
62e336597bb7
anime list: add support for different score formats
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
66 return ":)"; |
|
62e336597bb7
anime list: add support for different score formats
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
67 else if (score >= 66) |
|
62e336597bb7
anime list: add support for different score formats
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
68 return ":|"; |
|
62e336597bb7
anime list: add support for different score formats
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
69 else if (score >= 33) |
|
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 |
|
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 } |
|
62e336597bb7
anime list: add support for different score formats
Paper <mrpapersonic@gmail.com>
parents:
183
diff
changeset
|
74 default: |
| 258 | 75 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
|
76 } |
|
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 |
| 9 | 79 Date Anime::GetUserDateStarted() const { |
| 80 assert(list_info_.get()); | |
| 81 return list_info_->started; | |
| 82 } | |
| 83 | |
| 84 Date Anime::GetUserDateCompleted() const { | |
| 85 assert(list_info_.get()); | |
| 86 return list_info_->completed; | |
| 87 } | |
| 88 | |
| 89 bool Anime::GetUserIsPrivate() const { | |
| 90 assert(list_info_.get()); | |
| 91 return list_info_->is_private; | |
| 92 } | |
| 93 | |
| 94 unsigned int Anime::GetUserRewatchedTimes() const { | |
| 95 assert(list_info_.get()); | |
| 96 return list_info_->rewatched_times; | |
| 97 } | |
| 98 | |
| 99 bool Anime::GetUserIsRewatching() const { | |
| 100 assert(list_info_.get()); | |
| 101 return list_info_->rewatching; | |
| 102 } | |
| 103 | |
| 104 uint64_t Anime::GetUserTimeUpdated() const { | |
| 105 assert(list_info_.get()); | |
| 106 return list_info_->updated; | |
| 107 } | |
| 108 | |
| 109 std::string Anime::GetUserNotes() const { | |
| 110 assert(list_info_.get()); | |
| 111 return list_info_->notes; | |
| 112 } | |
| 113 | |
| 114 void Anime::SetUserStatus(ListStatus status) { | |
| 115 assert(list_info_.get()); | |
| 116 list_info_->status = status; | |
| 117 } | |
| 118 | |
| 10 | 119 void Anime::SetUserScore(int score) { |
| 120 assert(list_info_.get()); | |
| 121 list_info_->score = score; | |
| 122 } | |
| 123 | |
| 9 | 124 void Anime::SetUserProgress(int progress) { |
| 125 assert(list_info_.get()); | |
| 126 list_info_->progress = progress; | |
| 127 } | |
| 128 | |
| 129 void Anime::SetUserDateStarted(Date const& started) { | |
| 130 assert(list_info_.get()); | |
| 131 list_info_->started = started; | |
| 132 } | |
| 133 | |
| 134 void Anime::SetUserDateCompleted(Date const& completed) { | |
| 135 assert(list_info_.get()); | |
| 136 list_info_->completed = completed; | |
| 137 } | |
| 138 | |
| 139 void Anime::SetUserIsPrivate(bool is_private) { | |
| 140 assert(list_info_.get()); | |
| 141 list_info_->is_private = is_private; | |
| 142 } | |
| 143 | |
| 144 void Anime::SetUserRewatchedTimes(int rewatched) { | |
| 145 assert(list_info_.get()); | |
| 146 list_info_->rewatched_times = rewatched; | |
| 147 } | |
| 148 | |
| 149 void Anime::SetUserIsRewatching(bool rewatching) { | |
| 150 assert(list_info_.get()); | |
| 151 list_info_->rewatching = rewatching; | |
| 152 } | |
| 153 | |
| 154 void Anime::SetUserTimeUpdated(uint64_t updated) { | |
| 155 assert(list_info_.get()); | |
| 156 list_info_->updated = updated; | |
| 157 } | |
| 158 | |
| 159 void Anime::SetUserNotes(std::string const& notes) { | |
| 160 assert(list_info_.get()); | |
| 161 list_info_->notes = notes; | |
| 162 } | |
| 163 | |
| 164 /* Series data */ | |
| 165 int Anime::GetId() const { | |
| 166 return info_.id; | |
| 167 } | |
| 168 | |
| 169 std::string Anime::GetRomajiTitle() const { | |
| 170 return info_.title.romaji; | |
| 171 } | |
| 172 | |
| 173 std::string Anime::GetEnglishTitle() const { | |
| 174 return info_.title.english; | |
| 175 } | |
| 176 | |
| 177 std::string Anime::GetNativeTitle() const { | |
| 178 return info_.title.native; | |
| 179 } | |
| 180 | |
| 181 std::vector<std::string> Anime::GetTitleSynonyms() const { | |
| 182 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
|
183 |
|
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
186
diff
changeset
|
184 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
|
185 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
|
186 vec.push_back(key); |
|
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 |
|
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
186
diff
changeset
|
189 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
|
190 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
|
191 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
|
192 |
|
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
186
diff
changeset
|
193 for (auto& synonym : info_.synonyms) |
|
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
186
diff
changeset
|
194 add_to_synonyms(result, synonym); |
|
975a3f0965e2
locale: only attempt loading locales after QApplication is init'd
Paper <mrpapersonic@gmail.com>
parents:
186
diff
changeset
|
195 |
| 9 | 196 return result; |
| 197 } | |
| 198 | |
| 199 int Anime::GetEpisodes() const { | |
| 200 return info_.episodes; | |
| 201 } | |
| 202 | |
| 203 SeriesStatus Anime::GetAiringStatus() const { | |
| 204 return info_.status; | |
| 205 } | |
| 206 | |
| 207 Date Anime::GetAirDate() const { | |
| 208 return info_.air_date; | |
| 209 } | |
| 210 | |
| 211 std::vector<std::string> Anime::GetGenres() const { | |
| 212 return info_.genres; | |
| 213 } | |
| 214 | |
| 215 std::vector<std::string> Anime::GetProducers() const { | |
| 216 return info_.producers; | |
| 217 } | |
| 218 | |
| 219 SeriesFormat Anime::GetFormat() const { | |
| 220 return info_.format; | |
| 221 } | |
| 222 | |
| 223 SeriesSeason Anime::GetSeason() const { | |
| 224 return info_.season; | |
| 225 } | |
| 226 | |
| 227 int Anime::GetAudienceScore() const { | |
| 228 return info_.audience_score; | |
| 229 } | |
| 230 | |
| 231 std::string Anime::GetSynopsis() const { | |
| 232 return info_.synopsis; | |
| 233 } | |
| 234 | |
| 235 int Anime::GetDuration() const { | |
| 236 return info_.duration; | |
| 237 } | |
| 238 | |
|
66
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
36
diff
changeset
|
239 std::string Anime::GetPosterUrl() const { |
|
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
36
diff
changeset
|
240 return info_.poster_url; |
|
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
36
diff
changeset
|
241 } |
|
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
36
diff
changeset
|
242 |
|
67
442065432549
poster: make posters link to AniList
Paper <mrpapersonic@gmail.com>
parents:
66
diff
changeset
|
243 std::string Anime::GetServiceUrl() const { |
|
183
01d259b9c89f
pages/torrents.cc: parse feed descriptions separately
Paper <mrpapersonic@gmail.com>
parents:
178
diff
changeset
|
244 /* 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
|
245 return "https://anilist.co/anime/" + Strings::ToUtf8String(GetId()); |
|
67
442065432549
poster: make posters link to AniList
Paper <mrpapersonic@gmail.com>
parents:
66
diff
changeset
|
246 } |
|
442065432549
poster: make posters link to AniList
Paper <mrpapersonic@gmail.com>
parents:
66
diff
changeset
|
247 |
| 9 | 248 void Anime::SetId(int id) { |
| 249 info_.id = id; | |
| 250 } | |
| 251 | |
| 252 void Anime::SetRomajiTitle(std::string const& title) { | |
| 253 info_.title.romaji = title; | |
| 254 } | |
| 255 | |
| 256 void Anime::SetEnglishTitle(std::string const& title) { | |
| 257 info_.title.english = title; | |
| 258 } | |
| 259 | |
| 260 void Anime::SetNativeTitle(std::string const& title) { | |
| 261 info_.title.native = title; | |
| 262 } | |
| 263 | |
| 264 void Anime::SetTitleSynonyms(std::vector<std::string> const& synonyms) { | |
| 265 info_.synonyms = synonyms; | |
| 266 } | |
| 267 | |
| 268 void Anime::AddTitleSynonym(std::string const& synonym) { | |
| 269 info_.synonyms.push_back(synonym); | |
| 270 } | |
| 271 | |
| 272 void Anime::SetEpisodes(int episodes) { | |
| 273 info_.episodes = episodes; | |
| 274 } | |
| 275 | |
| 276 void Anime::SetAiringStatus(SeriesStatus status) { | |
| 277 info_.status = status; | |
| 278 } | |
| 279 | |
| 280 void Anime::SetAirDate(Date const& date) { | |
| 281 info_.air_date = date; | |
| 282 } | |
| 283 | |
| 284 void Anime::SetGenres(std::vector<std::string> const& genres) { | |
| 285 info_.genres = genres; | |
| 286 } | |
| 287 | |
| 288 void Anime::SetProducers(std::vector<std::string> const& producers) { | |
| 289 info_.producers = producers; | |
| 290 } | |
| 291 | |
| 292 void Anime::SetFormat(SeriesFormat format) { | |
| 293 info_.format = format; | |
| 294 } | |
| 295 | |
| 296 void Anime::SetSeason(SeriesSeason season) { | |
| 297 info_.season = season; | |
| 298 } | |
| 299 | |
| 300 void Anime::SetAudienceScore(int audience_score) { | |
| 301 info_.audience_score = audience_score; | |
| 302 } | |
| 303 | |
| 304 void Anime::SetSynopsis(std::string synopsis) { | |
| 305 info_.synopsis = synopsis; | |
| 306 } | |
| 307 | |
| 308 void Anime::SetDuration(int duration) { | |
| 309 info_.duration = duration; | |
| 310 } | |
| 311 | |
|
66
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
36
diff
changeset
|
312 void Anime::SetPosterUrl(std::string url) { |
|
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
36
diff
changeset
|
313 info_.poster_url = url; |
|
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
36
diff
changeset
|
314 } |
|
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
36
diff
changeset
|
315 |
| 9 | 316 std::string Anime::GetUserPreferredTitle() const { |
| 317 switch (session.config.anime_list.language) { | |
| 318 case TitleLanguage::NATIVE: return (GetNativeTitle().empty()) ? GetRomajiTitle() : GetNativeTitle(); | |
| 319 case TitleLanguage::ENGLISH: return (GetEnglishTitle().empty()) ? GetRomajiTitle() : GetEnglishTitle(); | |
| 320 default: break; | |
| 321 } | |
| 322 return GetRomajiTitle(); | |
| 323 } | |
| 324 | |
| 325 } // namespace Anime |
