From fdf4c2a2646793c3a40c735f72d874e7ba659777 Mon Sep 17 00:00:00 2001 From: KeksNino Date: Sun, 23 Aug 2026 20:22:11 +0200 Subject: [PATCH] refactor: move move_files into separate module --- src/main.rs | 66 ++++------------------------------------------------- 1 file changed, 4 insertions(+), 62 deletions(-) diff --git a/src/main.rs b/src/main.rs index cc8673e..1d5c7a8 100755 --- a/src/main.rs +++ b/src/main.rs @@ -1,14 +1,13 @@ use clap::{Parser, Subcommand}; -use glob::glob; use lofty::file::TaggedFileExt; -use lofty::prelude::ItemKey; use lofty::probe::Probe; -use lofty::tag::Accessor; -use lofty::tag::Tag; use std::ffi::OsStr; -use std::fs::{copy, create_dir_all, read_dir, rename}; +use std::fs::read_dir; use std::path::PathBuf; +mod move_files; +use move_files::move_files; + #[derive(Parser)] #[command(version, about, long_about = None)] struct Args { @@ -73,60 +72,3 @@ fn get_metadata>(file_path: P) -> lofty::tag::Tag { }; tag.clone() } - -fn move_files( - file_path: PathBuf, - tag: Tag, - extra_files: [String; 8], -) -> Result<(), Box> { - let target_dir = PathBuf::from("/home/user/Desktop/coding/keks-sort"); - - let artist = tag.artist(); - let album = tag.album(); - let title = tag.title(); - let album_artist_path = tag.get_string(ItemKey::AlbumArtist).unwrap_or("None"); - - let artist_dir = if !album_artist_path.is_empty() { - Some(album_artist_path) - } else { - artist.as_deref() - }; - - let album_dir = album.or(title); - - let (Some(artist_dir), Some(album_dir)) = (artist_dir, album_dir) else { - return Ok(()); - }; - - let dir_to_create = target_dir.join(artist_dir).join(album_dir.as_ref()); - let _ = create_dir_all(dir_to_create); - let target = target_dir.join(artist_dir).join(album_dir.as_ref()); - - //copy(&file_path, target.join(file_path.file_name().unwrap()))?; - let should_copy = true; - if should_copy { - copy(&file_path, target.join(file_path.file_name().unwrap()))?; - } else { - rename(&file_path, target.join(file_path.file_name().unwrap()))?; - } - - for ext in &extra_files { - let file = file_path.parent().unwrap().join(format!("*.{}", ext)); - - for slice in glob(file.to_str().unwrap())? { - let path = slice?; - - let result = if should_copy { - copy(&path, target.join(path.file_name().unwrap())).map(|_| ()) - } else { - rename(&path, target.join(path.file_name().unwrap())) - }; - - if let Err(e) = result { - println!("Copy failed: {e}"); - } - } - } - println!("Imported file: {:?}", file_path.file_name().unwrap()); - Ok(()) -}