diff --git a/.gitignore b/.gitignore index 59b2d02..bdb32a9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ /target config.yaml +body.html +live_id.json diff --git a/Cargo.lock b/Cargo.lock index 3ff9e9e..23342e4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -72,7 +72,7 @@ checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" [[package]] name = "bilistream" -version = "0.1.3" +version = "0.1.4" dependencies = [ "async-trait", "m3u8-rs", diff --git a/Cargo.toml b/Cargo.toml index 8ffbb14..8c1c8d9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bilistream" -version = "0.1.3" +version = "0.1.4" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/src/plugins/live.rs b/src/plugins/live.rs index 8672f38..fadbb78 100644 --- a/src/plugins/live.rs +++ b/src/plugins/live.rs @@ -105,6 +105,7 @@ pub async fn get_live_id(channel_name: &str) -> Result> { .build(); let url = format!("https://www.youtube.com/channel/{}", channel_name); tracing::debug!("{}", url); + // println!("channel地址为:{}", url); let res = client.get(&url).send().await?; let body = res.text().await?; // 保存body为文件,后缀为html @@ -131,12 +132,19 @@ pub async fn get_live_id(channel_name: &str) -> Result> { // let json = json.split("\"").nth(1).unwrap(); // let json = json.split("\"").nth(0).unwrap(); let j: Value = serde_json::from_str(json).unwrap(); - let video_id = j["contents"]["twoColumnBrowseResultsRenderer"]["tabs"][0]["tabRenderer"] - ["content"]["sectionListRenderer"]["contents"][1]["itemSectionRenderer"]["contents"][0] - ["shelfRenderer"]["content"]["horizontalListRenderer"]["items"][0]["gridVideoRenderer"] - ["videoId"] + let mut video_id = j["contents"]["twoColumnBrowseResultsRenderer"]["tabs"][0] + ["tabRenderer"]["content"]["sectionListRenderer"]["contents"][1]["itemSectionRenderer"] + ["contents"][0]["shelfRenderer"]["content"]["horizontalListRenderer"]["items"][0] + ["gridVideoRenderer"]["videoId"] .to_string(); - + if video_id == "null" { + video_id = j["contents"]["twoColumnBrowseResultsRenderer"]["tabs"][0]["tabRenderer"] + ["content"]["sectionListRenderer"]["contents"][2]["itemSectionRenderer"] + ["contents"][0]["shelfRenderer"]["content"]["horizontalListRenderer"]["items"][0] + ["gridVideoRenderer"]["videoId"] + .to_string(); + } + // println!("获取到的videoId为:{}", video_id); tracing::debug!( "{}", j["contents"]["twoColumnBrowseResultsRenderer"]["tabs"][0]["tabRenderer"]["content"] @@ -147,7 +155,10 @@ pub async fn get_live_id(channel_name: &str) -> Result> { // 将结果保存为一个json文件 let mut file = std::fs::File::create("live_id.json").unwrap(); std::io::Write::write_all(&mut file, json.as_bytes()).unwrap(); - return Ok(video_id); + if video_id == "null" { + } else { + return Ok(video_id); + } } Err("获取video_id失败".into())