Mercurial > minori
annotate src/core/anime.cc @ 183:01d259b9c89f
pages/torrents.cc: parse feed descriptions separately
services/anilist.cc: use constexpr STL string_view for HTTP queries
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Mon, 04 Dec 2023 13:40:42 -0500 |
parents | bc8d2ccff09c |
children | 62e336597bb7 |
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" | |
178
bc8d2ccff09c
win32/dark: use existing STL classes for dwmapi
Paper <mrpapersonic@gmail.com>
parents:
81
diff
changeset
|
8 |
9 | 9 #include <algorithm> |
10 #include <string> | |
11 #include <vector> | |
12 | |
13 namespace Anime { | |
14 | |
15 /* User list data */ | |
16 bool Anime::IsInUserList() const { | |
17 if (list_info_.get()) | |
18 return true; | |
19 return false; | |
20 } | |
21 | |
22 void Anime::AddToUserList() { | |
23 list_info_.reset(new ListInformation); | |
24 } | |
25 | |
26 void Anime::RemoveFromUserList() { | |
27 list_info_.reset(); | |
28 } | |
29 | |
30 ListStatus Anime::GetUserStatus() const { | |
31 assert(list_info_.get()); | |
32 return list_info_->status; | |
33 } | |
34 | |
35 int Anime::GetUserProgress() const { | |
36 assert(list_info_.get()); | |
37 return list_info_->progress; | |
38 } | |
39 | |
40 int Anime::GetUserScore() const { | |
41 assert(list_info_.get()); | |
42 return list_info_->score; | |
43 } | |
44 | |
45 Date Anime::GetUserDateStarted() const { | |
46 assert(list_info_.get()); | |
47 return list_info_->started; | |
48 } | |
49 | |
50 Date Anime::GetUserDateCompleted() const { | |
51 assert(list_info_.get()); | |
52 return list_info_->completed; | |
53 } | |
54 | |
55 bool Anime::GetUserIsPrivate() const { | |
56 assert(list_info_.get()); | |
57 return list_info_->is_private; | |
58 } | |
59 | |
60 unsigned int Anime::GetUserRewatchedTimes() const { | |
61 assert(list_info_.get()); | |
62 return list_info_->rewatched_times; | |
63 } | |
64 | |
65 bool Anime::GetUserIsRewatching() const { | |
66 assert(list_info_.get()); | |
67 return list_info_->rewatching; | |
68 } | |
69 | |
70 uint64_t Anime::GetUserTimeUpdated() const { | |
71 assert(list_info_.get()); | |
72 return list_info_->updated; | |
73 } | |
74 | |
75 std::string Anime::GetUserNotes() const { | |
76 assert(list_info_.get()); | |
77 return list_info_->notes; | |
78 } | |
79 | |
80 void Anime::SetUserStatus(ListStatus status) { | |
81 assert(list_info_.get()); | |
82 list_info_->status = status; | |
83 } | |
84 | |
10 | 85 void Anime::SetUserScore(int score) { |
86 assert(list_info_.get()); | |
87 list_info_->score = score; | |
88 } | |
89 | |
9 | 90 void Anime::SetUserProgress(int progress) { |
91 assert(list_info_.get()); | |
92 list_info_->progress = progress; | |
93 } | |
94 | |
95 void Anime::SetUserDateStarted(Date const& started) { | |
96 assert(list_info_.get()); | |
97 list_info_->started = started; | |
98 } | |
99 | |
100 void Anime::SetUserDateCompleted(Date const& completed) { | |
101 assert(list_info_.get()); | |
102 list_info_->completed = completed; | |
103 } | |
104 | |
105 void Anime::SetUserIsPrivate(bool is_private) { | |
106 assert(list_info_.get()); | |
107 list_info_->is_private = is_private; | |
108 } | |
109 | |
110 void Anime::SetUserRewatchedTimes(int rewatched) { | |
111 assert(list_info_.get()); | |
112 list_info_->rewatched_times = rewatched; | |
113 } | |
114 | |
115 void Anime::SetUserIsRewatching(bool rewatching) { | |
116 assert(list_info_.get()); | |
117 list_info_->rewatching = rewatching; | |
118 } | |
119 | |
120 void Anime::SetUserTimeUpdated(uint64_t updated) { | |
121 assert(list_info_.get()); | |
122 list_info_->updated = updated; | |
123 } | |
124 | |
125 void Anime::SetUserNotes(std::string const& notes) { | |
126 assert(list_info_.get()); | |
127 list_info_->notes = notes; | |
128 } | |
129 | |
130 /* Series data */ | |
131 int Anime::GetId() const { | |
132 return info_.id; | |
133 } | |
134 | |
135 std::string Anime::GetRomajiTitle() const { | |
136 return info_.title.romaji; | |
137 } | |
138 | |
139 std::string Anime::GetEnglishTitle() const { | |
140 return info_.title.english; | |
141 } | |
142 | |
143 std::string Anime::GetNativeTitle() const { | |
144 return info_.title.native; | |
145 } | |
146 | |
147 std::vector<std::string> Anime::GetTitleSynonyms() const { | |
148 std::vector<std::string> result; | |
149 #define IN_VECTOR(v, k) (std::count(v.begin(), v.end(), k)) | |
36 | 150 #define ADD_TO_SYNONYMS(v, k) \ |
151 if (!k.empty() && !IN_VECTOR(v, k) && k != GetUserPreferredTitle()) \ | |
9 | 152 v.push_back(k) |
153 ADD_TO_SYNONYMS(result, info_.title.english); | |
154 ADD_TO_SYNONYMS(result, info_.title.romaji); | |
155 ADD_TO_SYNONYMS(result, info_.title.native); | |
156 for (auto& synonym : info_.synonyms) { | |
157 ADD_TO_SYNONYMS(result, synonym); | |
158 } | |
159 #undef ADD_TO_SYNONYMS | |
160 #undef IN_VECTOR | |
161 return result; | |
162 } | |
163 | |
164 int Anime::GetEpisodes() const { | |
165 return info_.episodes; | |
166 } | |
167 | |
168 SeriesStatus Anime::GetAiringStatus() const { | |
169 return info_.status; | |
170 } | |
171 | |
172 Date Anime::GetAirDate() const { | |
173 return info_.air_date; | |
174 } | |
175 | |
176 std::vector<std::string> Anime::GetGenres() const { | |
177 return info_.genres; | |
178 } | |
179 | |
180 std::vector<std::string> Anime::GetProducers() const { | |
181 return info_.producers; | |
182 } | |
183 | |
184 SeriesFormat Anime::GetFormat() const { | |
185 return info_.format; | |
186 } | |
187 | |
188 SeriesSeason Anime::GetSeason() const { | |
189 return info_.season; | |
190 } | |
191 | |
192 int Anime::GetAudienceScore() const { | |
193 return info_.audience_score; | |
194 } | |
195 | |
196 std::string Anime::GetSynopsis() const { | |
197 return info_.synopsis; | |
198 } | |
199 | |
200 int Anime::GetDuration() const { | |
201 return info_.duration; | |
202 } | |
203 | |
66
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
36
diff
changeset
|
204 std::string Anime::GetPosterUrl() const { |
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
36
diff
changeset
|
205 return info_.poster_url; |
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
36
diff
changeset
|
206 } |
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
36
diff
changeset
|
207 |
67
442065432549
poster: make posters link to AniList
Paper <mrpapersonic@gmail.com>
parents:
66
diff
changeset
|
208 std::string Anime::GetServiceUrl() const { |
183
01d259b9c89f
pages/torrents.cc: parse feed descriptions separately
Paper <mrpapersonic@gmail.com>
parents:
178
diff
changeset
|
209 /* todo: add support for other services... */ |
67
442065432549
poster: make posters link to AniList
Paper <mrpapersonic@gmail.com>
parents:
66
diff
changeset
|
210 return "https://anilist.co/anime/" + std::to_string(GetId()); |
442065432549
poster: make posters link to AniList
Paper <mrpapersonic@gmail.com>
parents:
66
diff
changeset
|
211 } |
442065432549
poster: make posters link to AniList
Paper <mrpapersonic@gmail.com>
parents:
66
diff
changeset
|
212 |
9 | 213 void Anime::SetId(int id) { |
214 info_.id = id; | |
215 } | |
216 | |
217 void Anime::SetRomajiTitle(std::string const& title) { | |
218 info_.title.romaji = title; | |
219 } | |
220 | |
221 void Anime::SetEnglishTitle(std::string const& title) { | |
222 info_.title.english = title; | |
223 } | |
224 | |
225 void Anime::SetNativeTitle(std::string const& title) { | |
226 info_.title.native = title; | |
227 } | |
228 | |
229 void Anime::SetTitleSynonyms(std::vector<std::string> const& synonyms) { | |
230 info_.synonyms = synonyms; | |
231 } | |
232 | |
233 void Anime::AddTitleSynonym(std::string const& synonym) { | |
234 info_.synonyms.push_back(synonym); | |
235 } | |
236 | |
237 void Anime::SetEpisodes(int episodes) { | |
238 info_.episodes = episodes; | |
239 } | |
240 | |
241 void Anime::SetAiringStatus(SeriesStatus status) { | |
242 info_.status = status; | |
243 } | |
244 | |
245 void Anime::SetAirDate(Date const& date) { | |
246 info_.air_date = date; | |
247 } | |
248 | |
249 void Anime::SetGenres(std::vector<std::string> const& genres) { | |
250 info_.genres = genres; | |
251 } | |
252 | |
253 void Anime::SetProducers(std::vector<std::string> const& producers) { | |
254 info_.producers = producers; | |
255 } | |
256 | |
257 void Anime::SetFormat(SeriesFormat format) { | |
258 info_.format = format; | |
259 } | |
260 | |
261 void Anime::SetSeason(SeriesSeason season) { | |
262 info_.season = season; | |
263 } | |
264 | |
265 void Anime::SetAudienceScore(int audience_score) { | |
266 info_.audience_score = audience_score; | |
267 } | |
268 | |
269 void Anime::SetSynopsis(std::string synopsis) { | |
270 info_.synopsis = synopsis; | |
271 } | |
272 | |
273 void Anime::SetDuration(int duration) { | |
274 info_.duration = duration; | |
275 } | |
276 | |
66
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
36
diff
changeset
|
277 void Anime::SetPosterUrl(std::string url) { |
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
36
diff
changeset
|
278 info_.poster_url = url; |
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
36
diff
changeset
|
279 } |
6481c5aed3e1
posters: add poster widget...
Paper <mrpapersonic@gmail.com>
parents:
36
diff
changeset
|
280 |
9 | 281 std::string Anime::GetUserPreferredTitle() const { |
282 switch (session.config.anime_list.language) { | |
283 case TitleLanguage::NATIVE: return (GetNativeTitle().empty()) ? GetRomajiTitle() : GetNativeTitle(); | |
284 case TitleLanguage::ENGLISH: return (GetEnglishTitle().empty()) ? GetRomajiTitle() : GetEnglishTitle(); | |
285 default: break; | |
286 } | |
287 return GetRomajiTitle(); | |
288 } | |
289 | |
290 } // namespace Anime |