Skip to content

Commit

Permalink
[mod] 添加kk, 千帆, bilibili弹幕-预览版
Browse files Browse the repository at this point in the history
  • Loading branch information
Borber committed Jan 18, 2023
1 parent 689ca4a commit b36b8a1
Show file tree
Hide file tree
Showing 22 changed files with 114 additions and 24 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]


## [0.1.13]

### Added

- 添加 kk 直播源获取
- 添加 千帆直播源获取
- bili 直播弹幕获取-预览版

## [0.1.12]

### 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.12"
version = "0.1.13"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
|[花椒](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>`|
|[kk](https://www.kktv5.com/)|`https://www.kktv5.com/show/<RID>`|
|[千帆直播](https://qf.56.com/)|`https://qf.56.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>` 主播名字而非直播间号|
Expand Down
7 changes: 3 additions & 4 deletions src/declarative.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ use crate::{
danmu::{self, Danmu},
live, Cli,
};
use std::path::PathBuf;
use anyhow::{Ok, Result};
use clap::{Parser, Subcommand};
use paste::paste;
use std::path::PathBuf;

// 声明宏:获取直播源的command的实现
macro_rules! get_source_url_command {
Expand Down Expand Up @@ -49,7 +49,7 @@ macro_rules! get_source_url_command {
// 展开宏命令
// 添加新的直播平台可以在括号末尾添加,并在live文件夹里添加对应的文件
get_source_url_command!(
Bili, Douyu, Douyin, Huya, Kuaishou, Cc, Huajiao, Yqs, Mht, Now, Afreeca, Panda, Flex, Wink
Bili, Douyu, Douyin, Huya, Kuaishou, Cc, Huajiao, Kk, Qf, Yqs, Mht, Now, Afreeca, Panda, Flex, Wink
);

// 为没有实现弹幕功能的直播平台添加默认空白实现
Expand Down Expand Up @@ -78,6 +78,5 @@ macro_rules! default_danmu_client {
}
}
}

}
};
}
2 changes: 1 addition & 1 deletion src/live/afreeca.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::collections::HashMap;
use anyhow::{Ok, Result};
use regex::Regex;

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

const URL: &str = "https://play.afreecatv.com/";
const PLAY_URL: &str = "https://live.afreecatv.com/afreeca/player_live_api.php?bjid=";
Expand Down
2 changes: 1 addition & 1 deletion src/live/bili.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ impl BiliDanmuClient {
/// 初始化websocket
async fn init_ws(&mut self) {
let reg_datas = Self::get_ws_info(&self.room_id);
let (mut ws, _)= tokio_tungstenite::connect_async(WSS_URL).await.unwrap();
let (mut ws, _) = tokio_tungstenite::connect_async(WSS_URL).await.unwrap();
for data in reg_datas {
Pin::new(&mut ws).start_send(Message::Binary(data)).unwrap();
}
Expand Down
2 changes: 1 addition & 1 deletion src/live/cc.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{common::CLIENT, model::ShowType, util::parse_url, default_danmu_client};
use crate::{common::CLIENT, default_danmu_client, model::ShowType, util::parse_url};
use anyhow::{Ok, Result};
use regex::Regex;

Expand Down
2 changes: 1 addition & 1 deletion src/live/douyin.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{common::CLIENT, model::ShowType, util::parse_url, default_danmu_client};
use crate::{common::CLIENT, default_danmu_client, model::ShowType, util::parse_url};

use anyhow::{Ok, Result};
use regex::Regex;
Expand Down
2 changes: 1 addition & 1 deletion src/live/douyu.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::collections::HashMap;

use crate::{common::CLIENT, model::ShowType, default_danmu_client};
use crate::{common::CLIENT, default_danmu_client, model::ShowType};

use crate::util::{do_js, md5, parse_url};
use anyhow::{Ok, Result};
Expand Down
2 changes: 1 addition & 1 deletion src/live/flex.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use anyhow::{Ok, Result};

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

const URL: &str = "https://api.flextv.co.kr/api/channels/rid/stream?option=all";

Expand Down
2 changes: 1 addition & 1 deletion src/live/huajiao.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use anyhow::{Ok, Result};
use regex::Regex;

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

const URL: &str = "https://www.huajiao.com/l/";

Expand Down
2 changes: 1 addition & 1 deletion src/live/huya.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use anyhow::{Ok, Result};
use regex::Regex;

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

const URL: &str = "https://www.huya.com/";

Expand Down
37 changes: 37 additions & 0 deletions src/live/kk.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use anyhow::{Ok, Result};
use regex::Regex;

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

const URL: &str = "https://sgapi.kktv8.com/roomApi/room/roomVideoBitrate?roomId=";

default_danmu_client!(Kk);

/// kk直播
///
/// https://www.kktv5.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#"http[\s\S]*?flv"#).unwrap();
match re.captures(&text) {
Some(cap) => Ok(ShowType::On(vec![parse_url(
cap.get(0).unwrap().as_str().to_string(),
)])),
None => Ok(ShowType::Off),
}
}

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

#[tokio::test]
async fn test_get_url() {
println!("{}", get("157079155").await.unwrap());
}
}
2 changes: 1 addition & 1 deletion src/live/kuaishou.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use regex::Regex;

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

