diff --git a/example.audio-conv.yaml b/example.audio-conv.yaml index 584c926..22646c1 100644 --- a/example.audio-conv.yaml +++ b/example.audio-conv.yaml @@ -13,6 +13,10 @@ matches: bitrate: 160 bitrate_type: vbr # or cbr + # for copy (copies file without transcoding it): + # to: + # codec: copy + # for mp3: # to: # codec: mp3 diff --git a/src/config.rs b/src/config.rs index 1699318..dbca3c4 100644 --- a/src/config.rs +++ b/src/config.rs @@ -46,6 +46,9 @@ pub enum Transcode { #[serde(default = "bitrate_type_vbr")] bitrate_type: BitrateType, }, + + #[serde(rename = "copy")] + Copy, } impl Transcode { @@ -54,6 +57,7 @@ impl Transcode { Transcode::Opus { .. } => "opus", Transcode::Flac { .. } => "flac", Transcode::Mp3 { .. } => "mp3", + Transcode::Copy => "", } } } diff --git a/src/main.rs b/src/main.rs index cdb9560..0d1e33a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -264,15 +264,40 @@ async fn transcode( ) -> Result<()> { let from_path = config.from.join(&args.rel_from_path); let mut to_path = config.to.join(&args.rel_from_path); - to_path.set_extension(args.transcode.extension()); - let file_src: Element = gmake("filesrc")?; - file_src.set_property("location", &path_to_gstring(&from_path))?; + fs::create_dir_all( + to_path + .parent() + .with_context(|| format!("could not get parent dir for {}", to_path.display()))?, + ) + .await?; // encode into a tmp file first, then rename to actuall file name, that way we're writing // "whole" files to the intended file path, ignoring partial files in the mtime check let to_path_tmp = to_path.with_extension("tmp"); + if let config::Transcode::Copy = args.transcode { + rm_file_on_err(&to_path_tmp, async { + fs::copy(&from_path, &to_path_tmp).await.with_context(|| { + format!( + "could not copy file from {} to {}", + from_path.display(), + to_path_tmp.display() + ) + }) + }) + .await?; + + fs::rename(&to_path_tmp, &to_path).await?; + + return Ok(()); + } + + to_path.set_extension(args.transcode.extension()); + + let file_src: Element = gmake("filesrc")?; + file_src.set_property("location", &path_to_gstring(&from_path))?; + let decodebin: Element = gmake("decodebin")?; let src_elems: &[&Element] = &[&file_src, &decodebin]; @@ -378,6 +403,8 @@ async fn transcode( dest_elems.push(encoder); dest_elems.push(gmake("id3v2mux")?); } + + config::Transcode::Copy => unreachable!(), }; let file_dest: gstreamer_base::BaseSink = gmake("filesink")?; @@ -419,13 +446,6 @@ async fn transcode( let bus = pipeline.get_bus().context("pipe get bus")?; - fs::create_dir_all( - to_path - .parent() - .with_context(|| format!("could not get parent dir for {}", to_path.display()))?, - ) - .await?; - rm_file_on_err(&to_path_tmp, async { pipeline .set_state(gstreamer::State::Playing)