Created
May 18, 2022 18:49
-
-
Save ksqsf/3209df5ce1af63b254027000364550bb to your computer and use it in GitHub Desktop.
下载 Bilibili 音频
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env cargo play -q | |
//# anyhow = "*" | |
//# reqwest = {version="*", features=["gzip","blocking"]} | |
//# serde_json = "*" | |
fn main() -> anyhow::Result<()> { | |
let audio_id = "832257"; | |
let client = reqwest::blocking::Client::new(); | |
let body = client.get(format!("https://www.bilibili.com/audio/music-service-c/web/song/info?sid={}", audio_id)).send()?.text()?; | |
let resp = &serde_json::from_str::<serde_json::Value>(&body)?["data"]["cover"]; | |
let cover_url = resp.as_str().unwrap(); | |
let cover = client.get(cover_url).send()?.bytes()?; | |
std::fs::write("/tmp/ccc.jpg", cover)?; | |
let body = client.get(format!("https://www.bilibili.com/audio/music-service-c/web/url?sid={}", audio_id)).send()?.text()?; | |
let resp = &serde_json::from_str::<serde_json::Value>(&body)?["data"]["cdns"][0]; | |
let file_url = resp.as_str().unwrap(); | |
let file = client.get(file_url) | |
.header("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:99.0) Gecko/20100101 Firefox/99.0") | |
.header("Referer", "https://www.bilibili.com/") | |
.send()?.bytes()?; | |
std::fs::write("/tmp/aaa.m4a", file)?; | |
Ok(()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Rust so far is the best (statically) typed scripting language!!
Reasons: