refactor: add gif to extra_files and bypass array length specification
This commit is contained in:
+5
-11
@@ -3,6 +3,7 @@ use lofty::file::TaggedFileExt;
|
|||||||
use lofty::probe::Probe;
|
use lofty::probe::Probe;
|
||||||
use std::ffi::OsStr;
|
use std::ffi::OsStr;
|
||||||
use std::fs::read_dir;
|
use std::fs::read_dir;
|
||||||
|
use std::io;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
mod move_files;
|
mod move_files;
|
||||||
@@ -38,7 +39,7 @@ enum Commands {
|
|||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
let extra_files = [
|
let extra_files = [
|
||||||
"jpg", "png", "pdf", "log", "cue", "mp4", "lrc", "txt", "docx",
|
"jpg", "png", "pdf", "log", "cue", "mp4", "lrc", "txt", "docx", "gif",
|
||||||
]
|
]
|
||||||
.map(str::to_string);
|
.map(str::to_string);
|
||||||
|
|
||||||
@@ -61,7 +62,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let tag = get_metadata(&path);
|
let tag = get_metadata(&path);
|
||||||
|
|
||||||
if let Err(e) =
|
if let Err(e) =
|
||||||
move_files(path.clone(), tag?, extra_files.clone(), *copy, true, *new)
|
move_files(path.clone(), tag?, &extra_files, *copy, true, *new)
|
||||||
{
|
{
|
||||||
eprintln!("Failed to import {:?}: {}", path, e);
|
eprintln!("Failed to import {:?}: {}", path, e);
|
||||||
}
|
}
|
||||||
@@ -69,14 +70,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
} else {
|
} else {
|
||||||
println!("Importing file: {:?}", file);
|
println!("Importing file: {:?}", file);
|
||||||
let tag = get_metadata(file);
|
let tag = get_metadata(file);
|
||||||
move_files(
|
move_files(file.clone(), tag?.clone(), &extra_files, *copy, false, *new)?;
|
||||||
file.clone(),
|
|
||||||
tag?.clone(),
|
|
||||||
extra_files.clone(),
|
|
||||||
*copy,
|
|
||||||
false,
|
|
||||||
*new,
|
|
||||||
)?;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -93,7 +87,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Commands::Edit { files } => {
|
Commands::Edit { files } => {
|
||||||
edit(files.to_vec(), extra_files)?;
|
edit(files.to_vec(), &extra_files)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-3
@@ -12,7 +12,7 @@ use std::path::PathBuf;
|
|||||||
pub fn move_files(
|
pub fn move_files(
|
||||||
file_path: PathBuf,
|
file_path: PathBuf,
|
||||||
tag: Tag,
|
tag: Tag,
|
||||||
extra_files: [String; 9],
|
extra_files: &[String],
|
||||||
should_copy: bool,
|
should_copy: bool,
|
||||||
has_parent: bool,
|
has_parent: bool,
|
||||||
add_new_playlist: bool,
|
add_new_playlist: bool,
|
||||||
@@ -64,7 +64,7 @@ pub fn move_files(
|
|||||||
new_playlist(target.join(file_name))?;
|
new_playlist(target.join(file_name))?;
|
||||||
}
|
}
|
||||||
|
|
||||||
for ext in &extra_files {
|
for ext in extra_files {
|
||||||
let pattern = file_path.parent().unwrap().join(format!("*.{}", ext));
|
let pattern = file_path.parent().unwrap().join(format!("*.{}", ext));
|
||||||
|
|
||||||
let paths: Vec<_> = glob(pattern.to_str().unwrap())?.collect::<Result<_, _>>()?;
|
let paths: Vec<_> = glob(pattern.to_str().unwrap())?.collect::<Result<_, _>>()?;
|
||||||
@@ -109,7 +109,6 @@ fn new_playlist(path: PathBuf) -> std::result::Result<(), std::io::Error> {
|
|||||||
.append(true)
|
.append(true)
|
||||||
.open(new_playlist_path)
|
.open(new_playlist_path)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
println!("{:?}", path);
|
|
||||||
writeln!(new_playlist, "{}", path.display())
|
writeln!(new_playlist, "{}", path.display())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user