Skip to content

Commit

Permalink
Merge pull request #1217 from spotDL/dev
Browse files Browse the repository at this point in the history
Publish v3.4.1

* Artist albums fixes (#1212)
Authored by @xnetcat 

* fixed none type error when getting album (#1216)
Authored by @xnetcat

* Bump version number to v3.4.1

Co-authored-by: Jakub <42355410+xnetcat@users.noreply.github.com>
  • Loading branch information
Silverarmor and xnetcat authored Mar 18, 2021
2 parents dd57613 + fd75a38 commit f32ed39
Show file tree
Hide file tree
Showing 12 changed files with 75,951 additions and 51,942 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,6 @@ dist

# Jetbrains IDEs; PyCharm/IntelliJ
.idea

# tox
.tox
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[metadata]
version = 3.4.0
version = 3.4.1

name = spotdl
url = https://github.com/spotDL/spotify-downloader
Expand Down
6 changes: 4 additions & 2 deletions spotdl/search/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,10 @@ def _map_result_to_song_data(result: dict) -> dict:
'link': f'https://www.youtube.com/watch?v={video_id}',
'position': 0
}
if 'album' in result:
song_data['album'] = result['album']['name']

album = result.get('album')
if album:
song_data['album'] = album['name']

return song_data

Expand Down
101 changes: 76 additions & 25 deletions spotdl/search/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,64 +66,115 @@ def get_album_tracks(albumUrl: str) -> List[SongObj]:


def get_artist_tracks(artistUrl: str) -> List[SongObj]:
'''
"""
`str` `albumUrl` : Spotify Url of the artist whose tracks are to be
retrieved
returns a `list<songObj>` containing Url's of each track in the artist profile
'''
"""

spotifyClient = get_spotify_client()
artistTracks = []
artistTracks: List = []
albums: List = []
offset = 0

artistResponse = spotifyClient.artist_albums(artistUrl)

# while loop acts like do-while
while True:
for album in artistResponse['items']:
for album in artistResponse["items"]:
# check if we've already downloaded album with this name
# could happen if artist has released album for multiple regions
skipAlbum = False
for toSkip in albums:
if album["name"] == toSkip["name"]:
skipAlbum = True
break

if skipAlbum is True:
continue

# get albums and singles
if not (
album['album_group'] == 'appears_on' and album['album_type'] in [
'album', 'compilation']
album["album_group"] == "appears_on" and album["album_type"]
in ["album", "compilation"]
):
artistTracks.extend(get_album_tracks(album['id']))
artistTracksResponse = spotifyClient.album_tracks(album["uri"])
albumTracks = []

# while loop acts like do-while
while True:
for track in artistTracksResponse["items"]:
skipTrack = False
for toSkip in artistTracks:
# skip duplicate track
if toSkip.get_song_name() == track["name"]:
skipTrack = True
break

if skipTrack is True:
continue

song = SongObj.from_url(
"https://open.spotify.com/track/" + track["id"]
)

if song.get_youtube_link() is not None:
albumTracks.append(song)

# check if more tracks are to be passed
if artistTracksResponse["next"]:
artistTracksResponse = spotifyClient.album_tracks(
album["uri"], offset=len(albumTracks)
)
else:
artistTracks.extend(albumTracks)
break

# get features from other artists albums
elif album['album_group'] == 'appears_on' and album['album_type'] == 'album':
trackResponse = spotifyClient.album_tracks(album['uri'])
elif (
album["album_group"] == "appears_on" and album["album_type"] == "album"
):
featureAlbums = spotifyClient.album_tracks(album["uri"])
albumTracks = []

# while loop acts like do-while
while True:
for track in trackResponse['items']:
for artist in track['artists']:
if artist['id'] == artistResponse['href'].split('/')[-2]:
for feat in featureAlbums["items"]:
for artist in feat["artists"]:
skipTrack = False
for toSkip in artistTracks:
# skip duplicate track
if toSkip.get_song_name() == track["name"]:
skipTrack = True
break

if skipTrack is True:
continue

if artist["id"] == artistResponse["href"].split("/")[-2]:
song = SongObj.from_url(
'https://open.spotify.com/track/' + track['id']
"https://open.spotify.com/track/" + feat["id"]
)

if song.get_youtube_link() is not None:
albumTracks.append(song)

# check if more tracks are to be passed
if trackResponse['next']:
trackResponse = spotifyClient.album_tracks(
album['uri'],
offset=len(albumTracks)
if featureAlbums["next"]:
featureAlbums = spotifyClient.album_tracks(
album["uri"], offset=len(albumTracks)
)
else:
artistTracks.extend(albumTracks)
albums.append(album)
break

artistTracks.extend(albumTracks)

offset += len(artistResponse['items'])
offset += len(artistResponse["items"])

# check if more albums are to be passed
if artistResponse['next']:
artistResponse = spotifyClient.artist_albums(
artistUrl,
offset=offset
)
if artistResponse["next"]:
artistResponse = spotifyClient.artist_albums(artistUrl, offset=offset)
else:
break

Expand Down
Loading

0 comments on commit f32ed39

Please sign in to comment.