Skip to content

Commit

Permalink
check ffmpeg
Browse files Browse the repository at this point in the history
  • Loading branch information
kingwingfly committed Aug 18, 2024
1 parent 68ad4c5 commit 57ab91b
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 12 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
6 changes: 3 additions & 3 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>"]
description = "Back up your favorite online resources with CLI."
license = "MIT"
Expand All @@ -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"
Expand Down
14 changes: 14 additions & 0 deletions fav_cli/src/bili/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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(())
}
16 changes: 11 additions & 5 deletions fav_cli/src/bili/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()?;
Expand Down
2 changes: 1 addition & 1 deletion fav_utils/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 5 additions & 0 deletions fav_utils/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ pub enum FavUtilsError {
QrExpired,
/// FFMPEG merge failed
MergeFailed,
/// FFMPEG not found
FFMPEGNotFound,
}

impl std::error::Error for FavUtilsError {}
Expand All @@ -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")
}
}
}
}
Expand Down

0 comments on commit 57ab91b

Please sign in to comment.