Merge pull request #493 from ritiek/fetch-all-album-types

Fetch all album types for an artist by default
This commit is contained in:
Ritiek Malhotra
2019-02-08 18:03:37 +05:30
committed by GitHub
3 changed files with 8 additions and 15 deletions

View File

@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- -
### Changed ### 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) - 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)) - Use first artist from album object for album artist ([@tillhainbach](https://github.com/tillhainbach))

View File

@@ -158,13 +158,13 @@ def fetch_album(album):
return 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 This funcction returns all the albums from a give artist_url using the US
market market
:param artist_url - spotify artist url :param artist_url - spotify artist url
: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
a standard album all albums
:param return - the album from the artist :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/" album_base_url = "https://open.spotify.com/album/"
# fetching all default albums # 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 # if no file if given, the default save file is in the current working
# directory with the name of the artist # 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"]) log.info("Fetching album: " + album["name"])
write_album(album_base_url + album["id"], text_file=text_file) 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): def write_album(album_url, text_file=None):
album = fetch_album(album_url) album = fetch_album(album_url)

View File

@@ -113,7 +113,8 @@ class TestFetchAlbumsFromArtist:
return albums return albums
def test_len(self, albums_from_artist_fixture): 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): def test_zeroth_album_name(self, albums_from_artist_fixture):
assert albums_from_artist_fixture[0]["name"] == "Revolution Radio" assert albums_from_artist_fixture[0]["name"] == "Revolution Radio"
@@ -128,11 +129,9 @@ class TestFetchAlbumsFromArtist:
assert albums_from_artist_fixture[0]["total_tracks"] == 12 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): def test_write_all_albums_from_artist(tmpdir):
# current number of tracks on spotify since as of 10/10/2018 expect_tracks = 282
# in US market only
expect_tracks = 49
text_file = os.path.join(str(tmpdir), "test_ab.txt") text_file = os.path.join(str(tmpdir), "test_ab.txt")
spotify_tools.write_all_albums_from_artist( spotify_tools.write_all_albums_from_artist(
"https://open.spotify.com/artist/4dpARuHxo51G3z768sgnrY", text_file "https://open.spotify.com/artist/4dpARuHxo51G3z768sgnrY", text_file