mirror of
https://github.com/KevinMidboe/spotify-downloader.git
synced 2025-10-29 18:00:15 +00:00
Merge pull request #493 from ritiek/fetch-all-album-types
Fetch all album types for an artist by default
This commit is contained in:
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
||||
-
|
||||
|
||||
### Changed
|
||||
- Fetch all artist albums by default instead of only fetching the "album" type ([@ritiek](https://github.com/ritiek)) (#493)
|
||||
- Option `-f` (`--folder`) is used when exporting text files using `-p` (`--playlist`) for playlists or `-b` (`--album`) for albums ([@Silverfeelin](https://github.com/Silverfeelin)) (#476)
|
||||
- Use first artist from album object for album artist ([@tillhainbach](https://github.com/tillhainbach))
|
||||
|
||||
|
||||
@@ -158,13 +158,13 @@ def fetch_album(album):
|
||||
return album
|
||||
|
||||
|
||||
def fetch_albums_from_artist(artist_url, album_type="album"):
|
||||
def fetch_albums_from_artist(artist_url, album_type=None):
|
||||
"""
|
||||
This funcction returns all the albums from a give artist_url using the US
|
||||
market
|
||||
:param artist_url - spotify artist url
|
||||
:param album_type - the type of album to fetch (ex: single) the default is
|
||||
a standard album
|
||||
all albums
|
||||
:param return - the album from the artist
|
||||
"""
|
||||
|
||||
@@ -195,7 +195,7 @@ def write_all_albums_from_artist(artist_url, text_file=None):
|
||||
album_base_url = "https://open.spotify.com/album/"
|
||||
|
||||
# fetching all default albums
|
||||
albums = fetch_albums_from_artist(artist_url)
|
||||
albums = fetch_albums_from_artist(artist_url, album_type=None)
|
||||
|
||||
# if no file if given, the default save file is in the current working
|
||||
# directory with the name of the artist
|
||||
@@ -207,13 +207,6 @@ def write_all_albums_from_artist(artist_url, text_file=None):
|
||||
log.info("Fetching album: " + album["name"])
|
||||
write_album(album_base_url + album["id"], text_file=text_file)
|
||||
|
||||
# fetching all single albums
|
||||
singles = fetch_albums_from_artist(artist_url, album_type="single")
|
||||
|
||||
for single in singles:
|
||||
log.info("Fetching single: " + single["name"])
|
||||
write_album(album_base_url + single["id"], text_file=text_file)
|
||||
|
||||
|
||||
def write_album(album_url, text_file=None):
|
||||
album = fetch_album(album_url)
|
||||
|
||||
@@ -113,7 +113,8 @@ class TestFetchAlbumsFromArtist:
|
||||
return albums
|
||||
|
||||
def test_len(self, albums_from_artist_fixture):
|
||||
assert len(albums_from_artist_fixture) == 18
|
||||
# TODO: Mock this test (failed in #493)
|
||||
assert len(albums_from_artist_fixture) == 52
|
||||
|
||||
def test_zeroth_album_name(self, albums_from_artist_fixture):
|
||||
assert albums_from_artist_fixture[0]["name"] == "Revolution Radio"
|
||||
@@ -128,11 +129,9 @@ class TestFetchAlbumsFromArtist:
|
||||
assert albums_from_artist_fixture[0]["total_tracks"] == 12
|
||||
|
||||
|
||||
# XXX: Mock this test off if it fails in future
|
||||
# TODO: Mock this test (failed in #493)
|
||||
def test_write_all_albums_from_artist(tmpdir):
|
||||
# current number of tracks on spotify since as of 10/10/2018
|
||||
# in US market only
|
||||
expect_tracks = 49
|
||||
expect_tracks = 282
|
||||
text_file = os.path.join(str(tmpdir), "test_ab.txt")
|
||||
spotify_tools.write_all_albums_from_artist(
|
||||
"https://open.spotify.com/artist/4dpARuHxo51G3z768sgnrY", text_file
|
||||
|
||||
Reference in New Issue
Block a user