From 9779b4af6bff8fe965d6a92470a05d6bd93ccfe5 Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Wed, 13 Oct 2021 17:26:36 +0200 Subject: [PATCH] Add variables documentation to the readme and allow variables in the downloader path --- README.md | 17 ++++++++++++++++- src/downloader.rs | 14 +++++++++----- src/settings.rs | 3 +-- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 0a03367..f5c772e 100644 --- a/README.md +++ b/README.md @@ -51,9 +51,24 @@ Usage: down_on_spot.exe (track_url | album_url | playlist_url | artist_url) ``` +### Template variables + +The following variables are available for `path` and `filename_template` in the `settings.json`: + +- %0disc% +- %0track% +- %album% +- %albumArtist% +- %albumArtists% +- %artist% +- %disc% +- %id% +- %title% +- %track% + ## Known issues -- KDE Konsole specific prints to clear the screen or color the text does not work on windows +- KDE Konsole specific prints to clear the screen or color the text does not work on windows - Premium account dependency due to librespot - Sometimes downloads slow down diff --git a/src/downloader.rs b/src/downloader.rs index a1efa21..db75dbf 100644 --- a/src/downloader.rs +++ b/src/downloader.rs @@ -79,7 +79,7 @@ impl Downloader { let queue: Vec = tracks.into_iter().map(|t| t.into()).collect(); self.add_to_queue_multiple(queue).await; } - + // Unsupported SpotifyItem::Other(u) => { error!("Unsupported URI: {}", u); @@ -272,8 +272,7 @@ impl DownloaderInternal { .get_album(&track.album.id.ok_or(SpotifyError::Unavailable)?, None) .await? .data; - // Generate path - let mut filename = config.filename_template.to_owned(); + let tags: Vec<(&str, String)> = vec![ ("%title%", sanitize(&track.name)), ( @@ -331,10 +330,15 @@ impl DownloaderInternal { ), ), ]; + + // Generate path + let mut filename = config.filename_template.to_owned(); + let mut path_template = config.path.to_owned(); for (t, v) in tags { + path_template = path_template.replace(t, &v); filename = filename.replace(t, &v); } - let path = config.path.join(filename); + let path = PathBuf::from(path_template).join(filename); tokio::fs::create_dir_all(path.parent().unwrap()).await?; // Download @@ -809,7 +813,7 @@ impl ToString for Quality { pub struct DownloaderConfig { pub concurrent_downloads: usize, pub quality: Quality, - pub path: PathBuf, + pub path: String, pub filename_template: String, pub id3v24: bool, pub convert_to_mp3: bool, diff --git a/src/settings.rs b/src/settings.rs index c8b6508..963903f 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -1,7 +1,6 @@ use crate::downloader::DownloaderConfig; use crate::downloader::Quality; use crate::error::SpotifyError; -use std::path::PathBuf; use serde::{Deserialize, Serialize}; use tokio::{ @@ -36,7 +35,7 @@ impl Settings { downloader: DownloaderConfig { concurrent_downloads: 4, quality: Quality::Q320, - path: PathBuf::from("downloads"), + path: "downloads".to_string(), filename_template: "%artist% - %title%".to_string(), id3v24: true, convert_to_mp3: false,