From f37465598e66e3bfc413d10ab2b592fcd05e85db Mon Sep 17 00:00:00 2001 From: Louis <836250617@qq.com> Date: Sun, 18 Aug 2024 20:50:17 +0800 Subject: [PATCH] check ffmpeg --- CHANGELOG.md | 4 ++++ Cargo.lock | 6 +++--- Cargo.toml | 6 +++--- fav_cli/src/bili/action.rs | 14 ++++++++++++++ fav_cli/src/bili/mod.rs | 16 +++++++++++----- fav_utils/Cargo.toml | 2 +- fav_utils/src/error.rs | 5 +++++ 7 files changed, 41 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bd9136b..11a50eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,10 @@ Note: In this file, do not use the hard wrap in the middle of a sentence for com --> ## [Unreleased] +## [0.2.31] - 2024-08-18 + +- improve: `pull` will check ffmpeg before running. + ## [0.2.30] - 2024-06-18 - fix: wrong hint of `fav status -h` diff --git a/Cargo.lock b/Cargo.lock index 910d091..add9730 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -371,7 +371,7 @@ checksum = "9fc0510504f03c51ada170672ac806f1f105a88aa97a5281117e1ddc3368e51a" [[package]] name = "fav" -version = "0.2.30" +version = "0.2.31" dependencies = [ "fav_cli", "tokio", @@ -381,7 +381,7 @@ dependencies = [ [[package]] name = "fav_cli" -version = "0.2.30" +version = "0.2.31" dependencies = [ "chrono", "clap", @@ -429,7 +429,7 @@ dependencies = [ [[package]] name = "fav_utils" -version = "0.0.12" +version = "0.0.13" dependencies = [ "fav_core", "futures", diff --git a/Cargo.toml b/Cargo.toml index 22c48fe..e7a5c2e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,7 @@ resolver = "2" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [workspace.package] -version = "0.2.30" +version = "0.2.31" authors = ["Louis <836250617@qq.com>"] description = "Back up your favorite online resources with CLI." license = "MIT" @@ -16,8 +16,8 @@ documentation = "" [workspace.dependencies] fav_core = { path = "fav_core", version = "0.1.4" } fav_derive = { path = "fav_derive", version = "0.0.2" } -fav_utils = { path = "fav_utils", version = "0.0.12" } -fav_cli = { path = "fav_cli", version = "0.2.30" } +fav_utils = { path = "fav_utils", version = "0.0.13" } +fav_cli = { path = "fav_cli", version = "0.2.31" } [profile.release] lto = "fat" diff --git a/fav_cli/src/bili/action.rs b/fav_cli/src/bili/action.rs index 239b7a6..23b423a 100644 --- a/fav_cli/src/bili/action.rs +++ b/fav_cli/src/bili/action.rs @@ -3,6 +3,7 @@ use fav_core::prelude::*; use fav_core::status::SetStatusExt as _; use fav_core::visual::{TableRes as _, TableSet as _, TableSets as _}; use fav_utils::bili::{Bili, BiliSets}; +use fav_utils::FavUtilsError; use std::io::Write as _; use tracing::{error, info, warn}; @@ -229,3 +230,16 @@ pub(super) async fn daemon(sets: &mut BiliSets, interval: u64) -> FavCoreResult< } Ok(()) } + +pub(super) fn check_ffmpeg() -> FavCoreResult<()> { + let status = std::process::Command::new("ffmpeg") + .arg("-version") + .stdout(std::process::Stdio::null()) + .stderr(std::process::Stdio::null()) + .status() + .unwrap(); + if !status.success() { + return Err(FavUtilsError::FFMPEGNotFound.into()); + } + Ok(()) +} diff --git a/fav_cli/src/bili/mod.rs b/fav_cli/src/bili/mod.rs index 438ed00..07bc6c7 100644 --- a/fav_cli/src/bili/mod.rs +++ b/fav_cli/src/bili/mod.rs @@ -158,11 +158,17 @@ impl Cli { Commands::Fetch => fetch(&mut sets).await, Commands::Track { id: ids } => track(&mut sets, ids), Commands::Untrack { id: ids } => untrack(&mut sets, ids), - Commands::Pull { id } => match id { - Some(ids) => pull(&mut sets, ids).await, - None => pull_all(&mut sets).await, - }, - Commands::Daemon { interval } => daemon(&mut sets, interval).await, + Commands::Pull { id } => { + check_ffmpeg()?; + match id { + Some(ids) => pull(&mut sets, ids).await, + None => pull_all(&mut sets).await, + } + } + Commands::Daemon { interval } => { + check_ffmpeg()?; + daemon(&mut sets, interval).await + } _ => unreachable!(), }; sets.write()?; diff --git a/fav_utils/Cargo.toml b/fav_utils/Cargo.toml index 7b451f7..4a24092 100644 --- a/fav_utils/Cargo.toml +++ b/fav_utils/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "fav_utils" -version = "0.0.12" +version = "0.0.13" authors.workspace = true description = "Fav's utils crate; A collection of utilities and data structures for the fav project" license.workspace = true diff --git a/fav_utils/src/error.rs b/fav_utils/src/error.rs index e2d0cab..5e195ff 100644 --- a/fav_utils/src/error.rs +++ b/fav_utils/src/error.rs @@ -15,6 +15,8 @@ pub enum FavUtilsError { QrExpired, /// FFMPEG merge failed MergeFailed, + /// FFMPEG not found + FFMPEGNotFound, } impl std::error::Error for FavUtilsError {} @@ -27,6 +29,9 @@ impl std::fmt::Display for FavUtilsError { FavUtilsError::NoCookie => write!(f, "No cookie"), FavUtilsError::QrExpired => write!(f, "Qr code expired"), FavUtilsError::MergeFailed => write!(f, "FFMPEG merge failed"), + FavUtilsError::FFMPEGNotFound => { + write!(f, "FFMPEG should be able to be directly called") + } } } }