mirror of
https://github.com/amtoaer/bili-sync.git
synced 2026-05-06 20:42:48 +08:00
feat: 支持自定义 ffmpeg 路径 (#639)
This commit is contained in:
@@ -20,6 +20,9 @@ pub struct Args {
|
|||||||
|
|
||||||
#[arg(short, long, env = "BILI_SYNC_CONFIG_DIR")]
|
#[arg(short, long, env = "BILI_SYNC_CONFIG_DIR")]
|
||||||
pub config_dir: Option<PathBuf>,
|
pub config_dir: Option<PathBuf>,
|
||||||
|
|
||||||
|
#[arg(short, long, env = "BILI_SYNC_FFMPEG_PATH")]
|
||||||
|
pub ffmpeg_path: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
mod built_info {
|
mod built_info {
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ use tokio::task::JoinSet;
|
|||||||
use tokio_util::io::StreamReader;
|
use tokio_util::io::StreamReader;
|
||||||
|
|
||||||
use crate::bilibili::Client;
|
use crate::bilibili::Client;
|
||||||
use crate::config::ConcurrentDownloadLimit;
|
use crate::config::{ARGS, ConcurrentDownloadLimit};
|
||||||
|
|
||||||
pub struct Downloader {
|
pub struct Downloader {
|
||||||
client: Client,
|
client: Client,
|
||||||
@@ -70,7 +70,7 @@ impl Downloader {
|
|||||||
self.multi_fetch_internal(audio_urls, true, concurrent_download)
|
self.multi_fetch_internal(audio_urls, true, concurrent_download)
|
||||||
)?;
|
)?;
|
||||||
let final_temp_file = TempFile::new().await?;
|
let final_temp_file = TempFile::new().await?;
|
||||||
let output = Command::new("ffmpeg")
|
let output = Command::new(ARGS.ffmpeg_path.as_deref().unwrap_or("ffmpeg"))
|
||||||
.args([
|
.args([
|
||||||
"-i",
|
"-i",
|
||||||
video_temp_file.file_path().to_string_lossy().as_ref(),
|
video_temp_file.file_path().to_string_lossy().as_ref(),
|
||||||
|
|||||||
@@ -18,10 +18,12 @@ use std::fmt::Debug;
|
|||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use anyhow::{Context, Result, bail};
|
||||||
use bilibili::BiliClient;
|
use bilibili::BiliClient;
|
||||||
use parking_lot::RwLock;
|
use parking_lot::RwLock;
|
||||||
use sea_orm::DatabaseConnection;
|
use sea_orm::DatabaseConnection;
|
||||||
use task::{http_server, video_downloader};
|
use task::{http_server, video_downloader};
|
||||||
|
use tokio::process::Command;
|
||||||
use tokio_util::sync::CancellationToken;
|
use tokio_util::sync::CancellationToken;
|
||||||
use tokio_util::task::TaskTracker;
|
use tokio_util::task::TaskTracker;
|
||||||
|
|
||||||
@@ -33,8 +35,13 @@ use crate::utils::signal::terminate;
|
|||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
let (connection, log_writer) = init().await;
|
let (bili_client, connection, log_writer) = match init().await {
|
||||||
let bili_client = Arc::new(BiliClient::new());
|
Ok(res) => res,
|
||||||
|
Err(e) => {
|
||||||
|
error!("初始化失败:{:#}", e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let token = CancellationToken::new();
|
let token = CancellationToken::new();
|
||||||
let tracker = TaskTracker::new();
|
let tracker = TaskTracker::new();
|
||||||
@@ -77,7 +84,7 @@ fn spawn_task(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// 初始化日志系统、打印欢迎信息,初始化数据库连接和全局配置
|
/// 初始化日志系统、打印欢迎信息,初始化数据库连接和全局配置
|
||||||
async fn init() -> (DatabaseConnection, LogHelper) {
|
async fn init() -> Result<(Arc<BiliClient>, DatabaseConnection, LogHelper)> {
|
||||||
let (tx, _rx) = tokio::sync::broadcast::channel(30);
|
let (tx, _rx) = tokio::sync::broadcast::channel(30);
|
||||||
let log_history = Arc::new(RwLock::new(VecDeque::with_capacity(MAX_HISTORY_LOGS + 1)));
|
let log_history = Arc::new(RwLock::new(VecDeque::with_capacity(MAX_HISTORY_LOGS + 1)));
|
||||||
let log_writer = LogHelper::new(tx, log_history.clone());
|
let log_writer = LogHelper::new(tx, log_history.clone());
|
||||||
@@ -85,14 +92,26 @@ async fn init() -> (DatabaseConnection, LogHelper) {
|
|||||||
init_logger(&ARGS.log_level, Some(log_writer.clone()));
|
init_logger(&ARGS.log_level, Some(log_writer.clone()));
|
||||||
info!("欢迎使用 Bili-Sync,当前程序版本:{}", config::version());
|
info!("欢迎使用 Bili-Sync,当前程序版本:{}", config::version());
|
||||||
info!("项目地址:https://github.com/amtoaer/bili-sync");
|
info!("项目地址:https://github.com/amtoaer/bili-sync");
|
||||||
|
|
||||||
|
let ffmpeg_path = ARGS.ffmpeg_path.as_deref().unwrap_or("ffmpeg");
|
||||||
|
let ffmpeg_exists = Command::new(ffmpeg_path)
|
||||||
|
.arg("-version")
|
||||||
|
.output()
|
||||||
|
.await
|
||||||
|
.map(|output| output.status.success())
|
||||||
|
.unwrap_or(false);
|
||||||
|
if !ffmpeg_exists {
|
||||||
|
bail!("ffmpeg 不存在或无法执行,请确保已正确安装 ffmpeg,并且 {ffmpeg_path} 命令可用");
|
||||||
|
}
|
||||||
|
|
||||||
let connection = setup_database(&CONFIG_DIR.join("data.sqlite"))
|
let connection = setup_database(&CONFIG_DIR.join("data.sqlite"))
|
||||||
.await
|
.await
|
||||||
.expect("数据库初始化失败");
|
.context("数据库初始化失败")?;
|
||||||
info!("数据库初始化完成");
|
info!("数据库初始化完成");
|
||||||
VersionedConfig::init(&connection).await.expect("配置初始化失败");
|
VersionedConfig::init(&connection).await.context("配置初始化失败")?;
|
||||||
info!("配置初始化完成");
|
info!("配置初始化完成");
|
||||||
|
|
||||||
(connection, log_writer)
|
Ok((Arc::new(BiliClient::new()), connection, log_writer))
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn handle_shutdown(connection: DatabaseConnection, tracker: TaskTracker, token: CancellationToken) {
|
async fn handle_shutdown(connection: DatabaseConnection, tracker: TaskTracker, token: CancellationToken) {
|
||||||
|
|||||||
Reference in New Issue
Block a user