feat: add ffmpeg audio plugin and migrate verbosity to tracing levels
Release / check-release (push) Successful in 59s
Release / build_gnu (push) Skipped
Release / build_musl (push) Skipped
Release / build_windows (push) Skipped
Release / package_gnu (deb) (push) Skipped
Release / package_gnu (rpm) (push) Skipped
Release / package_musl (deb) (push) Skipped
Release / package_musl (rpm) (push) Skipped
Release / publish-release (push) Skipped
CI / Test (push) Successful in 1m44s
CI / Build Linux (push) Successful in 2m3s

This commit is contained in:
Elias Wendland committed 2026-07-15 22:57:00 +02:00
1 parent b97a108d1e
commit f58f73194e
7 files changed
+257 -149

No files matched your search

+35 -14
View File
@@ -12,39 +12,56 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
use crate::plugin::Plugin;
use std::path::Path;
pub fn identify_format(path: &str) -> Option<&'static str> {
pub fn identify_format(path: &str, plugins: &[Box<dyn Plugin>]) -> Option<&'static str> {
let p = Path::new(path);
let ext = p
.extension()
.and_then(|s| s.to_str())
.unwrap_or(path)
.to_lowercase();
match ext.as_str() {
"jpg" | "jpeg" => Some("jpeg"),
"png" => Some("png"),
"mp4" => Some("mp4"),
"webm" => Some("webm"),
"mkv" => Some("mkv"),
"avi" => Some("avi"),
"mov" => Some("mov"),
"wmv" => Some("wmv"),
"flv" => Some("flv"),
"gif" => Some("gif"),
_ => None,
let ext_str = match ext.as_str() {
"jpg" => "jpeg",
other => other,
};
for plugin in plugins {
if let Some(&f) = plugin.from_formats().iter().find(|&&f| f == ext_str) {
return Some(f);
}
if let Some(&f) = plugin.to_formats().iter().find(|&&f| f == ext_str) {
return Some(f);
}
}
None
}
#[cfg(test)]
mod tests {
use super::*;
struct MockPlugin;
impl Plugin for MockPlugin {
fn name(&self) -> &'static str { "mock" }
fn from_formats(&self) -> Vec<&'static str> {
vec!["jpeg", "png", "mp4", "webm", "mkv", "avi", "mov", "wmv", "flv", "gif", "mp3", "wav", "ogg", "flac", "aac", "m4a", "opus", "wma", "amr", "aiff", "au"]
}
fn to_formats(&self) -> Vec<&'static str> { vec![] }
fn familiarity(&self, _: &str, _: &str) -> u8 { 0 }
fn quality(&self, _: &str, _: &str) -> u8 { 0 }
fn speed(&self, _: &str, _: &str) -> u8 { 0 }
fn convert(&self, _: &[u8], _: &str, _: &str, _: &Path) -> Result<Vec<u8>, String> { Ok(vec![]) }
}
macro_rules! test_ident {
($name:ident, $ext:expr, $expected:expr) => {
#[test]
fn $name() {
assert_eq!(identify_format($ext), $expected);
let mock = Box::new(MockPlugin);
let plugins: Vec<Box<dyn Plugin>> = vec![mock];
assert_eq!(identify_format($ext, &plugins), $expected);
}
};
}
@@ -74,4 +91,8 @@ mod tests {
test_ident!(test_identify_format_19, "test_file_without_extension", None);
test_ident!(test_identify_format_20, ".jpg", None);
test_ident!(test_identify_format_21, "", None);
test_ident!(test_identify_format_22, "test.mp3", Some("mp3"));
test_ident!(test_identify_format_23, "test.WAV", Some("wav"));
test_ident!(test_identify_format_24, "audio.flac", Some("flac"));
test_ident!(test_identify_format_25, "music.ogg", Some("ogg"));
}