diff --git a/README.md b/README.md index d11273b..92370eb 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # 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. @@ -50,7 +50,7 @@ OPTIONS: ARGS: ... 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 diff --git a/src/main.rs b/src/main.rs index 2911c57..8464d5b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -27,7 +27,7 @@ use indicatif::{ProgressBar, ProgressStyle}; about = "A commandline utility to download music directly from Spotify" )] 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, #[structopt(short = "u", long = "username", help = "Your Spotify username")] username: String, @@ -97,7 +97,7 @@ async fn download_tracks( bar.set_style(bar_style); bar.enable_steady_tick(500); - for (i, track) in tracks.iter().enumerate() { + for (i, track) in tracks.iter().enumerate() { let track_item = Track::get(&session, *track).await.unwrap(); let artist_name: String; @@ -175,6 +175,33 @@ async fn download_tracks( bar.finish(); } +async fn get_tracks_from_playlist_or_album(session: &Session, track: SpotifyId, track_url: &String) -> Vec { + 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] async fn main() { let opt = Opt::from_args(); @@ -210,18 +237,8 @@ async fn main() { tracks.push(track); } librespot::core::spotify_id::SpotifyAudioType::NonPlayable => { - match Playlist::get(&session, track).await { - Ok(mut playlist) => { - 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); - } - } + let mut multiple_tracks = get_tracks_from_playlist_or_album(&session, track, &track_url).await; + tracks.append(&mut multiple_tracks) } } }