diff 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
line wrap: on
line diff
--- a/src/core/anime.cc	Wed May 08 16:43:32 2024 -0400
+++ b/src/core/anime.cc	Wed May 08 16:44:27 2024 -0400
@@ -170,6 +170,13 @@
 	return info_.id;
 }
 
+std::optional<std::string> Anime::GetServiceId(Service service) const {
+	if (info_.ids.find(service) == info_.ids.end())
+		return std::nullopt;
+
+	return info_.ids.at(service);
+}
+
 /* note: this should use std::optional */
 std::optional<std::string> Anime::GetTitle(TitleLanguage language) const {
 	if (info_.titles.find(language) == info_.titles.end())
@@ -239,13 +246,21 @@
 }
 
 std::string Anime::GetPosterUrl() const {
+	/* this isn't really service-specific. this could use
+	 * kitsu, MAL, or anilist, and would achieve basically
+	 * the same effect. */
 	return info_.poster_url;
 }
 
-std::string Anime::GetServiceUrl() const {
+std::optional<std::string> Anime::GetServiceUrl(Service service) const {
 	/* todo: add support for other services... */
-	switch (session.config.service) {
-		case Service::AniList: return "https://anilist.co/anime/" + Strings::ToUtf8String(GetId());
+	std::optional<std::string> id = GetServiceId(service);
+	if (!id.has_value())
+		return std::nullopt;
+
+	switch (service) {
+		case Service::AniList:
+			return "https://anilist.co/anime/" + id.value();
 		default: return "";
 	}
 }
@@ -254,6 +269,10 @@
 	info_.id = id;
 }
 
+void Anime::SetServiceId(Service service, const std::string& id) {
+	info_.ids[service] = id;
+}
+
 void Anime::SetTitle(TitleLanguage language, const std::string& title) {
 	info_.titles[language] = title;
 }