Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
dcbf0a7ba2
|
+7
-14
@@ -10,7 +10,7 @@ use std::io::Write;
|
|||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::{fs::File, fs::read_dir, io::Read, process::Command};
|
use std::{fs::File, fs::read_dir, io::Read, process::Command};
|
||||||
|
|
||||||
pub fn edit(file_path: Vec<PathBuf>, extra_files: &[String]) -> std::io::Result<()> {
|
pub fn edit(file_path: Vec<PathBuf>, extra_files: [String; 9]) -> std::io::Result<()> {
|
||||||
let tmp_file_path = PathBuf::from("/tmp/keks-sort-metadata");
|
let tmp_file_path = PathBuf::from("/tmp/keks-sort-metadata");
|
||||||
let mut tmp_file = File::create(&tmp_file_path)?;
|
let mut tmp_file = File::create(&tmp_file_path)?;
|
||||||
let editor = var("EDITOR").unwrap();
|
let editor = var("EDITOR").unwrap();
|
||||||
@@ -34,22 +34,15 @@ pub fn edit(file_path: Vec<PathBuf>, extra_files: &[String]) -> std::io::Result<
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
let tag = match crate::get_metadata(&path) {
|
let tag = crate::get_metadata(&path);
|
||||||
Ok(tag) => tag,
|
|
||||||
Err(err) => {
|
|
||||||
eprintln!("Failed to get metadata for {:?}: {}", path, err);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
files.push(FileMetadata { path, tag });
|
files.push(FileMetadata { path, tag });
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if let Ok(tag) = crate::get_metadata(file) {
|
let tag = &crate::get_metadata(file);
|
||||||
files.push(FileMetadata {
|
files.push(FileMetadata {
|
||||||
path: file.to_path_buf(),
|
path: file.to_path_buf(),
|
||||||
tag: tag.clone(),
|
tag: tag.clone(),
|
||||||
});
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+28
-28
@@ -1,9 +1,9 @@
|
|||||||
use clap::{Parser, Subcommand};
|
use clap::{Parser, Subcommand};
|
||||||
|
//use ini::Ini;
|
||||||
use lofty::file::TaggedFileExt;
|
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;
|
||||||
@@ -37,9 +37,25 @@ enum Commands {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
//let mut conf = Ini::new();
|
||||||
|
//conf.with_section(Some("General"))
|
||||||
|
// .set("target_directory", "");
|
||||||
|
////conf.write_to_file("conf.ini").unwrap();
|
||||||
|
//
|
||||||
|
//let conf = Ini::load_from_file("conf.ini").unwrap();
|
||||||
|
//
|
||||||
|
//let section = conf.section(Some("General")).unwrap();
|
||||||
|
//println!("target_dir={:?}", section.get("target_directory"));
|
||||||
|
//
|
||||||
|
//for (_sec, prop) in &conf {
|
||||||
|
// for (key, value) in prop.iter() {
|
||||||
|
// println!("{:?}:{:?}", key, value);
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
//
|
||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
let extra_files = [
|
let extra_files = [
|
||||||
"jpg", "png", "pdf", "log", "cue", "mp4", "lrc", "txt", "docx", "gif",
|
"jpg", "png", "pdf", "log", "cue", "mp4", "lrc", "txt", "docx",
|
||||||
]
|
]
|
||||||
.map(str::to_string);
|
.map(str::to_string);
|
||||||
|
|
||||||
@@ -57,35 +73,12 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
.is_some_and(|ext| extra_files.iter().any(|x| x == ext))
|
.is_some_and(|ext| extra_files.iter().any(|x| x == ext))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
} else {
|
|
||||||
let mut input = String::new();
|
|
||||||
|
|
||||||
eprintln!("Found files that aren't music files: {}", path.display());
|
|
||||||
eprintln!(" [1] Copy all files");
|
|
||||||
eprintln!(" [2] Skip non-music files");
|
|
||||||
eprintln!(" [3] Cancel import");
|
|
||||||
|
|
||||||
eprint!("> ");
|
|
||||||
io::stdin()
|
|
||||||
.read_line(&mut input)
|
|
||||||
.expect("failed to read input");
|
|
||||||
|
|
||||||
let mut other_files: Vec<PathBuf>;
|
|
||||||
match input.trim() {
|
|
||||||
"1" => {
|
|
||||||
other_files.extend(&path);
|
|
||||||
}
|
|
||||||
"2" => {}
|
|
||||||
_ => {
|
|
||||||
println!("Invalid option.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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, *copy, true, *new)
|
move_files(path.clone(), tag?, extra_files.clone(), *copy, true, *new)
|
||||||
{
|
{
|
||||||
eprintln!("Failed to import {:?}: {}", path, e);
|
eprintln!("Failed to import {:?}: {}", path, e);
|
||||||
}
|
}
|
||||||
@@ -93,7 +86,14 @@ 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(file.clone(), tag?.clone(), &extra_files, *copy, false, *new)?;
|
move_files(
|
||||||
|
file.clone(),
|
||||||
|
tag?.clone(),
|
||||||
|
extra_files.clone(),
|
||||||
|
*copy,
|
||||||
|
false,
|
||||||
|
*new,
|
||||||
|
)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -110,7 +110,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)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-2
@@ -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],
|
extra_files: [String; 9],
|
||||||
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,6 +109,7 @@ 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