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,6 +51,21 @@ 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

View file

@ -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,

View file

@ -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,