diff --git a/src/background.rs b/src/background.rs index 382767a..7c9ce74 100644 --- a/src/background.rs +++ b/src/background.rs @@ -11,39 +11,40 @@ pub struct Background { pub hash: String } -pub fn get_uri() -> String { - let lang = crate::i18n::get_lang(); - - if lang.language == unic_langid::langid!("zh-cn").language { - concat!("https://hyp-api.", "mi", "ho", "yo", ".com/hyp/hyp-connect/api/getAllGameBasicInfo?launcher_id=jGHBHlcOq1").to_owned() - } - - else { - let uri = concat!("https://sg-hyp-api.", "ho", "yo", "verse", ".com/hyp/hyp-connect/api/getAllGameBasicInfo?launcher_id=VYTpXlbWo8&language="); - - uri.to_owned() + &crate::i18n::format_lang(lang) - } -} - #[cached::proc_macro::cached(result)] pub fn get_background_info() -> anyhow::Result { - let json = serde_json::from_slice::(minreq::get(get_uri()).send()?.as_bytes())?; - - let uri = json["data"]["game_info_list"].as_array() - .ok_or_else(|| anyhow::anyhow!("Failed to list games in the backgrounds API"))? - .iter() - .find(|game| { - match game["game"]["biz"].as_str() { - Some(biz) => biz.starts_with("bh3_"), - _ => false - } - }) - .ok_or_else(|| anyhow::anyhow!("Failed to find the game in the backgrounds API"))?["backgrounds"] - .as_array() - .and_then(|backgrounds| backgrounds.iter().next()) - .and_then(|background| background["background"]["url"].as_str()) - .ok_or_else(|| anyhow::anyhow!("Failed to get background picture url"))? - .to_string(); + let lang = crate::i18n::get_lang(); + + let uri = if lang.language == unic_langid::langid!("zh-cn").language { + let api_uri = concat!("https://hyp-api.", "mi", "ho", "yo", ".com/hyp/hyp-connect/api/getAllGameBasicInfo?launcher_id=jGHBHlcOq1"); + + let json = serde_json::from_slice::(minreq::get(api_uri).send()?.as_bytes())?; + + json["data"]["game_info_list"].as_array() + .ok_or_else(|| anyhow::anyhow!("Failed to list games in the backgrounds API"))? + .iter() + .find(|game| { + match game["game"]["biz"].as_str() { + Some(biz) => biz.starts_with("bh3_"), + _ => false + } + }) + .ok_or_else(|| anyhow::anyhow!("Failed to find the game in the backgrounds API"))?["backgrounds"] + .as_array() + .and_then(|backgrounds| backgrounds.iter().next()) + .and_then(|background| background["background"]["url"].as_str()) + .map(|background| background.to_owned()) + } else { + let api_uri = concat!("https://bh3-launcher.", "ho", "yo", "verse", ".com/bh3_global/mdk/launcher/api/content?filter_adv=true&key=dpz65xJ3&launcher_id=10&language="); + + let json = serde_json::from_slice::(minreq::get(api_uri.to_string() + &crate::i18n::format_lang(lang)).send()?.as_bytes())?; + + json["data"]["adv"]["background"].as_str().map(|background| background.to_owned()) + }; + + let Some(uri) = uri else { + anyhow::bail!("Failed to get background picture url"); + }; let hash = uri.split('/') .last()