Skip to content

Commit

Permalink
[mod] 添加now平台支持
Browse files Browse the repository at this point in the history
  • Loading branch information
Borber committed Jan 18, 2023
1 parent 7ecb323 commit 2a37517
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 6 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.12]

### Added

- 添加 now 直播源获取

### Changed

- Format 添加 rtmp 格式


## [0.1.11]

### Added
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "seam"
version = "0.1.11"
version = "0.1.12"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
|[花椒](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>`|
|[Now直播](https://now.qq.com/)|`https://now.qq.com/pcweb/story.html?roomid=<RID>`|
|[afreeca](https://afreecatv.com/)|`https://bj.afreecatv.com/<RID>` 主播名字而非直播间号|
|[pandalive](https://www.pandalive.co.kr/)|`https://www.pandalive.co.kr/channel/<RID>` 主播名字而非直播间号|
|[flex](https://www.flextv.co.kr/)|`https://www.flextv.co.kr/channels/<RID>` 主播名字而非直播间号|
Expand Down
2 changes: 1 addition & 1 deletion src/declarative.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ macro_rules! get_source_url_command {
// 展开宏命令
// 添加新的直播平台可以在括号末尾添加,并在live文件夹里添加对应的文件
get_source_url_command!(
Bili, Douyu, Douyin, Huya, Kuaishou, Cc, Huajiao, Yqs, Mht, Afreeca, Panda, Flex, Wink
Bili, Douyu, Douyin, Huya, Kuaishou, Cc, Huajiao, Yqs, Mht, Now, Afreeca, Panda, Flex, Wink
);
1 change: 1 addition & 0 deletions src/live/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub mod huajiao;
pub mod huya;
pub mod kuaishou;
pub mod mht;
pub mod now;
pub mod panda;
pub mod wink;
pub mod yqs;
34 changes: 34 additions & 0 deletions src/live/now.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use anyhow::{Ok, Result};

use crate::{model::ShowType, common::CLIENT, util::parse_url};

const URL: &str = "https://now.qq.com/cgi-bin/now/web/room/get_live_room_url?platform=8&room_id=";

/// NOW直播
///
/// https://now.qq.com/
pub async fn get(rid: &str) -> Result<ShowType> {
let json: serde_json::Value = CLIENT.get(format!("{URL}{rid}")).send().await?.json().await?;
match &json["result"]["is_on_live"].as_bool().unwrap() {
true => {
let mut urls = vec![];
for f in ["raw_flv_url", "raw_hls_url", "raw_rtmp_url"] {
if let Some(url) = json["result"][f].as_str() {
urls.push(parse_url(url.to_string()));
}
}
Ok(ShowType::On(urls))
},
false => Ok(ShowType::Off)
}
}

#[cfg(test)]
mod tests {
use super::*;

#[tokio::test]
async fn test_get_url() {
println!("{}", get("1347547853").await.unwrap());
}
}
2 changes: 2 additions & 0 deletions src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub struct Node {
pub enum Format {
FLV,
M3U,
RTMP,
Other(String),
}
/// 自定义序列化方法
Expand All @@ -45,6 +46,7 @@ impl Serialize for Format {
let str = match self {
Format::FLV => "flv",
Format::M3U => "m3u",
Format::RTMP => "rtmp",
Format::Other(s) => s.as_str(),
};
serializer.serialize_str(str)
Expand Down
10 changes: 7 additions & 3 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,15 @@ pub async fn do_js(js: &str) -> String {
}

pub fn match_format(url: &str) -> Format {
if url.contains("m3u8") {
if url.contains(".m3u8") {
Format::M3U
} else if url.contains("flv") {
} else if url.contains(".flv") {
Format::FLV
} else {
}
else if url.contains("rtmp:") {
Format::RTMP
}
else {
Format::Other("unknown".to_owned())
}
}
Expand Down

0 comments on commit 2a37517

Please sign in to comment.