Mercurial > minori
comparison 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 |
comparison
equal
deleted
inserted
replaced
283:969a3e8c79c5 | 284:e66ffc338d82 |
---|---|
108 } | 108 } |
109 return "CURRENT"; | 109 return "CURRENT"; |
110 } | 110 } |
111 | 111 |
112 void ParseTitle(const nlohmann::json& json, Anime::Anime& anime) { | 112 void ParseTitle(const nlohmann::json& json, Anime::Anime& anime) { |
113 anime.SetNativeTitle(JSON::GetString<std::string>(json, "/native"_json_pointer, "")); | 113 nlohmann::json::json_pointer g = "/native"_json_pointer; |
114 anime.SetEnglishTitle(JSON::GetString<std::string>(json, "/english"_json_pointer, "")); | 114 if (json.contains(g) && json[g].is_string()) |
115 anime.SetRomajiTitle(JSON::GetString<std::string>(json, "/romaji"_json_pointer, "")); | 115 anime.SetTitle(Anime::TitleLanguage::Native, json[g]); |
116 | |
117 g = "/english"_json_pointer; | |
118 if (json.contains(g) && json[g].is_string()) | |
119 anime.SetTitle(Anime::TitleLanguage::English, json[g]); | |
120 | |
121 g = "/romaji"_json_pointer; | |
122 if (json.contains(g) && json[g].is_string()) | |
123 anime.SetTitle(Anime::TitleLanguage::Romaji, json[g]); | |
116 } | 124 } |
117 | 125 |
118 int ParseMediaJson(const nlohmann::json& json) { | 126 int ParseMediaJson(const nlohmann::json& json) { |
119 int id = JSON::GetNumber(json, "/id"_json_pointer); | 127 int id = JSON::GetNumber(json, "/id"_json_pointer); |
120 if (!id) | 128 if (!id) |