diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d1c5ba..6e77ad3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] + + +## [0.1.7] + +### Added + +- 支持网易CC直播源获取 + +### Changed + +- 使用 `super` 替代绝对位置 + ## [0.1.6] ### Added diff --git a/README.md b/README.md index d4d7d73..5488c12 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,8 @@ |[斗鱼](https://www.douyu.com/)|`https://www.douyu.com/` 或 `https://www.douyu.com/xx/xx?rid=`| |[抖音](https://live.douyin.com/)|`https://live.douyin.com/`| |[虎牙](https://huya.com/)|`https://huya.com/`| +|[快手](https://live.kuaishou.com/)|`https://live.kuaishou.com/u/`| +|[CC](https://cc.163.com/)|`https://cc.163.com/`| |[花椒](https://www.huajiao.com/)|`https://www.huajiao.com/l/`| |[艺气山](https://www.173.com/)|`https://www.173.com/`| |[棉花糖](https://www.2cq.com/)|`https://www.2cq.com/`| @@ -42,6 +44,8 @@ - [x] [斗鱼](https://www.douyu.com/) - [x] [抖音](https://live.douyin.com/) - [x] [虎牙](https://huya.com/) + - [x] [快手](https://live.kuaishou.com/) + - [x] [CC](https://cc.163.com/) - [x] [花椒](https://www.huajiao.com/) - [x] [艺气山](https://www.173.com/) - [x] [棉花糖](https://www.2cq.com/) diff --git a/src/live/bilibili.rs b/src/live/bilibili.rs index 5d97a6a..602adfd 100644 --- a/src/live/bilibili.rs +++ b/src/live/bilibili.rs @@ -116,7 +116,7 @@ fn convert_qn_to_quality_string(qn: &str) -> String { #[cfg(test)] mod tests { - use crate::live::bilibili::get; + use super::*; use crate::util::match_show_type; #[tokio::test] diff --git a/src/live/cc.rs b/src/live/cc.rs new file mode 100644 index 0000000..34f8e6c --- /dev/null +++ b/src/live/cc.rs @@ -0,0 +1,64 @@ +use anyhow::{Ok, Result}; +use regex::Regex; +use crate::{modle::{Node, ShowType}, common::CLIENT}; + +const URL: &str = "https://cc.163.com/"; + +/// 网易CC直播 +/// +/// https://cc.163.com/ +pub async fn get(rid: &str) -> Result { + let text = CLIENT.get(format!("{URL}{rid}")).send().await?.text().await?; + let re = Regex::new(r#""#).unwrap(); + let json = match re.captures(&text) { + Some(rap) => { + rap.get(1).unwrap().as_str() + }, + None => { + return Ok(ShowType::Error("未找到直播间".to_string())); + }, + }; + let json: serde_json::Value = serde_json::from_str(&json)?; + let resolution = match &json["props"]["pageProps"]["roomInfoInitData"]["live"]["quickplay"]["resolution"] { + serde_json::Value::Null => return Ok(ShowType::Off), + v => v, + }; + let mut nodes = vec![]; + for vbr in ["blueray", "ultra", "high", "standard"] { + let cdn = change_str(vbr); + if resolution[vbr] != serde_json::Value::Null { + nodes.push(Node{ + rate: format!("{cdn}-ali"), + url: resolution[vbr]["cdn"]["ali"].as_str().unwrap().to_string(), + }); + nodes.push(Node{ + rate: format!("{cdn}-ks"), + url: resolution[vbr]["cdn"]["ks"].as_str().unwrap().to_string(), + }); + break; + } + } + Ok(ShowType::On(nodes)) +} + +fn change_str(s: &str) -> &str { + match s { + "blueray" => "蓝光", + "ultra" => "超清", + "high" => "高清", + "standard" => "标清", + _ => "未知", + } +} + + +#[cfg(test)] +mod tests{ + use super::*; + use crate::util::match_show_type; + + #[tokio::test] + async fn test_get_url() { + match_show_type(get("361433").await.unwrap()); + } +} \ No newline at end of file diff --git a/src/live/douyin.rs b/src/live/douyin.rs index abac95f..da1a23e 100644 --- a/src/live/douyin.rs +++ b/src/live/douyin.rs @@ -54,7 +54,7 @@ fn douyin_trim_value(v: &Value) -> String { #[cfg(test)] mod tests { - use crate::live::douyin::get; + use super::*; use crate::util::match_show_type; #[tokio::test] async fn test_get_url() { diff --git a/src/live/douyu.rs b/src/live/douyu.rs index e5eb7e7..e786e4b 100644 --- a/src/live/douyu.rs +++ b/src/live/douyu.rs @@ -133,7 +133,7 @@ async fn douyu_do_js(rid: &str) -> Result { #[cfg(test)] mod tests { - use crate::live::douyu::get; + use super::*; use crate::util::match_show_type; #[tokio::test] diff --git a/src/live/huajiao.rs b/src/live/huajiao.rs index 9b13a39..4cf1210 100644 --- a/src/live/huajiao.rs +++ b/src/live/huajiao.rs @@ -44,7 +44,7 @@ pub async fn get(rid: &str) -> Result { #[cfg(test)] mod tests { - use crate::live::huajiao::get; + use super::*; use crate::util::match_show_type; #[tokio::test] diff --git a/src/live/huya.rs b/src/live/huya.rs index 0264f05..ac360ad 100644 --- a/src/live/huya.rs +++ b/src/live/huya.rs @@ -60,7 +60,7 @@ pub async fn get(rid: &str) -> Result { #[cfg(test)] mod tests { - use crate::live::huya::get; + use super::*; use crate::util::match_show_type; #[tokio::test] diff --git a/src/live/kuaishou.rs b/src/live/kuaishou.rs index 134a9cc..63b3358 100644 --- a/src/live/kuaishou.rs +++ b/src/live/kuaishou.rs @@ -46,7 +46,7 @@ pub async fn get(rid: &str) -> Result { #[cfg(test)] mod tests { - use crate::live::kuaishou::get; + use super::*; use crate::util::match_show_type; #[tokio::test] diff --git a/src/live/mht.rs b/src/live/mht.rs index c7c44bd..365f398 100644 --- a/src/live/mht.rs +++ b/src/live/mht.rs @@ -39,7 +39,7 @@ pub async fn get(rid: &str) -> Result { #[cfg(test)] mod tests { - use crate::live::mht::get; + use super::*; use crate::util::match_show_type; #[tokio::test] diff --git a/src/live/mod.rs b/src/live/mod.rs index a871f83..162d59b 100644 --- a/src/live/mod.rs +++ b/src/live/mod.rs @@ -6,3 +6,4 @@ pub mod huya; pub mod kuaishou; pub mod mht; pub mod yqs; +pub mod cc; diff --git a/src/live/yqs.rs b/src/live/yqs.rs index edb2e39..f530669 100644 --- a/src/live/yqs.rs +++ b/src/live/yqs.rs @@ -27,7 +27,7 @@ pub async fn get(rid: &str) -> Result { #[cfg(test)] mod tests { - use crate::live::yqs::get; + use super::*; use crate::util::match_show_type; #[tokio::test] diff --git a/src/main.rs b/src/main.rs index 7f5afaa..ddc30c9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,7 +15,7 @@ ________ _______ _______ _______ |__ | ___| | | |_______|_______|___|___|__|_|__| -获取直播源地址, 目前支持 B站, 斗鱼, 抖音, 虎牙, 快手, 花椒, 艺气山, 棉花糖", long_about = None)] +获取直播源地址, 目前支持 B站, 斗鱼, 抖音, 虎牙, 快手, 网易CC, 花椒, 艺气山, 棉花糖", long_about = None)] struct Cli { #[command(subcommand)] command: Commands, @@ -48,6 +48,11 @@ enum Commands { /// 房间号 rid: String, }, + /// 网易CC + Cc { + /// 房间号 + rid: String, + }, /// 花椒 Huajiao { /// 房间号 @@ -74,6 +79,7 @@ async fn main() -> Result<()> { Commands::Douyin { rid } => util::match_show_type(live::douyin::get(&rid).await?), Commands::Huya { rid } => util::match_show_type(live::huya::get(&rid).await?), Commands::Kuaishou { rid } => util::match_show_type(live::kuaishou::get(&rid).await?), + Commands::Cc { rid } => util::match_show_type(live::cc::get(&rid).await?), Commands::Huajiao { rid } => util::match_show_type(live::huajiao::get(&rid).await?), Commands::Yqs { rid } => util::match_show_type(live::yqs::get(&rid).await?), Commands::Mht { rid } => util::match_show_type(live::mht::get(&rid).await?),