From a3d03cf30f736efad836654f1c5f5d9cbfcf935d Mon Sep 17 00:00:00 2001 From: YoursFunny Date: Thu, 24 Sep 2026 04:37:52 +0800 Subject: [PATCH] refactor(site): one ffmpeg gate instead of a probe plus a log call MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ffmpeg_available() and log_once_ffmpeg_missing() only ever appeared together (both encoders, three lines each: check, log, return), and calling one without the other was a bug in waiting — a probe that never logged, or a log that never gated. ffmpeg_missing() is the single gate: false when the binary is there, otherwise log once per process and say yes. Both call sites shrink to one condition. --- crates/x-media/src/site/bsky/interface.rs | 3 +-- crates/x-media/src/site/mod.rs | 13 ++++++++----- crates/x-media/src/site/pixiv/api.rs | 3 +-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/crates/x-media/src/site/bsky/interface.rs b/crates/x-media/src/site/bsky/interface.rs index efafe9f..8859f7d 100644 --- a/crates/x-media/src/site/bsky/interface.rs +++ b/crates/x-media/src/site/bsky/interface.rs @@ -153,8 +153,7 @@ async fn fetch_hls(url: &str, cap: u64) -> Result { async fn resolve_bsky_video( playlist_url: &str, ) -> Result, String> { - if !crate::site::ffmpeg_available() { - crate::site::log_once_ffmpeg_missing(); + if crate::site::ffmpeg_missing() { return Ok(None); } let master = fetch_hls(playlist_url, 1_048_576) diff --git a/crates/x-media/src/site/mod.rs b/crates/x-media/src/site/mod.rs index 4de9ae1..1e1f165 100644 --- a/crates/x-media/src/site/mod.rs +++ b/crates/x-media/src/site/mod.rs @@ -313,14 +313,17 @@ static FFMPEG_AVAILABLE: LazyLock = LazyLock::new(|| { static FFMPEG_MISSING_LOGGED: AtomicBool = AtomicBool::new(false); -pub(crate) fn ffmpeg_available() -> bool { - *FFMPEG_AVAILABLE -} - -pub(crate) fn log_once_ffmpeg_missing() { +/// Whether the encode step must be skipped: no ffmpeg on PATH, logged once +/// per process. The one gate both encoders check — the probe and the +/// log-once used to be two functions that only ever appeared together. +pub(crate) fn ffmpeg_missing() -> bool { + if *FFMPEG_AVAILABLE { + return false; + } if !FFMPEG_MISSING_LOGGED.swap(true, Ordering::Relaxed) { log::warn!("ffmpeg not found; ugoira and bsky video posts stay unsupported"); } + true } /// Site adapter: one impl per supported site (twitter / bsky / misskey / diff --git a/crates/x-media/src/site/pixiv/api.rs b/crates/x-media/src/site/pixiv/api.rs index d13d042..fdc2005 100644 --- a/crates/x-media/src/site/pixiv/api.rs +++ b/crates/x-media/src/site/pixiv/api.rs @@ -206,8 +206,7 @@ impl PixivAPI { &self, illust_id: u64, ) -> Result, PixivError> { - if !crate::site::ffmpeg_available() { - crate::site::log_once_ffmpeg_missing(); + if crate::site::ffmpeg_missing() { return Ok(None); } let metadata = self.ugoira_metadata(illust_id).await?;