Skip to content

Commit

Permalink
[mod] 使用 super
Browse files Browse the repository at this point in the history
  • Loading branch information
Borber committed Jan 12, 2023
1 parent bc4362d commit 987571f
Show file tree
Hide file tree
Showing 13 changed files with 96 additions and 9 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
|[斗鱼](https://www.douyu.com/)|`https://www.douyu.com/<RID>``https://www.douyu.com/xx/xx?rid=<RID>`|
|[抖音](https://live.douyin.com/)|`https://live.douyin.com/<RID>`|
|[虎牙](https://huya.com/)|`https://huya.com/<RID>`|
|[快手](https://live.kuaishou.com/)|`https://live.kuaishou.com/u/<RID>`|
|[CC](https://cc.163.com/)|`https://cc.163.com/<RID>`|
|[花椒](https://www.huajiao.com/)|`https://www.huajiao.com/l/<RID>`|
|[艺气山](https://www.173.com/)|`https://www.173.com/<RID>`|
|[棉花糖](https://www.2cq.com/)|`https://www.2cq.com/<RID>`|
Expand All @@ -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/)
Expand Down
2 changes: 1 addition & 1 deletion src/live/bilibili.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
64 changes: 64 additions & 0 deletions src/live/cc.rs
Original file line number Diff line number Diff line change
@@ -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<ShowType> {
let text = CLIENT.get(format!("{URL}{rid}")).send().await?.text().await?;
let re = Regex::new(r#"<script id="__NEXT_DATA__" type="application/json" crossorigin="anonymous">([\s\S]*?)</script>"#).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());
}
}
2 changes: 1 addition & 1 deletion src/live/douyin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion src/live/douyu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ async fn douyu_do_js(rid: &str) -> Result<Value> {

#[cfg(test)]
mod tests {
use crate::live::douyu::get;
use super::*;
use crate::util::match_show_type;

#[tokio::test]
Expand Down
2 changes: 1 addition & 1 deletion src/live/huajiao.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub async fn get(rid: &str) -> Result<ShowType> {

#[cfg(test)]
mod tests {
use crate::live::huajiao::get;
use super::*;
use crate::util::match_show_type;

#[tokio::test]
Expand Down
2 changes: 1 addition & 1 deletion src/live/huya.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub async fn get(rid: &str) -> Result<ShowType> {

#[cfg(test)]
mod tests {
use crate::live::huya::get;
use super::*;
use crate::util::match_show_type;

#[tokio::test]
Expand Down
2 changes: 1 addition & 1 deletion src/live/kuaishou.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub async fn get(rid: &str) -> Result<ShowType> {

#[cfg(test)]
mod tests {
use crate::live::kuaishou::get;
use super::*;
use crate::util::match_show_type;

#[tokio::test]
Expand Down
2 changes: 1 addition & 1 deletion src/live/mht.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub async fn get(rid: &str) -> Result<ShowType> {

#[cfg(test)]
mod tests {
use crate::live::mht::get;
use super::*;
use crate::util::match_show_type;

#[tokio::test]
Expand Down
1 change: 1 addition & 0 deletions src/live/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ pub mod huya;
pub mod kuaishou;
pub mod mht;
pub mod yqs;
pub mod cc;
2 changes: 1 addition & 1 deletion src/live/yqs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub async fn get(rid: &str) -> Result<ShowType> {

#[cfg(test)]
mod tests {
use crate::live::yqs::get;
use super::*;
use crate::util::match_show_type;

#[tokio::test]
Expand Down
8 changes: 7 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ ________ _______ _______ _______
|__ | ___| | |
|_______|_______|___|___|__|_|__|
获取直播源地址, 目前支持 B站, 斗鱼, 抖音, 虎牙, 快手, 花椒, 艺气山, 棉花糖", long_about = None)]
获取直播源地址, 目前支持 B站, 斗鱼, 抖音, 虎牙, 快手, 网易CC, 花椒, 艺气山, 棉花糖", long_about = None)]
struct Cli {
#[command(subcommand)]
command: Commands,
Expand Down Expand Up @@ -48,6 +48,11 @@ enum Commands {
/// 房间号
rid: String,
},
/// 网易CC
Cc {
/// 房间号
rid: String,
},
/// 花椒
Huajiao {
/// 房间号
Expand All @@ -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?),
Expand Down

0 comments on commit 987571f

Please sign in to comment.