mirror of
https://github.com/KevinMidboe/spotify-downloader.git
synced 2025-10-29 09:50:16 +00:00
Calling ._get_id isn't required in new spotipy versions
This commit is contained in:
@@ -31,8 +31,10 @@ All the below changes were made as a part of #690.
|
|||||||
- Display a combined *download & encode* progress bar.
|
- Display a combined *download & encode* progress bar.
|
||||||
|
|
||||||
### Changed
|
### 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.
|
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.
|
- Allow "&" character in filenames.
|
||||||
- **[Breaking]** Merge parameters `-ff` and `-f` to `-f` (`--output-file`).
|
- **[Breaking]** Merge parameters `-ff` and `-f` to `-f` (`--output-file`).
|
||||||
- **[Breaking]** Do not prefix formats with a dot when specifying `-i` and `-o` parameters
|
- **[Breaking]** Do not prefix formats with a dot when specifying `-i` and `-o` parameters
|
||||||
|
|||||||
2
setup.py
2
setup.py
@@ -30,7 +30,7 @@ setup(
|
|||||||
"pathlib >= 1.0.1",
|
"pathlib >= 1.0.1",
|
||||||
"youtube_dl >= 2017.9.26",
|
"youtube_dl >= 2017.9.26",
|
||||||
"pytube3 >= 9.6.4",
|
"pytube3 >= 9.6.4",
|
||||||
"spotipy >= 2.4.4",
|
"spotipy >= 2.12.0",
|
||||||
"mutagen >= 1.41.1",
|
"mutagen >= 1.41.1",
|
||||||
"beautifulsoup4 >= 4.6.3",
|
"beautifulsoup4 >= 4.6.3",
|
||||||
"unicode-slugify >= 0.1.3",
|
"unicode-slugify >= 0.1.3",
|
||||||
|
|||||||
@@ -70,13 +70,13 @@ def get_arguments(argv=None, base_config_file=spotdl.config.default_config_file)
|
|||||||
"if `--write-to=<path/to/file.txt>` has been passed",
|
"if `--write-to=<path/to/file.txt>` has been passed",
|
||||||
)
|
)
|
||||||
group.add_argument(
|
group.add_argument(
|
||||||
"-b",
|
"-a",
|
||||||
"--album",
|
"--album",
|
||||||
help="load tracks from album URL into <album_name>.txt or if "
|
help="load tracks from album URL into <album_name>.txt or if "
|
||||||
"`--write-to=<path/to/file.txt>` has been passed"
|
"`--write-to=<path/to/file.txt>` has been passed"
|
||||||
)
|
)
|
||||||
group.add_argument(
|
group.add_argument(
|
||||||
"-ab",
|
"-aa",
|
||||||
"--all-albums",
|
"--all-albums",
|
||||||
help="load all tracks from artist URL into <artist_name>.txt "
|
help="load all tracks from artist URL into <artist_name>.txt "
|
||||||
"or if `--write-to=<path/to/file.txt>` has been passed"
|
"or if `--write-to=<path/to/file.txt>` has been passed"
|
||||||
|
|||||||
@@ -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
|
from spotdl.authorize.services import AuthorizeSpotify
|
||||||
import spotdl.util
|
import spotdl.util
|
||||||
|
|
||||||
@@ -19,11 +14,8 @@ except ImportError:
|
|||||||
sys.exit(5)
|
sys.exit(5)
|
||||||
|
|
||||||
|
|
||||||
ALBUM_BASE_URL = "https://open.spotify.com/album/"
|
|
||||||
|
|
||||||
class SpotifyHelpers:
|
class SpotifyHelpers:
|
||||||
def __init__(self, spotify=None):
|
def __init__(self, spotify=None):
|
||||||
self._ALBUM_BASE_URL = ALBUM_BASE_URL
|
|
||||||
if spotify is None:
|
if spotify is None:
|
||||||
spotify = AuthorizeSpotify()
|
spotify = AuthorizeSpotify()
|
||||||
self.spotify = spotify
|
self.spotify = spotify
|
||||||
@@ -64,18 +56,12 @@ class SpotifyHelpers:
|
|||||||
def fetch_playlist(self, playlist_url):
|
def fetch_playlist(self, playlist_url):
|
||||||
logger.debug('Fetching playlist "{playlist}".'.format(playlist=playlist_url))
|
logger.debug('Fetching playlist "{playlist}".'.format(playlist=playlist_url))
|
||||||
try:
|
try:
|
||||||
playlist_id = self.spotify._get_id("playlist", playlist_url)
|
results = self.spotify.playlist(playlist_url, fields="tracks,next,name")
|
||||||
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"
|
|
||||||
)
|
|
||||||
except spotipy.client.SpotifyException:
|
except spotipy.client.SpotifyException:
|
||||||
logger.error("Unable to find playlist")
|
logger.exception(
|
||||||
logger.info("Make sure the playlist is set to publicly visible and then try again.")
|
"Unable to find playlist. Make sure the playlist is set "
|
||||||
|
"to publicly visible and then try again."
|
||||||
|
)
|
||||||
sys.exit(11)
|
sys.exit(11)
|
||||||
|
|
||||||
return results
|
return results
|
||||||
@@ -86,10 +72,9 @@ class SpotifyHelpers:
|
|||||||
text_file = u"{0}.txt".format(slugify(playlist["name"], ok="-_()[]{}"))
|
text_file = u"{0}.txt".format(slugify(playlist["name"], ok="-_()[]{}"))
|
||||||
return self.write_tracks(tracks, text_file)
|
return self.write_tracks(tracks, text_file)
|
||||||
|
|
||||||
def fetch_album(self, album_url):
|
def fetch_album(self, album_uri):
|
||||||
logger.debug('Fetching album "{album}".'.format(album=album_url))
|
logger.debug('Fetching album "{album}".'.format(album=album_uri))
|
||||||
album_id = self.spotify._get_id("album", album_url)
|
album = self.spotify.album(album_uri)
|
||||||
album = self.spotify.album(album_id)
|
|
||||||
return album
|
return album
|
||||||
|
|
||||||
def write_album_tracks(self, album, text_file=None):
|
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="-_()[]{}"))
|
text_file = u"{0}.txt".format(slugify(album["name"], ok="-_()[]{}"))
|
||||||
return self.write_tracks(tracks, text_file)
|
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
|
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
|
:param album_type - the type of album to fetch (ex: single) the default is
|
||||||
all albums
|
all albums
|
||||||
:param return - the album from the artist
|
:param return - the album from the artist
|
||||||
"""
|
"""
|
||||||
|
|
||||||
logger.debug('Fetching all albums for "{artist}".'.format(artist=artist_url))
|
logger.debug('Fetching all albums for "{artist}".'.format(artist=artist_uri))
|
||||||
artist_id = self.spotify._get_id("artist", artist_url)
|
|
||||||
# fetching artist's albums limitting the results to the US to avoid duplicate
|
# fetching artist's albums limitting the results to the US to avoid duplicate
|
||||||
# albums from multiple markets
|
# 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"]
|
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
|
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
|
current working directory called [ARTIST].txt, where [ARTIST] is the artist
|
||||||
of the album
|
of the album
|
||||||
:param artist_url - spotify artist url
|
:param artist_uri - spotify artist uri
|
||||||
:param text_file - file to write albums to
|
:param text_file - file to write albums to
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user