Skip to content

Commit

Permalink
Update to 0.1.7
Browse files Browse the repository at this point in the history
  • Loading branch information
limitcool committed Nov 28, 2022
1 parent d26d08b commit ecfc9e2
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 9 deletions.
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 = "bilistream"
version = "0.1.6"
version = "0.1.7"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ B站直播自动转播工具,无人值守自动转播Twitch,Youtube(支持youtub
# 安装必须依赖ffmpeg,Twitch及youtube都需要安装ffmpeg
# debian
apt install ffmpeg -y
# 部分机器可能还需要以下操作
apt-get update
apt install python3-pip -y
# centos
yum install ffmpeg -y
# 如需转播Youtube需单独安装Yt-dlp
Expand Down Expand Up @@ -79,6 +82,8 @@ Push:
Host: 127.0.0.1:8080
# 推送到的qq群号
Target:
FfmpegProxy: http://127.0.0.1:7890
# Ffmpeg代理地址,无需代理可以不填此项或者留空
```

### Youtube API申请地址
Expand All @@ -96,4 +101,4 @@ A:BiliRtmpUrl及 BiliRtmpKey 填写错误或使用海外机器进行推流,B站

Q:转播Youtube时出现`Connection to tcp://manifest.googlevideo.com:443 failed: Error number -138 occurred`

A: YT-DLP获取到的M3U8链接无法正常播放,需要等待Yt-dlp修复或更换其他方式获取M3U8链接。
A: Ffmpeg拉流未通过代理,请在配置项填写 FfmpegProxy: http://127.0.0.1:7890
2 changes: 2 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ pub struct Config {
pub push: Option<Push>,
#[serde(rename = "YoutubePreviewLive")]
pub youtube_preview_live: YoutubePreviewLive,
#[serde(rename = "FfmpegProxy")]
pub ffmpeg_proxy: Option<String>,
}

#[derive(Debug, Serialize, Deserialize, Clone)]
Expand Down
19 changes: 13 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use reqwest::{cookie::Jar, Url};
use reqwest_retry::policies::ExponentialBackoff;
use reqwest_retry::RetryTransientMiddleware;
use reqwest_middleware::{ClientBuilder};
use tracing_subscriber::{filter::EnvFilter,fmt::{self, format}, layer::SubscriberExt, util::SubscriberInitExt};
use tracing_subscriber::{filter::EnvFilter,fmt::{self}, layer::SubscriberExt, util::SubscriberInitExt};
use std::process::Command;
use config::{load_config,Config};

Expand Down Expand Up @@ -51,15 +51,15 @@ async fn main() {

if get_bili_live_state(cfg.bililive.room.clone()).await {
tracing::info!("B站直播中");
ffmpeg(cfg.bililive.bili_rtmp_url.clone(), cfg.bililive.bili_rtmp_key.clone(), r.get_real_m3u8_url().await.unwrap());
ffmpeg(cfg.bililive.bili_rtmp_url.clone(), cfg.bililive.bili_rtmp_key.clone(), r.get_real_m3u8_url().await.unwrap(),cfg.ffmpeg_proxy.clone());
}else{
tracing::info!("B站未直播");
bili_start_live(&cfg).await;
tracing::info!("B站已开播");
ffmpeg(cfg.bililive.bili_rtmp_url.clone(), cfg.bililive.bili_rtmp_key.clone(), r.get_real_m3u8_url().await.unwrap());
ffmpeg(cfg.bililive.bili_rtmp_url.clone(), cfg.bililive.bili_rtmp_key.clone(), r.get_real_m3u8_url().await.unwrap(),cfg.ffmpeg_proxy.clone());
loop {
if r.get_status().await.unwrap() {
ffmpeg(cfg.bililive.bili_rtmp_url.clone(), cfg.bililive.bili_rtmp_key.clone(), r.get_real_m3u8_url().await.unwrap());
ffmpeg(cfg.bililive.bili_rtmp_url.clone(), cfg.bililive.bili_rtmp_key.clone(), r.get_real_m3u8_url().await.unwrap(),cfg.ffmpeg_proxy.clone());
}else{
break;
}
Expand Down Expand Up @@ -170,10 +170,17 @@ async fn bili_stop_live(cfg:&Config){



pub fn ffmpeg(rtmp_url:String,rtmp_key:String,m3u8_url:String){
pub fn ffmpeg(rtmp_url:String,rtmp_key:String,m3u8_url:String,ffmpeg_proxy:Option<String>){
// let cmd = format!("{}&key={}",rtmp_url,rtmp_key);
let cmd = format!("{}{}",rtmp_url,rtmp_key);
let mut command =Command::new("ffmpeg");
// if ffmpeg_proxy.clone()!= "" {
// command.arg(ffmpeg_proxy.clone());
// }
if ffmpeg_proxy.is_some() {
command.arg("-http_proxy");
command.arg(ffmpeg_proxy.clone().unwrap());
}
command.arg("-re");
command.arg("-i");
command.arg(m3u8_url.clone());
Expand All @@ -190,7 +197,7 @@ pub fn ffmpeg(rtmp_url:String,rtmp_key:String,m3u8_url:String){
if code == 0 {
println!("Command executed successfully");
} else {
ffmpeg(rtmp_url, rtmp_key, m3u8_url)
ffmpeg(rtmp_url, rtmp_key, m3u8_url,ffmpeg_proxy)
}
}
None => {
Expand Down

0 comments on commit ecfc9e2

Please sign in to comment.