Add variables documentation to the readme and allow variables in the downloader path

This commit is contained in:
oSumAtrIX 2021-10-13 17:26:36 +02:00
parent 19b25479ae
commit 9779b4af6b
No known key found for this signature in database
GPG key ID: A9B3094ACDB604B4
3 changed files with 26 additions and 8 deletions

View file

@ -51,9 +51,24 @@ Usage:
down_on_spot.exe (track_url | album_url | playlist_url | artist_url) 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 ## 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 - Premium account dependency due to librespot
- Sometimes downloads slow down - Sometimes downloads slow down

View file

@ -79,7 +79,7 @@ impl Downloader {
let queue: Vec<Download> = tracks.into_iter().map(|t| t.into()).collect(); let queue: Vec<Download> = tracks.into_iter().map(|t| t.into()).collect();
self.add_to_queue_multiple(queue).await; self.add_to_queue_multiple(queue).await;
} }
// Unsupported // Unsupported
SpotifyItem::Other(u) => { SpotifyItem::Other(u) => {
error!("Unsupported URI: {}", u); error!("Unsupported URI: {}", u);
@ -272,8 +272,7 @@ impl DownloaderInternal {
.get_album(&track.album.id.ok_or(SpotifyError::Unavailable)?, None) .get_album(&track.album.id.ok_or(SpotifyError::Unavailable)?, None)
.await? .await?
.data; .data;
// Generate path
let mut filename = config.filename_template.to_owned();
let tags: Vec<(&str, String)> = vec![ let tags: Vec<(&str, String)> = vec![
("%title%", sanitize(&track.name)), ("%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 { for (t, v) in tags {
path_template = path_template.replace(t, &v);
filename = filename.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?; tokio::fs::create_dir_all(path.parent().unwrap()).await?;
// Download // Download
@ -809,7 +813,7 @@ impl ToString for Quality {
pub struct DownloaderConfig { pub struct DownloaderConfig {
pub concurrent_downloads: usize, pub concurrent_downloads: usize,
pub quality: Quality, pub quality: Quality,
pub path: PathBuf, pub path: String,
pub filename_template: String, pub filename_template: String,
pub id3v24: bool, pub id3v24: bool,
pub convert_to_mp3: bool, pub convert_to_mp3: bool,

View file

@ -1,7 +1,6 @@
use crate::downloader::DownloaderConfig; use crate::downloader::DownloaderConfig;
use crate::downloader::Quality; use crate::downloader::Quality;
use crate::error::SpotifyError; use crate::error::SpotifyError;
use std::path::PathBuf;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use tokio::{ use tokio::{
@ -36,7 +35,7 @@ impl Settings {
downloader: DownloaderConfig { downloader: DownloaderConfig {
concurrent_downloads: 4, concurrent_downloads: 4,
quality: Quality::Q320, quality: Quality::Q320,
path: PathBuf::from("downloads"), path: "downloads".to_string(),
filename_template: "%artist% - %title%".to_string(), filename_template: "%artist% - %title%".to_string(),
id3v24: true, id3v24: true,
convert_to_mp3: false, convert_to_mp3: false,