mirror of
https://github.com/GuillemCastro/spotify-dl.git
synced 2024-11-25 03:20:27 +01:00
add album download
This commit is contained in:
parent
effa494b92
commit
082a03771f
2 changed files with 33 additions and 16 deletions
|
@ -1,6 +1,6 @@
|
||||||
# spotify-dl
|
# spotify-dl
|
||||||
|
|
||||||
A command line utility to download songs and playlists directly from Spotify's servers.
|
A command line utility to download songs, podcasts, playlists and albums directly from Spotify's servers.
|
||||||
|
|
||||||
You need a Spotify Premium account.
|
You need a Spotify Premium account.
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ OPTIONS:
|
||||||
ARGS:
|
ARGS:
|
||||||
<tracks>... A list of Spotify URIs (songs, podcasts or playlists)```
|
<tracks>... A list of Spotify URIs (songs, podcasts or playlists)```
|
||||||
|
|
||||||
Songs and playlists must be passed as Spotify URIs or URLs (e.g. `spotify:track:123456789abcdefghABCDEF` for songs and `spotify:playlist:123456789abcdefghABCDEF` for playlists or `https://open.spotify.com/playlist/123456789abcdefghABCDEF?si=1234567890`).
|
Songs, playlists and albums must be passed as Spotify URIs or URLs (e.g. `spotify:track:123456789abcdefghABCDEF` for songs and `spotify:playlist:123456789abcdefghABCDEF` for playlists or `https://open.spotify.com/playlist/123456789abcdefghABCDEF?si=1234567890`).
|
||||||
|
|
||||||
## Disclaimer
|
## Disclaimer
|
||||||
|
|
||||||
|
|
43
src/main.rs
43
src/main.rs
|
@ -27,7 +27,7 @@ use indicatif::{ProgressBar, ProgressStyle};
|
||||||
about = "A commandline utility to download music directly from Spotify"
|
about = "A commandline utility to download music directly from Spotify"
|
||||||
)]
|
)]
|
||||||
struct Opt {
|
struct Opt {
|
||||||
#[structopt(help = "A list of Spotify URIs (songs, podcasts or playlists)")]
|
#[structopt(help = "A list of Spotify URIs (songs, podcasts, playlists or albums)")]
|
||||||
tracks: Vec<String>,
|
tracks: Vec<String>,
|
||||||
#[structopt(short = "u", long = "username", help = "Your Spotify username")]
|
#[structopt(short = "u", long = "username", help = "Your Spotify username")]
|
||||||
username: String,
|
username: String,
|
||||||
|
@ -175,6 +175,33 @@ async fn download_tracks(
|
||||||
bar.finish();
|
bar.finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn get_tracks_from_playlist_or_album(session: &Session, track: SpotifyId, track_url: &String) -> Vec<SpotifyId> {
|
||||||
|
match Playlist::get(&session, track).await {
|
||||||
|
Ok(playlist) => {
|
||||||
|
println!(
|
||||||
|
"Adding all songs from playlist {} (by {}) to the queue",
|
||||||
|
&playlist.name, &playlist.user
|
||||||
|
);
|
||||||
|
return playlist.tracks;
|
||||||
|
},
|
||||||
|
_ => ()
|
||||||
|
}
|
||||||
|
|
||||||
|
match Album::get(&session, track).await {
|
||||||
|
Ok(album) => {
|
||||||
|
println!(
|
||||||
|
"Adding all songs from album {} (by {:?}) to the queue",
|
||||||
|
&album.name, &album.artists
|
||||||
|
);
|
||||||
|
return album.tracks;
|
||||||
|
}
|
||||||
|
Err(_) => {
|
||||||
|
println!("Unsupported URI {}", &track_url);
|
||||||
|
vec![]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
let opt = Opt::from_args();
|
let opt = Opt::from_args();
|
||||||
|
@ -210,18 +237,8 @@ async fn main() {
|
||||||
tracks.push(track);
|
tracks.push(track);
|
||||||
}
|
}
|
||||||
librespot::core::spotify_id::SpotifyAudioType::NonPlayable => {
|
librespot::core::spotify_id::SpotifyAudioType::NonPlayable => {
|
||||||
match Playlist::get(&session, track).await {
|
let mut multiple_tracks = get_tracks_from_playlist_or_album(&session, track, &track_url).await;
|
||||||
Ok(mut playlist) => {
|
tracks.append(&mut multiple_tracks)
|
||||||
println!(
|
|
||||||
"Adding all songs from playlist {} (by {}) to the queue",
|
|
||||||
&playlist.name, &playlist.user
|
|
||||||
);
|
|
||||||
tracks.append(&mut playlist.tracks);
|
|
||||||
}
|
|
||||||
Err(_) => {
|
|
||||||
println!("Unsupported track {}", &track_url);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue