Skip to content

Commit e8d0003

Browse files
authored
Merge pull request #1 from CodeF0x/remove-glob-crate
Remove glob crate
2 parents 46a7fe3 + 45600fc commit e8d0003

File tree

4 files changed

+25
-131
lines changed

4 files changed

+25
-131
lines changed

Cargo.lock

Lines changed: 1 addition & 105 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ffzap"
3-
version = "0.1.3"
3+
version = "0.1.4"
44
edition = "2021"
55
description = "⚡ A multithreaded CLI for digital media processing using ffmpeg. If ffmpeg can do it, ffzap can do it - as many files in parallel as your CPU can handle."
66
license-file = "license.md"
@@ -11,5 +11,3 @@ repository = "https://github.com/CodeF0x/ffzap"
1111

1212
[dependencies]
1313
clap = { version = "4.5.20", features = ["derive"] }
14-
glob = "0.3.1"
15-
rand = "0.9.0-alpha.2"

README.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,14 @@ as a string and without the file name.
3434
With a single file it doesn't really make sense to use ffzap, so consider this more advanced example:
3535

3636
```bash
37-
ffzap -i "vids/**/*.{mp4,mkv}" -f "-c:v libx264 -b:v 1000k" -o transcoded/{{name}}.mp4 -t 4
37+
ffzap -i vids/**/*.{mp4,mkv} -f "-c:v libx264 -b:v 1000k" -o transcoded/{{name}}.mp4 -t 4
3838
```
3939

4040
This command takes all videos in `vids` and its subfolders ending in `.mp4` and `.mkv`, processes them using the
4141
options provided by `-f` and saves them to a (new) directory called `transcoded`, keeping the original filename and
4242
changing the file extension to `.mp4` while processing 4 files in parallel.
4343

44-
Notice that, when using glob patterns, `-i` (short for `--input-directory`) needs to be a string so that ffzap executes
45-
the glob pattern and **not** your shell. Otherwise, the command will fail.
46-
47-
For more `-o` (short for `--output-directory`) options, run `ffzap --help`. For more ffmpeg options,
44+
For more info on the `-o` syntax, run `ffzap --help`. For more ffmpeg options,
4845
visit [ffmpeg's documentation](https://ffmpeg.org/ffmpeg.html).
4946

5047
### Requirements

src/main.rs

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
use clap::Parser;
2-
use glob::glob;
32
use std::ffi::OsStr;
43
use std::fs::create_dir_all;
5-
use std::path::{Path, PathBuf};
4+
use std::path::Path;
65
use std::process::{Command, Stdio};
76
use std::sync::{Arc, Mutex};
87
use std::thread;
@@ -18,9 +17,9 @@ struct CmdArgs {
1817
#[arg(short, long, allow_hyphen_values = true)]
1918
ffmpeg_options: String,
2019

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>,
2423

2524
/// Specify the output file pattern. Use placeholders to customize file paths:
2625
///
@@ -41,19 +40,14 @@ struct CmdArgs {
4140
fn main() {
4241
let cmd_args = CmdArgs::parse();
4342

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));
5144

5245
let mut thread_handles = vec![];
5346

5447
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();
5751

5852
let handle = thread::spawn(move || loop {
5953
let path_to_process = {
@@ -64,12 +58,21 @@ fn main() {
6458

6559
match path_to_process {
6660
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+
6771
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>>();
6973

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());
7376
final_file_name = final_file_name
7477
.replace("{{name}}", &path.file_stem().unwrap().to_str().unwrap());
7578
final_file_name = final_file_name.replace(

0 commit comments

Comments
 (0)