From 819bb87fc22faa61ef7f10cc61597d0c5f91ccd6 Mon Sep 17 00:00:00 2001 From: Ritiek Malhotra Date: Sun, 10 May 2020 18:16:57 +0530 Subject: [PATCH] Calling ._get_id isn't required in new spotipy versions --- CHANGES.md | 4 ++- setup.py | 2 +- spotdl/command_line/arguments.py | 4 +-- spotdl/helpers/spotify.py | 44 ++++++++++---------------------- 4 files changed, 20 insertions(+), 34 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 4e614de..4dcb88a 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -31,8 +31,10 @@ All the below changes were made as a part of #690. - Display a combined *download & encode* progress bar. ### Changed -- Tracks are now downloaded in the current working directory (instead of Music directory) +- **[Breaking]** Tracks are now downloaded in the current working directory (instead of Music directory) by default. +- **[Breaking]** Short for `--album` is now `-a` instead of `-b`. +- **[Breaking]** Short for `--all-albums` is now `-aa` instead of `-ab`. - Allow "&" character in filenames. - **[Breaking]** Merge parameters `-ff` and `-f` to `-f` (`--output-file`). - **[Breaking]** Do not prefix formats with a dot when specifying `-i` and `-o` parameters diff --git a/setup.py b/setup.py index 2fc0da1..fdf6f89 100644 --- a/setup.py +++ b/setup.py @@ -30,7 +30,7 @@ setup( "pathlib >= 1.0.1", "youtube_dl >= 2017.9.26", "pytube3 >= 9.6.4", - "spotipy >= 2.4.4", + "spotipy >= 2.12.0", "mutagen >= 1.41.1", "beautifulsoup4 >= 4.6.3", "unicode-slugify >= 0.1.3", diff --git a/spotdl/command_line/arguments.py b/spotdl/command_line/arguments.py index 0469215..e9160c8 100644 --- a/spotdl/command_line/arguments.py +++ b/spotdl/command_line/arguments.py @@ -70,13 +70,13 @@ def get_arguments(argv=None, base_config_file=spotdl.config.default_config_file) "if `--write-to=` has been passed", ) group.add_argument( - "-b", + "-a", "--album", help="load tracks from album URL into .txt or if " "`--write-to=` has been passed" ) group.add_argument( - "-ab", + "-aa", "--all-albums", help="load all tracks from artist URL into .txt " "or if `--write-to=` has been passed" diff --git a/spotdl/helpers/spotify.py b/spotdl/helpers/spotify.py index 9c6bacb..44d2414 100644 --- a/spotdl/helpers/spotify.py +++ b/spotdl/helpers/spotify.py @@ -1,8 +1,3 @@ -# XXX: Perhaps we do not need to call `spotify._get_id` -# explicitly in newer versions of spotipy. -# Need to confirm this and if so, remove the calls -# to `spotify._get_id` in below methods. - from spotdl.authorize.services import AuthorizeSpotify import spotdl.util @@ -19,11 +14,8 @@ except ImportError: sys.exit(5) -ALBUM_BASE_URL = "https://open.spotify.com/album/" - class SpotifyHelpers: def __init__(self, spotify=None): - self._ALBUM_BASE_URL = ALBUM_BASE_URL if spotify is None: spotify = AuthorizeSpotify() self.spotify = spotify @@ -64,18 +56,12 @@ class SpotifyHelpers: def fetch_playlist(self, playlist_url): logger.debug('Fetching playlist "{playlist}".'.format(playlist=playlist_url)) try: - playlist_id = self.spotify._get_id("playlist", playlist_url) - except IndexError: - # Wrong format, in either case - logger.error("The provided playlist URL is not in a recognized format!") - sys.exit(10) - try: - results = self.spotify.user_playlist( - user=None, playlist_id=playlist_id, fields="tracks,next,name" - ) + results = self.spotify.playlist(playlist_url, fields="tracks,next,name") except spotipy.client.SpotifyException: - logger.error("Unable to find playlist") - logger.info("Make sure the playlist is set to publicly visible and then try again.") + logger.exception( + "Unable to find playlist. Make sure the playlist is set " + "to publicly visible and then try again." + ) sys.exit(11) return results @@ -86,10 +72,9 @@ class SpotifyHelpers: text_file = u"{0}.txt".format(slugify(playlist["name"], ok="-_()[]{}")) return self.write_tracks(tracks, text_file) - def fetch_album(self, album_url): - logger.debug('Fetching album "{album}".'.format(album=album_url)) - album_id = self.spotify._get_id("album", album_url) - album = self.spotify.album(album_id) + def fetch_album(self, album_uri): + logger.debug('Fetching album "{album}".'.format(album=album_uri)) + album = self.spotify.album(album_uri) return album def write_album_tracks(self, album, text_file=None): @@ -98,21 +83,20 @@ class SpotifyHelpers: text_file = u"{0}.txt".format(slugify(album["name"], ok="-_()[]{}")) return self.write_tracks(tracks, text_file) - def fetch_albums_from_artist(self, artist_url, album_type=None): + def fetch_albums_from_artist(self, artist_uri, album_type=None): """ - This function returns all the albums from a give artist_url using the US + This function returns all the albums from a give artist_uri using the US market - :param artist_url - spotify artist url + :param artist_uri - spotify artist uri :param album_type - the type of album to fetch (ex: single) the default is all albums :param return - the album from the artist """ - logger.debug('Fetching all albums for "{artist}".'.format(artist=artist_url)) - artist_id = self.spotify._get_id("artist", artist_url) + logger.debug('Fetching all albums for "{artist}".'.format(artist=artist_uri)) # fetching artist's albums limitting the results to the US to avoid duplicate # albums from multiple markets - results = self.spotify.artist_albums(artist_id, album_type=album_type, country="US") + results = self.spotify.artist_albums(artist_uri, album_type=album_type, country="US") albums = results["items"] @@ -128,7 +112,7 @@ class SpotifyHelpers: This function gets all albums from an artist and writes it to a file in the current working directory called [ARTIST].txt, where [ARTIST] is the artist of the album - :param artist_url - spotify artist url + :param artist_uri - spotify artist uri :param text_file - file to write albums to """