From ae0e8f6ebc2aed178f3101125bd12748b10f723e Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 3 Feb 2023 17:26:47 +0100 Subject: [PATCH] clean filenames too --- src/main.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 7d154d6..6e6b779 100644 --- a/src/main.rs +++ b/src/main.rs @@ -46,6 +46,17 @@ async fn create_session(credentials: Credentials) -> Session { session } +fn make_filename_compatible(filename: &str) -> String { + let invalid_chars = ['<', '>', ':', '\'', '"', '/', '\\', '|', '?', '*']; + let mut clean = String::new(); + for c in filename.chars() { + if !invalid_chars.contains(&c) && c.is_ascii() && !c.is_control() && c.len_utf8() == 1 { + clean.push(c); + } + } + clean +} + async fn download_tracks(session: &Session, destination: PathBuf, tracks: Vec) { let player_config = PlayerConfig::default(); let bar_style = ProgressStyle::default_bar() @@ -79,10 +90,11 @@ async fn download_tracks(session: &Session, destination: PathBuf, tracks: Vec