Can now search and download all songs by artist

This commit is contained in:
Logykk 2021-10-23 21:30:15 +13:00 committed by GitHub
parent 8770de741d
commit bb7a2786af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -11,6 +11,7 @@ import json
import os import os
import os.path import os.path
import platform import platform
import posixpath
import re import re
import sys import sys
import time import time
@ -342,12 +343,12 @@ def search(search_term):
"limit": "10", "limit": "10",
"offset": "0", "offset": "0",
"q": search_term, "q": search_term,
"type": "track,album,playlist" "type": "track,album,artist,playlist"
}, },
headers={"Authorization": "Bearer %s" % token}, headers={"Authorization": "Bearer %s" % token},
) )
# print(resp.json()) print(resp.json())
i = 1 i = 1
tracks = resp.json()["tracks"]["items"] tracks = resp.json()["tracks"]["items"]
@ -385,6 +386,20 @@ def search(search_term):
else: else:
total_albums = 0 total_albums = 0
artists = resp.json()["artists"]["items"]
if len(artists) > 0:
print("### ARTISTS ###")
for artist in artists:
print("%d, %s" % (
i,
artist["name"],
))
i += 1
total_artists = i - total_tracks - total_albums - 1
print("\n")
else:
total_artists = 0
playlists = resp.json()["playlists"]["items"] playlists = resp.json()["playlists"]["items"]
print("### PLAYLISTS ###") print("### PLAYLISTS ###")
for playlist in playlists: for playlist in playlists:
@ -408,9 +423,11 @@ def search(search_term):
download_track(track_id) download_track(track_id)
elif position <= total_albums + total_tracks: elif position <= total_albums + total_tracks:
download_album(albums[position - total_tracks - 1]["id"]) download_album(albums[position - total_tracks - 1]["id"])
elif position <= total_artists + total_tracks + total_albums:
download_artist_albums(artists[position - total_tracks - total_albums -1]["id"])
else: else:
playlist_choice = playlists[position - playlist_choice = playlists[position -
total_tracks - total_albums - 1] total_tracks - total_albums - total_artists - 1]
playlist_songs = get_playlist_songs( playlist_songs = get_playlist_songs(
token, playlist_choice['id']) token, playlist_choice['id'])
for song in playlist_songs: for song in playlist_songs: