Add variables documentation to the readme and allow variables in the downloader path
This commit is contained in:
parent
19b25479ae
commit
9779b4af6b
3 changed files with 26 additions and 8 deletions
15
README.md
15
README.md
|
|
@ -51,6 +51,21 @@ 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
|
||||||
|
|
|
||||||
|
|
@ -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,
|
||||||
|
|
|
||||||
|
|
@ -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,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue