1
1
use clap:: Parser ;
2
- use glob:: glob;
3
2
use std:: ffi:: OsStr ;
4
3
use std:: fs:: create_dir_all;
5
- use std:: path:: { Path , PathBuf } ;
4
+ use std:: path:: Path ;
6
5
use std:: process:: { Command , Stdio } ;
7
6
use std:: sync:: { Arc , Mutex } ;
8
7
use std:: thread;
@@ -18,9 +17,9 @@ struct CmdArgs {
18
17
#[ arg( short, long, allow_hyphen_values = true ) ]
19
18
ffmpeg_options : String ,
20
19
21
- /// the directory with all files you want to process. supports unix globs
22
- #[ arg( short, long) ]
23
- input_directory : String ,
20
+ /// the files you want to process.
21
+ #[ arg( short, long, num_args = 1 .. , value_delimiter = ' ' ) ]
22
+ input_directory : Vec < String > ,
24
23
25
24
/// Specify the output file pattern. Use placeholders to customize file paths:
26
25
///
@@ -41,19 +40,14 @@ struct CmdArgs {
41
40
fn main ( ) {
42
41
let cmd_args = CmdArgs :: parse ( ) ;
43
42
44
- let paths = Arc :: new ( Mutex :: new ( match glob ( & cmd_args. input_directory ) {
45
- Ok ( paths) => paths. filter_map ( Result :: ok) . collect :: < Vec < PathBuf > > ( ) ,
46
- Err ( err) => {
47
- eprintln ! ( "{}" , err. msg) ;
48
- std:: process:: exit ( 1 ) ;
49
- }
50
- } ) ) ;
43
+ let paths = Arc :: new ( Mutex :: new ( cmd_args. input_directory ) ) ;
51
44
52
45
let mut thread_handles = vec ! [ ] ;
53
46
54
47
for thread in 0 ..cmd_args. thread_count {
55
- let paths: Arc < Mutex < Vec < PathBuf > > > = Arc :: clone ( & paths) ;
56
- let args = cmd_args. clone ( ) ;
48
+ let paths: Arc < Mutex < Vec < String > > > = Arc :: clone ( & paths) ;
49
+ let ffmpeg_options = cmd_args. ffmpeg_options . clone ( ) ;
50
+ let output = cmd_args. output . clone ( ) ;
57
51
58
52
let handle = thread:: spawn ( move || loop {
59
53
let path_to_process = {
@@ -64,12 +58,21 @@ fn main() {
64
58
65
59
match path_to_process {
66
60
Some ( path) => {
61
+ let path = Path :: new ( & path) ;
62
+
63
+ if !path. is_file ( ) {
64
+ eprintln ! (
65
+ "[THREAD {thread}] -- {} doesn't appear to be a file, ignoring. Continuing with next task if there's more to do..." ,
66
+ path. to_str( ) . unwrap( )
67
+ ) ;
68
+ continue ;
69
+ }
70
+
67
71
println ! ( "[THREAD {thread}] -- Processing {}" , path. display( ) ) ;
68
- let split_options = & mut args . ffmpeg_options . split ( ' ' ) . collect :: < Vec < & str > > ( ) ;
72
+ let split_options = & mut ffmpeg_options. split ( ' ' ) . collect :: < Vec < & str > > ( ) ;
69
73
70
- let mut final_file_name = args
71
- . output
72
- . replace ( "{{ext}}" , path. extension ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) ) ;
74
+ let mut final_file_name =
75
+ output. replace ( "{{ext}}" , path. extension ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) ) ;
73
76
final_file_name = final_file_name
74
77
. replace ( "{{name}}" , & path. file_stem ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) ) ;
75
78
final_file_name = final_file_name. replace (
0 commit comments