finally add folder support via folder.meta is_album field
This commit is contained in:
parent
07c3aa7edc
commit
66a83fbbbb
|
@ -50,7 +50,19 @@ fn rename_file(process_args: &ProcessCommandArgs, file: &mut File) {
|
|||
let artist = artist.replace('/', &replace_char);
|
||||
|
||||
// Step 4: Join Filename
|
||||
let filename = format!("{} - {}", artist, title);
|
||||
let filename = match file.folder_meta.is_album {
|
||||
true => {
|
||||
format!(
|
||||
"{}. {} - {}",
|
||||
file.info.tags.track_number.unwrap(),
|
||||
title,
|
||||
artist
|
||||
)
|
||||
}
|
||||
false => {
|
||||
format!("{} - {}", artist, title)
|
||||
}
|
||||
};
|
||||
|
||||
if filename == file.filename {
|
||||
return;
|
||||
|
|
21
src/types.rs
21
src/types.rs
|
@ -1,5 +1,7 @@
|
|||
use std::path::PathBuf;
|
||||
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::utils::format_detection::FileFormat;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
@ -69,6 +71,8 @@ pub struct File {
|
|||
pub extra_files: Vec<File>,
|
||||
|
||||
pub info: AudioFileInfo,
|
||||
|
||||
pub folder_meta: FolderMeta,
|
||||
}
|
||||
|
||||
impl File {
|
||||
|
@ -105,6 +109,7 @@ impl File {
|
|||
path_to,
|
||||
extra_files: Vec::new(),
|
||||
info: AudioFileInfo::default(),
|
||||
folder_meta: FolderMeta::default(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -118,3 +123,19 @@ impl File {
|
|||
PathBuf::from(&self.path_from_source).join(self.join_filename())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Default)]
|
||||
pub struct FolderMeta {
|
||||
pub is_album: bool,
|
||||
}
|
||||
|
||||
impl FolderMeta {
|
||||
pub fn load(path: &PathBuf) -> Result<FolderMeta, Box<dyn std::error::Error>> {
|
||||
let file = std::fs::File::open(path)?;
|
||||
let reader = std::io::BufReader::new(file);
|
||||
|
||||
let u: FolderMeta =
|
||||
serde_yaml::from_reader(reader).expect("error while reading folder meta");
|
||||
Ok(u)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,7 +30,10 @@ impl FormatHandler for ID3AudioFormat {
|
|||
Ok(Tags {
|
||||
title: String::from(title.unwrap()),
|
||||
artist: String::from(artist.unwrap()),
|
||||
track_number: self.id3_tags.track().map(|track_number| track_number as u64),
|
||||
track_number: self
|
||||
.id3_tags
|
||||
.track()
|
||||
.map(|track_number| track_number as u64),
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use std::fs;
|
||||
use std::{fs, path::PathBuf};
|
||||
|
||||
use crate::types::File;
|
||||
use crate::types::{File, FolderMeta};
|
||||
use walkdir::WalkDir;
|
||||
|
||||
use super::is_supported_file;
|
||||
|
@ -39,6 +39,7 @@ pub fn scan_for_music(src_dir: &String) -> Result<Vec<File>, Box<dyn std::error:
|
|||
for entry in WalkDir::new(src_dir) {
|
||||
let entry = entry.unwrap();
|
||||
let entry_path = entry.into_path();
|
||||
|
||||
if entry_path.is_dir() {
|
||||
continue;
|
||||
}
|
||||
|
@ -46,6 +47,13 @@ pub fn scan_for_music(src_dir: &String) -> Result<Vec<File>, Box<dyn std::error:
|
|||
if is_supported_file(&entry_path) {
|
||||
let mut file = File::from_path(src_dir.clone(), entry_path.clone());
|
||||
|
||||
let mut folder_meta_path = PathBuf::from(entry_path.parent().unwrap().clone());
|
||||
folder_meta_path.push("folder.meta");
|
||||
|
||||
if folder_meta_path.exists() {
|
||||
file.folder_meta = FolderMeta::load(&folder_meta_path)?;
|
||||
}
|
||||
|
||||
file.extra_files
|
||||
.extend(find_extra_files(src_dir.clone(), &file)?);
|
||||
|
||||
|
|
Loading…
Reference in a new issue