A tool to sync music with your favorite devices
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

transcode: use new Device abstraction

Gee Sawra 03e36628 abf3a5e8

+21 -21
+21 -21
src/cmd/transcode.rs
··· 1 + use std::path::PathBuf; 2 + 1 3 use crate::{ 2 - db, 3 - ffmpeg::{Bitrate, BitrateParser, Codec, SamplingRate, SamplingRateParser}, 4 + device, 5 + ffmpeg::{Bitrate, BitrateParser, Codec, Quality, SamplingRate, SamplingRateParser}, 4 6 }; 5 7 use anyhow::{Result, anyhow}; 6 8 use clap::Args as ClapArgs; ··· 9 11 pub struct Args { 10 12 /// Path where tunz database is stored. 11 13 #[arg(long)] 12 - pub destination: String, 14 + pub destination: PathBuf, 13 15 14 16 /// Enable or disable transcoding on copy. 15 17 #[arg(long)] ··· 34 36 Some(s) => match s { 35 37 true => { 36 38 if !(self.bitrate.is_some() 37 - || self.codec.is_some() 38 - || self.sampling_rate.is_some()) 39 + && self.codec.is_some() 40 + && self.sampling_rate.is_some()) 39 41 { 40 - return Err(anyhow!("can't enable transcoding with no settings!")); 42 + return Err(anyhow!("must specify all transcoding settings")); 41 43 } 42 44 43 45 Ok(()) ··· 52 54 pub async fn run(args: Args) -> Result<()> { 53 55 args.validate()?; 54 56 55 - let dest_db = db::Instance::new(&args.destination, true).await?; 57 + // transcoding settings are always written in tunz.db, open dest as a disk by default 56 58 57 - if let Some(enabled) = args.enabled { 58 - dest_db.set_transcoding(enabled).await?; 59 + let dest = device::Disk::new(args.destination).await?; 59 60 60 - if !enabled { 61 - return Ok(()); // user is disabling transcoding, we can return early 61 + if let Some(enabled) = args.enabled { 62 + match enabled { 63 + true => { 64 + dest.set_transcoding_settings(Some(Quality { 65 + bitrate: args.bitrate.unwrap(), 66 + sampling_rate: args.sampling_rate, 67 + codec: args.codec.unwrap(), 68 + })) 69 + .await? 70 + } 71 + false => dest.set_transcoding_settings(None).await?, 62 72 } 63 73 } 64 - 65 - dest_db 66 - .set_transcoding_settings( 67 - args.codec.map(|e| e.to_string()), 68 - args.bitrate.map(|e| e.to_string()), 69 - args.sampling_rate.map(|e| e.to_string()), 70 - ) 71 - .await?; 72 - 73 - println!("{:?}", dest_db.get_transcoding_settings().await?); 74 74 75 75 Ok(()) 76 76 }