const URL: &str = "https://live.kuaishou.com/u/";
Expand Down
2 changes: 1 addition & 1 deletion src/live/mht.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{common::CLIENT, model::ShowType, util::parse_url, default_danmu_client};
use crate::{common::CLIENT, default_danmu_client, model::ShowType, util::parse_url};

use anyhow::{Ok, Result};
use serde_json::Value;
Expand Down
2 changes: 2 additions & 0 deletions src/live/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ pub mod douyu;
pub mod flex;
pub mod huajiao;
pub mod huya;
pub mod kk;
pub mod kuaishou;
pub mod mht;
pub mod now;
pub mod panda;
pub mod qf;
pub mod wink;
pub mod yqs;
15 changes: 10 additions & 5 deletions src/live/now.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use anyhow::{Ok, Result};

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

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

Expand All @@ -10,7 +10,12 @@ default_danmu_client!(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?;
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![];
Expand All @@ -20,8 +25,8 @@ pub async fn get(rid: &str) -> Result<ShowType> {
}
}
Ok(ShowType::On(urls))
},
false => Ok(ShowType::Off)
}
false => Ok(ShowType::Off),
}
}

Expand All @@ -33,4 +38,4 @@ mod tests {
async fn test_get_url() {
println!("{}", get("1347547853").await.unwrap());
}
}
}
2 changes: 1 addition & 1 deletion src/live/panda.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use anyhow::{Ok, Result};

const URL: &str = "https://api.pandalive.co.kr/v1/live/play/";

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

default_danmu_client!(Panda);

Expand Down
37 changes: 37 additions & 0 deletions src/live/qf.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use anyhow::{Ok, Result};
use regex::Regex;

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

const URL: &str = "https://qf.56.com/";

default_danmu_client!(Qf);

/// 千帆直播
///
/// https://www.kktv5.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#"flvUrl:'([\s\S]*?)'"#).unwrap();
match re.captures(&text) {
Some(cap) => Ok(ShowType::On(vec![parse_url(
cap.get(1).unwrap().as_str().to_string(),
)])),
None => Ok(ShowType::Off),
}
}

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

#[tokio::test]
async fn test_get_url() {
println!("{}", get("520006").await.unwrap());
}
}
2 changes: 1 addition & 1 deletion src/live/wink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use anyhow::{Ok, Result};

const URL: &str = "https://api.winktv.co.kr/v1/live/play";

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

default_danmu_client!(Wink);

Expand Down
2 changes: 1 addition & 1 deletion src/live/yqs.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{common::CLIENT, model::ShowType, util::parse_url, default_danmu_client};
use crate::{common::CLIENT, default_danmu_client, model::ShowType, util::parse_url};

use anyhow::{Ok, Result};
use std::collections::HashMap;
Expand Down

0 comments on commit b36b8a1

Please sign in to comment.