@@ -8,15 +8,17 @@ use crate::{
88 format:: { Codec , get_track_data} ,
99 utils:: {
1010 adb_file_exists,
11- fs:: { FSBackend , get_file_ext, get_file_name} ,
12- is_adb_running, parse_sync_list, push_to_adb_device, read_dir_recursively, read_selectively, transcode_file,
11+ ffmpeg:: { strip_covers, transcode_file} ,
12+ fs:: { FSBackend , get_file_ext, get_file_name, read_dir_recursively, read_selectively} ,
13+ is_adb_running, parse_sync_list, push_to_adb_device,
1314 } ,
1415} ;
1516
1617pub struct SyncOpts {
1718 pub fs : FSBackend ,
1819 pub codec : Option < Codec > ,
1920 pub bitrate : Option < u32 > ,
21+ pub strip_covers : bool ,
2022 pub transcode_codecs : Vec < Codec > ,
2123 pub sync_codecs : Vec < Codec > ,
2224 pub sync_list : Option < String > ,
@@ -99,12 +101,11 @@ pub fn run<P: AsRef<Path>>(source_dir: P, target_dir: P, opts: SyncOpts) -> Resu
99101 // But why? Can't we use the check from codec.is_some()? No, not really.
100102 // We support syncing files that are part of the sync_extensions, so they don't go through the transcoding workflow.
101103 // So in cases like removing the temp file, it will remove the source file instead.
102- let mut transcoded = false ;
104+ let mut is_temp = false ;
103105 let mut final_source_path = file. clone ( ) ;
104106
105- let file_data = get_track_data ( & file, & source_file_ext) ?;
106- let is_transcodable =
107- !opts. sync_codecs . contains ( & file_data. codec ) && opts. transcode_codecs . contains ( & file_data. codec ) ;
107+ let meta = get_track_data ( & file, & source_file_ext) ?;
108+ let is_transcodable = !opts. sync_codecs . contains ( & meta. codec ) && opts. transcode_codecs . contains ( & meta. codec ) ;
108109
109110 match & opts. codec {
110111 Some ( codec) if is_transcodable => {
@@ -123,27 +124,41 @@ pub fn run<P: AsRef<Path>>(source_dir: P, target_dir: P, opts: SyncOpts) -> Resu
123124 fs:: create_dir_all ( temp_path. parent ( ) . unwrap ( ) ) ?;
124125 transcode_file ( & file, & temp_path, * codec, bitrate) ?;
125126
126- transcoded = true ;
127+ is_temp = true ;
127128 final_source_path = temp_path;
128129 rel_path. set_extension ( new_ext) ;
129130 }
130131 None if is_transcodable => {
131132 skipping ( & rel_path, & indicator, Some ( "due to no codec" ) ) ;
132133 continue ;
133134 }
134- _ if opts. sync_codecs . contains ( & file_data . codec ) => {
135+ _ if opts. sync_codecs . contains ( & meta . codec ) => {
135136 if fs_wrapper. exists ( & target_dir. join ( & rel_path) ) ? {
136137 path_already_exists ( & rel_path, & indicator) ;
137138 continue ;
138139 }
140+
141+ if opts. strip_covers {
142+ let temp_path = temp_dir. join ( & rel_path) ;
143+ fs:: create_dir_all ( temp_path. parent ( ) . unwrap ( ) ) ?;
144+ fs:: copy ( & file, & temp_path) ?;
145+
146+ let message = format ! ( "Stripping covers from {}" , get_file_name( & rel_path) ) ;
147+ indicator. set_message ( message) ;
148+
149+ strip_covers ( & temp_path, & temp_path) ?;
150+
151+ is_temp = true ;
152+ final_source_path = temp_path;
153+ }
139154 }
140155 _ => unreachable ! ( ) ,
141156 }
142157
143- indicator. set_message ( format ! ( "Moving {:?}" , get_file_name( & rel_path) ) ) ;
158+ indicator. set_message ( format ! ( "Syncing {:?}" , get_file_name( & rel_path) ) ) ;
144159 fs_wrapper. copy ( & final_source_path, & target_dir. join ( rel_path) ) ?;
145160
146- if transcoded {
161+ if is_temp {
147162 fs:: remove_file ( final_source_path) ?;
148163 }
149164
@@ -180,6 +195,10 @@ impl FSWrapper {
180195 FSBackend :: Adb => push_to_adb_device ( source, target) ,
181196 FSBackend :: Ftp => todo ! ( ) ,
182197 FSBackend :: None => {
198+ if let Some ( p) = target. parent ( ) {
199+ fs:: create_dir_all ( p) ?;
200+ }
201+
183202 fs:: copy ( source, target) ?;
184203 Ok ( ( ) )
185204 }
0 commit comments