Mercurial > minori
diff src/services/anilist.cc @ 284:e66ffc338d82
anime: refactor title structure to a map
author | Paper <paper@paper.us.eu.org> |
---|---|
date | Wed, 08 May 2024 16:21:05 -0400 |
parents | 657fda1b9cac |
children | 53e3c015a973 |
line wrap: on
line diff
--- a/src/services/anilist.cc Wed May 08 16:20:37 2024 -0400 +++ b/src/services/anilist.cc Wed May 08 16:21:05 2024 -0400 @@ -110,9 +110,17 @@ } void ParseTitle(const nlohmann::json& json, Anime::Anime& anime) { - anime.SetNativeTitle(JSON::GetString<std::string>(json, "/native"_json_pointer, "")); - anime.SetEnglishTitle(JSON::GetString<std::string>(json, "/english"_json_pointer, "")); - anime.SetRomajiTitle(JSON::GetString<std::string>(json, "/romaji"_json_pointer, "")); + nlohmann::json::json_pointer g = "/native"_json_pointer; + if (json.contains(g) && json[g].is_string()) + anime.SetTitle(Anime::TitleLanguage::Native, json[g]); + + g = "/english"_json_pointer; + if (json.contains(g) && json[g].is_string()) + anime.SetTitle(Anime::TitleLanguage::English, json[g]); + + g = "/romaji"_json_pointer; + if (json.contains(g) && json[g].is_string()) + anime.SetTitle(Anime::TitleLanguage::Romaji, json[g]); } int ParseMediaJson(const nlohmann::json& json) {