Mercurial > minori
comparison src/core/anime.cc @ 286:53e3c015a973
anime: initial cross-service support
currently the Kitsu and MAL services don't work when chosen in the
GUI. This is because they haven't been implemented yet :)
author | Paper <paper@paper.us.eu.org> |
---|---|
date | Wed, 08 May 2024 16:44:27 -0400 |
parents | e66ffc338d82 |
children | 91ac90a34003 |
comparison
equal
deleted
inserted
replaced
285:65df2813d0de | 286:53e3c015a973 |
---|---|
168 /* Series data */ | 168 /* Series data */ |
169 int Anime::GetId() const { | 169 int Anime::GetId() const { |
170 return info_.id; | 170 return info_.id; |
171 } | 171 } |
172 | 172 |
173 std::optional<std::string> Anime::GetServiceId(Service service) const { | |
174 if (info_.ids.find(service) == info_.ids.end()) | |
175 return std::nullopt; | |
176 | |
177 return info_.ids.at(service); | |
178 } | |
179 | |
173 /* note: this should use std::optional */ | 180 /* note: this should use std::optional */ |
174 std::optional<std::string> Anime::GetTitle(TitleLanguage language) const { | 181 std::optional<std::string> Anime::GetTitle(TitleLanguage language) const { |
175 if (info_.titles.find(language) == info_.titles.end()) | 182 if (info_.titles.find(language) == info_.titles.end()) |
176 return std::nullopt; | 183 return std::nullopt; |
177 | 184 |
237 int Anime::GetDuration() const { | 244 int Anime::GetDuration() const { |
238 return info_.duration; | 245 return info_.duration; |
239 } | 246 } |
240 | 247 |
241 std::string Anime::GetPosterUrl() const { | 248 std::string Anime::GetPosterUrl() const { |
249 /* this isn't really service-specific. this could use | |
250 * kitsu, MAL, or anilist, and would achieve basically | |
251 * the same effect. */ | |
242 return info_.poster_url; | 252 return info_.poster_url; |
243 } | 253 } |
244 | 254 |
245 std::string Anime::GetServiceUrl() const { | 255 std::optional<std::string> Anime::GetServiceUrl(Service service) const { |
246 /* todo: add support for other services... */ | 256 /* todo: add support for other services... */ |
247 switch (session.config.service) { | 257 std::optional<std::string> id = GetServiceId(service); |
248 case Service::AniList: return "https://anilist.co/anime/" + Strings::ToUtf8String(GetId()); | 258 if (!id.has_value()) |
259 return std::nullopt; | |
260 | |
261 switch (service) { | |
262 case Service::AniList: | |
263 return "https://anilist.co/anime/" + id.value(); | |
249 default: return ""; | 264 default: return ""; |
250 } | 265 } |
251 } | 266 } |
252 | 267 |
253 void Anime::SetId(int id) { | 268 void Anime::SetId(int id) { |
254 info_.id = id; | 269 info_.id = id; |
270 } | |
271 | |
272 void Anime::SetServiceId(Service service, const std::string& id) { | |
273 info_.ids[service] = id; | |
255 } | 274 } |
256 | 275 |
257 void Anime::SetTitle(TitleLanguage language, const std::string& title) { | 276 void Anime::SetTitle(TitleLanguage language, const std::string& title) { |
258 info_.titles[language] = title; | 277 info_.titles[language] = title; |
259 } | 278 } |