feat: add log in ~/.local/share/music-sort to show past imported files
This commit is contained in:
+34
-3
@@ -1,8 +1,12 @@
|
|||||||
|
use chrono::Utc;
|
||||||
use glob::glob;
|
use glob::glob;
|
||||||
use lofty::prelude::ItemKey;
|
use lofty::prelude::ItemKey;
|
||||||
use lofty::tag::Accessor;
|
use lofty::tag::Accessor;
|
||||||
use lofty::tag::Tag;
|
use lofty::tag::Tag;
|
||||||
use std::fs::{copy, create_dir_all, remove_dir, rename};
|
use std::env::var;
|
||||||
|
use std::fs::OpenOptions;
|
||||||
|
use std::fs::{copy, create_dir, create_dir_all, remove_dir, rename, File};
|
||||||
|
use std::io::Write;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
pub fn move_files(
|
pub fn move_files(
|
||||||
@@ -12,7 +16,7 @@ pub fn move_files(
|
|||||||
should_copy: bool,
|
should_copy: bool,
|
||||||
has_parent: bool,
|
has_parent: bool,
|
||||||
) -> Result<(), Box<dyn std::error::Error>> {
|
) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let target_dir = PathBuf::from("/home/user/Desktop/coding/keks-sort");
|
let target_dir = PathBuf::from("/home/user/Music/Tracks");
|
||||||
|
|
||||||
let artist = tag.artist();
|
let artist = tag.artist();
|
||||||
let album = tag.album();
|
let album = tag.album();
|
||||||
@@ -77,6 +81,33 @@ pub fn move_files(
|
|||||||
remove_dir(file_path.parent().unwrap())?;
|
remove_dir(file_path.parent().unwrap())?;
|
||||||
}
|
}
|
||||||
|
|
||||||
//println!("Imported file: {:?}", file_path.file_name().unwrap());
|
write_log(file_path)?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn write_log(file_path: PathBuf) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
let home_dir: PathBuf = PathBuf::from(var("HOME").expect("HOME is no set"));
|
||||||
|
let data_dir = home_dir.join(".local").join("share").join("music-sort");
|
||||||
|
let log_file_path = data_dir.join("music-sort.log");
|
||||||
|
|
||||||
|
if !data_dir.exists() {
|
||||||
|
create_dir(&data_dir)?;
|
||||||
|
}
|
||||||
|
if !log_file_path.exists() {
|
||||||
|
File::create(&log_file_path)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut log_file = OpenOptions::new().append(true).open(log_file_path).unwrap();
|
||||||
|
|
||||||
|
if let Err(e) = writeln!(
|
||||||
|
log_file,
|
||||||
|
"[{}]: Imported file: {:?}",
|
||||||
|
Utc::now().format("%Y-%m-%dT%H:%M:%S"),
|
||||||
|
file_path.file_name().unwrap()
|
||||||
|
) {
|
||||||
|
eprintln!("Couldn't write to file: {}", e);
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user