From dbab46143156c1c2bd7a457e3408d88a74662d40 Mon Sep 17 00:00:00 2001 From: limitcool Date: Mon, 15 Aug 2022 15:05:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=83=A8=E5=88=86=E6=83=85?= =?UTF-8?q?=E5=86=B5=E4=B8=8B=E8=8E=B7=E5=8F=96=E4=B8=8D=E5=88=B0youtube?= =?UTF-8?q?=E7=9B=B4=E6=92=AD=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 ++ Cargo.lock | 2 +- Cargo.toml | 2 +- src/plugins/live.rs | 23 +++++++++++++++++------ 4 files changed, 21 insertions(+), 8 deletions(-) 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())