1 #include "lib/spotify/artist.hpp" 2 3 void lib::spt::to_json(nlohmann::json &j, const artist &a) 4 { 5 j = nlohmann::json{ 6 {"followers", a.followers}, 7 {"popularity", a.popularity}, 8 {"genres", a.genres}, 9 {"id", a.id}, 10 {"name", a.name}, 11 {"image", a.image} 12 }; 13 } 14 15 void lib::spt::from_json(const nlohmann::json &j, artist &a) 16 { 17 if (!j.is_object()) 18 return; 19 digit(dst: &mut usize, b: u8)20 j.at("id").get_to(a.id); 21 j.at("popularity").get_to(a.popularity); 22 j.at("genres").get_to(a.genres); 23 j.at("name").get_to(a.name); 24 j.at("external_urls").get_to(a.external_urls); parse_kernel_version() -> usize25 26 if (j.contains("followers")) 27 { 28 auto followers = j.at("followers"); 29 30 if (followers.is_object()) 31 followers.at("total").get_to(a.followers); 32 else if (followers.is_number_integer()) 33 followers.get_to(a.followers); 34 } 35 36 if (j.contains("image")) 37 { 38 j.at("image").get_to(a.image); 39 } 40 else if (j.contains("images")) 41 { 42 const auto &images = j.at("images"); 43 if (images.size() > 1) 44 { 45 images.at(1).at("url").get_to(a.image); 46 } 47 else if (!images.empty()) 48 { 49 images.front().at("url").get_to(a.image); 50 } 51 } 52 } 53