comparison src/services/anilist.cc @ 305:91ac90a34003

core/time: remove Duration class, use regular functions instead this class was pretty useless anyway
author Paper <paper@paper.us.eu.org>
date Sun, 19 May 2024 15:56:20 -0400
parents 2115488eb302
children 34347fd2a2de
comparison
equal deleted inserted replaced
304:2115488eb302 305:91ac90a34003
134 } 134 }
135 return "CURRENT"; 135 return "CURRENT";
136 } 136 }
137 137
138 static void ParseTitle(const nlohmann::json& json, Anime::Anime& anime) { 138 static void ParseTitle(const nlohmann::json& json, Anime::Anime& anime) {
139 nlohmann::json::json_pointer g = "/native"_json_pointer; 139 static const std::unordered_map<Anime::TitleLanguage, nlohmann::json::json_pointer> map = {
140 if (json.contains(g) && json[g].is_string()) 140 {Anime::TitleLanguage::Native, "/native"_json_pointer},
141 anime.SetTitle(Anime::TitleLanguage::Native, json[g]); 141 {Anime::TitleLanguage::English, "/english"_json_pointer},
142 142 {Anime::TitleLanguage::Romaji, "/romaji"_json_pointer},
143 g = "/english"_json_pointer; 143 };
144 if (json.contains(g) && json[g].is_string()) 144
145 anime.SetTitle(Anime::TitleLanguage::English, json[g]); 145 for (const auto& [language, ptr] : map)
146 146 if (json.contains(ptr) && json[ptr].is_string())
147 g = "/romaji"_json_pointer; 147 anime.SetTitle(language, json[ptr]);
148 if (json.contains(g) && json[g].is_string())
149 anime.SetTitle(Anime::TitleLanguage::Romaji, json[g]);
150 } 148 }
151 149
152 static int ParseMediaJson(const nlohmann::json& json) { 150 static int ParseMediaJson(const nlohmann::json& json) {
153 int id = JSON::GetNumber(json, "/id"_json_pointer); 151 int id = JSON::GetNumber(json, "/id"_json_pointer);
154 if (!id) 152 if (!id)