feat: add ffmpeg plugin and update plugin interface to support temporary directories and context-dependent metrics
Release / check-release (push) Successful in 15s
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 1m31s
CI / Build Linux (push) Successful in 1m47s
Release / check-release (push) Successful in 15s
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 1m31s
CI / Build Linux (push) Successful in 1m47s
This commit is contained in:
+68
-14
@@ -1,10 +1,26 @@
|
||||
// Copyright (C) 2026 Elias Wendland <eliaswendland@pm.me>
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, version 3 exclusively.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// 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;
|
||||
use std::time::Instant;
|
||||
|
||||
pub fn run_conversion(
|
||||
path: &[(&dyn Plugin, &str, &str)],
|
||||
input: &[u8],
|
||||
verbosity: u8,
|
||||
temp_dir: &Path,
|
||||
) -> Result<Vec<u8>, String> {
|
||||
if verbosity >= 1 {
|
||||
let path_str: Vec<_> = path.iter().map(|(p, _, _)| p.name()).collect();
|
||||
@@ -15,22 +31,35 @@ pub fn run_conversion(
|
||||
|
||||
for (plugin, from_format, to_format) in path {
|
||||
if verbosity >= 2 {
|
||||
eprintln!("Converting {} to {} using plugin {}...", from_format, to_format, plugin.name());
|
||||
eprintln!(
|
||||
"Converting {} to {} using plugin {}...",
|
||||
from_format,
|
||||
to_format,
|
||||
plugin.name()
|
||||
);
|
||||
}
|
||||
|
||||
if verbosity >= 4 {
|
||||
eprintln!("[Plugin Log] Running plugin: {}", plugin.name());
|
||||
eprintln!("[Plugin Log] Source format: {}", from_format);
|
||||
eprintln!("[Plugin Log] Target format: {}", to_format);
|
||||
eprintln!("[Plugin Log] Metrics - Familiarity: {}, Quality: {}, Speed: {}", plugin.familiarity(), plugin.quality(), plugin.speed());
|
||||
eprintln!(
|
||||
"[Plugin Log] Metrics - Familiarity: {}, Quality: {}, Speed: {}",
|
||||
plugin.familiarity(*from_format, *to_format),
|
||||
plugin.quality(*from_format, *to_format),
|
||||
plugin.speed(*from_format, *to_format)
|
||||
);
|
||||
}
|
||||
|
||||
let start_time = Instant::now();
|
||||
current_data = plugin.convert(¤t_data, from_format, to_format)?;
|
||||
current_data = plugin.convert(¤t_data, from_format, to_format, temp_dir)?;
|
||||
let elapsed = start_time.elapsed();
|
||||
|
||||
if verbosity >= 3 {
|
||||
eprintln!("Step '{} -> {}' completed in {:.2?}", from_format, to_format, elapsed);
|
||||
eprintln!(
|
||||
"Step '{} -> {}' completed in {:.2?}",
|
||||
from_format, to_format, elapsed
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,13 +79,31 @@ mod tests {
|
||||
}
|
||||
|
||||
impl Plugin for MockPlugin {
|
||||
fn name(&self) -> &'static str { self.name }
|
||||
fn from_formats(&self) -> Vec<&'static str> { vec!["a"] }
|
||||
fn to_formats(&self) -> Vec<&'static str> { vec!["b"] }
|
||||
fn familiarity(&self) -> u8 { self.f }
|
||||
fn quality(&self) -> u8 { self.q }
|
||||
fn speed(&self) -> u8 { self.s }
|
||||
fn convert(&self, input: &[u8], _from: &str, _to: &str) -> Result<Vec<u8>, String> {
|
||||
fn name(&self) -> &'static str {
|
||||
self.name
|
||||
}
|
||||
fn from_formats(&self) -> Vec<&'static str> {
|
||||
vec!["a"]
|
||||
}
|
||||
fn to_formats(&self) -> Vec<&'static str> {
|
||||
vec!["b"]
|
||||
}
|
||||
fn familiarity(&self, _from: &str, _to: &str) -> u8 {
|
||||
self.f
|
||||
}
|
||||
fn quality(&self, _from: &str, _to: &str) -> u8 {
|
||||
self.q
|
||||
}
|
||||
fn speed(&self, _from: &str, _to: &str) -> u8 {
|
||||
self.s
|
||||
}
|
||||
fn convert(
|
||||
&self,
|
||||
input: &[u8],
|
||||
_from: &str,
|
||||
_to: &str,
|
||||
_temp_dir: &Path,
|
||||
) -> Result<Vec<u8>, String> {
|
||||
if self.fail {
|
||||
return Err("Failed".to_string());
|
||||
}
|
||||
@@ -70,11 +117,18 @@ mod tests {
|
||||
($name:ident, $verbosity:expr, $fail:expr, $expected_res:expr, $expected_len:expr) => {
|
||||
#[test]
|
||||
fn $name() {
|
||||
let plugin = MockPlugin { name: "mock", f: 10, q: 10, s: 10, fail: $fail };
|
||||
let plugin = MockPlugin {
|
||||
name: "mock",
|
||||
f: 10,
|
||||
q: 10,
|
||||
s: 10,
|
||||
fail: $fail,
|
||||
};
|
||||
let path: Vec<(&dyn Plugin, &str, &str)> = vec![(&plugin, "a", "b")];
|
||||
let input = vec![0];
|
||||
|
||||
let result = run_conversion(&path, &input, $verbosity);
|
||||
|
||||
let result =
|
||||
run_conversion(&path, &input, $verbosity, std::path::Path::new("/dev/shm"));
|
||||
assert_eq!(result.is_ok(), $expected_res);
|
||||
if let Ok(res) = result {
|
||||
assert_eq!(res.len(), $expected_len);
|
||||
|
||||
Reference in New Issue
Block a user