diff --git a/README.md b/README.md index d195bd4..f7165b7 100644 --- a/README.md +++ b/README.md @@ -125,10 +125,10 @@ Usage: sldl [OPTIONS] ``` ``` Spotify - --spotify-id spotify client ID - --spotify-secret spotify client secret - --spotify-token spotify access token - --spotify-refresh spotify refresh token + --spotify-id Spotify client ID + --spotify-secret Spotify client secret + --spotify-token Spotify access token + --spotify-refresh Spotify refresh token --remove-from-source Remove downloaded tracks from source playlist ``` ``` @@ -247,24 +247,28 @@ Tip: For playlists containing music videos, it may be better to remove all text A playlist/album url or 'spotify-likes': Download a spotify playlist, album, or your liked songs. Credentials are required when downloading a private playlist or liked music. -#### Using Credential/Application +#### Using Credentials -Create a [Spotify application](https://developer.spotify.com/dashboard/applications) with a redirect url of `http://localhost:48721/callback`. Obtain an application **ID** and **Secret** from the created application dashboard. +
+ Click to expand + +Create a Spotify application at https://developer.spotify.com/dashboard/applications with a redirect url http://localhost:48721/callback. Obtain an application ID and secret from the created application dashboard. Start sldl with the obtained credentials and an authorized action to trigger the Spotify app login flow: -```shell -sldl spotify-likes --number 1 --spotify-id 123456 --spotify-secret 123456 ... ``` -sldl will try to open a browser automatically but will fallback to logging the login flow URL to output. After login flow is complete sldl will output a **Token** and **Refresh Token** and finish running the current command. +sldl spotify-likes --spotify-id 123456 --spotify-secret 123456 -n 1 --print-tracks +``` +sldl will try to open a browser automatically but will fallback to logging the login flow URL to output. After login flow is complete sldl will output a token and refresh token and finish running the current command. -To skip requiring login flow every time `sldl` is used the **Token** and **Refresh Token** can be provided to sldl (hint: use `--config` and store this info in the config file to make commands less verbose): +To skip requiring login flow every time sldl is used the token and refresh token can be provided to sldl (hint: store this info in the config file to make commands less verbose): -```shell -sldl spotify-likes --number 1 --spotify-id 123456 --spotify-secret 123456 --spotify-refresh 123456 --spotify-token 123456 ... +``` +sldl spotify-likes --spotify-id 123456 --spotify-secret 123456 --spotify-refresh 123456 --spotify-token 123456 -n 1 --pt ``` -`spotify-token` access is only valid for 1 hour. `spotify-refresh` will enable sldl to renew access every time it is run (and can be used without including `spotify-token`) +spotify-token access is only valid for 1 hour. spotify-refresh will enable sldl to renew access every time it is run (and can be used without including spotify-token) +
### Bandcamp A bandcamp url: Download a single track, an album, or an artist's entire discography. diff --git a/slsk-batchdl/Extractors/Spotify.cs b/slsk-batchdl/Extractors/Spotify.cs index 598a5d8..ec65ab7 100644 --- a/slsk-batchdl/Extractors/Spotify.cs +++ b/slsk-batchdl/Extractors/Spotify.cs @@ -29,22 +29,10 @@ namespace Extractors bool needLogin = Config.input == "spotify-likes" || Config.removeTracksFromSource; var tle = new TrackListEntry(); - static void readSpotifyCreds() - { - Console.Write("Spotify client ID:"); - Config.spotifyId = Console.ReadLine(); - Console.Write("Spotify client secret:"); - Config.spotifySecret = Console.ReadLine(); - Console.Write("Spotify token:"); - Config.spotifyToken = Console.ReadLine(); - Console.Write("Spotify refresh token:"); - Config.spotifyRefresh = Console.ReadLine(); - Console.WriteLine(); - } - if (needLogin && Config.spotifyToken.Length == 0 && (Config.spotifyId.Length == 0 || Config.spotifySecret.Length == 0)) { - readSpotifyCreds(); + Console.WriteLine("Error: Credentials are required when downloading liked music or removing from source playlists."); + Environment.Exit(0); } spotifyClient = new Spotify(Config.spotifyId, Config.spotifySecret, Config.spotifyToken, Config.spotifyRefresh); @@ -73,7 +61,8 @@ namespace Extractors else if (Config.input.Contains("/artist/")) { Console.WriteLine("Loading spotify artist"); - throw new NotImplementedException("Spotify artist download currently not supported."); + Console.WriteLine("Error: Spotify artist download currently not supported."); + Environment.Exit(0); } else { @@ -93,19 +82,8 @@ namespace Extractors } else if (!needLogin) { - Console.WriteLine("Spotify playlist not found. It may be set to private. Login? [Y/n]"); - if (Console.ReadLine()?.ToLower().Trim() == "y") - { - readSpotifyCreds(); - spotifyClient = new Spotify(Config.spotifyId, Config.spotifySecret); - await spotifyClient.Authorize(true, Config.removeTracksFromSource); - Console.WriteLine("Loading Spotify playlist"); - (playlistName, playlistUri, tracks) = await spotifyClient.GetPlaylist(Config.input, max, off); - } - else - { - Environment.Exit(0); - } + Console.WriteLine("Spotify playlist not found (it may be set to private, but no credentials have been provided)."); + Environment.Exit(0); } else throw; } @@ -242,11 +220,11 @@ namespace Extractors if (_clientRefreshToken.Length != 0) { Console.WriteLine("Trying to renew access with refresh token..."); - // var refreshRequest = new TokenSwapRefreshRequest( - // new Uri("http://localhost:48721/refresh"), - // _clientRefreshToken - // ); - var refreshRequest = new AuthorizationCodeRefreshRequest(_clientId, _clientSecret, _clientRefreshToken); + // var refreshRequest = new TokenSwapRefreshRequest( + // new Uri("http://localhost:48721/refresh"), + // _clientRefreshToken + // ); + var refreshRequest = new AuthorizationCodeRefreshRequest(_clientId, _clientSecret, _clientRefreshToken); try { var oauthClient = new OAuthClient(); @@ -279,9 +257,11 @@ namespace Extractors ) ); - Console.WriteLine("Spotify token: " + tokenResponse.AccessToken); + Console.WriteLine("spotify-token=" + tokenResponse.AccessToken); _clientToken = tokenResponse.AccessToken; - Console.WriteLine("Spotify refresh token: " + tokenResponse.RefreshToken); + Console.WriteLine(); + Console.WriteLine("spotify-refresh=" + tokenResponse.RefreshToken); + Console.WriteLine(); _clientRefreshToken = tokenResponse.RefreshToken; _client = new SpotifyClient(tokenResponse.AccessToken); diff --git a/slsk-batchdl/Help.cs b/slsk-batchdl/Help.cs index 98ff06c..dfb9ef9 100644 --- a/slsk-batchdl/Help.cs +++ b/slsk-batchdl/Help.cs @@ -102,8 +102,10 @@ public static class Help See --help ""search"". (default: 220) Spotify - --spotify-id spotify client ID - --spotify-secret spotify client secret + --spotify-id Spotify client ID + --spotify-secret Spotify client secret + --spotify-token Spotify access token + --spotify-refresh Spotify refresh token --remove-from-source Remove downloaded tracks from source playlist YouTube @@ -219,6 +221,26 @@ public static class Help The id and secret can be obtained at https://developer.spotify.com/dashboard/applications. Create an app and add http://localhost:48721/callback as a redirect url in its settings. + Using Credentials + Create a Spotify application at https://developer.spotify.com/dashboard/applications with a + redirect url http://localhost:48721/callback. Obtain an application ID and secret from the + created application dashboard. + Start sldl with the obtained credentials and an authorized action to trigger the Spotify + app login flow: + + sldl spotify-likes --spotify-id 123456 --spotify-secret 123456 -n 1 --print-tracks + + sldl will try to open a browser automatically but will fallback to logging the login flow + URL to output. After login flow is complete sldl will output a token and refresh token and + finish running the current command. + To skip requiring login flow every time sldl is used the token and refresh token can be + provided to sldl (hint: store this info in the config file to make commands less verbose): + + sldl spotify-likes --spotify-id 123456 --spotify-secret 123456 --spotify-refresh 123456 --spotify-token 123456 -n 1 --pt + + spotify-token access is only valid for 1 hour. spotify-refresh will enable sldl to renew + access every time it is run (and can be used without including spotify-token). + Bandcamp A bandcamp url: Download a single track, an album, or an artist's entire discography. Extracts the artist name, album name and sets --album-track-count=""n+"", where n is the