use std::path::PathBuf; #[derive(Debug, Clone)] pub struct Tags { pub title: String, pub artist: String, pub supports_replaygain: bool, pub contains_replaygain_tags: bool, } #[derive(Debug, Clone)] pub struct File { pub filename: String, pub extension: String, pub extra_files: Vec, pub path_to: PathBuf, pub path_from_source: PathBuf, pub tags: Tags, } impl File { pub fn from_path(source_dir: String, full_path: PathBuf) -> File { let full_file_path = PathBuf::from(&source_dir).join(full_path); let filename = full_file_path .file_stem() .unwrap() .to_str() .unwrap() .to_string(); let extension = full_file_path .extension() .unwrap() .to_str() .unwrap() .to_string(); let path_from_src = full_file_path.strip_prefix(&source_dir).unwrap(); let mut folder_path_from_src = path_from_src.to_path_buf(); folder_path_from_src.pop(); let path_to = PathBuf::from(&source_dir).join(&folder_path_from_src); File { filename, extension, path_from_source: folder_path_from_src, path_to, extra_files: Vec::new(), tags: Tags { title: "".to_string(), artist: "".to_string(), supports_replaygain: false, contains_replaygain_tags: false, }, } } pub fn join_filename(&self) -> String { format!("{}.{}", self.filename, self.extension) } pub fn join_path_to(&self) -> PathBuf { PathBuf::from(&self.path_to).join(self.join_filename()) } pub fn join_path_from_source(&self) -> PathBuf { PathBuf::from(&self.path_from_source).join(self.join_filename()) } }