#print(bcolors.HEADER+"Now checking this track: "+track.asbuiltin().get("name")+bcolors.ENDC)
albuminfo=track.asbuiltin().get("album")
albumartist=albuminfo.get("artists")[0]["name"]#TODO: Handle when an album has more than one artist!
#print("Album artist is "+albumartist)
#print(track.asbuiltin())
#print(albuminfo)
artistlist=[]
foraintrack.artists:
artistlist+=[a.asbuiltin().get("name")]
#print("Found artist "+a.asbuiltin().get("name"))
ifalbumartistinartistlist:
#print("One of the track's artists is also the album artist, "+albumartist)
iflen(track.artists)==1:
artist=albumartist
else:
#print("Well, there's other artists, but going with the one whose name is on the album...")
artist=track.artists[0].asbuiltin().get("name")
else:
#print(bcolors.WARNING+"Danger, Will Robinson! No track artist matches the album artist "+albumartist+"!"+bcolors.ENDC)
if"Various Artists"inalbumartist:
#print("Taking 'Various Artists' as evidence that this is some sort of compilation, and defaulting to the first track artist listed")
artist=track.artists[0].asbuiltin().get("name")
elif"Cast"inalbumartist:
#print("Album artist has 'Cast' in its name, presuming this is a musical and that'll make more sense than crediting the individual performer as is weirdly common")
artist=albumartist
elif"Cast"inalbuminfo["name"]:
#print("Album title has 'Cast' in its name, presuming this is a musical and that'll make more sense than crediting the individual performer as is weirdly common")
artist=albumartist
else:
# If we can't match anything else, default to track artist
artist=track.artists[0].asbuiltin().get("name")
#print(bcolors.FAIL+"Oh no! Seems like I didn't catch a potential scenario, couldn't determine artist for "+track.asbuiltin().get("name")+bcolors.ENDC)
#print(" Going with "+bcolors.OKCYAN+artist+bcolors.ENDC)
returnartist
# From Blender by way of https://stackoverflow.com/a/287944/2808933, should do something better
classbcolors:
HEADER='\033[95m'
OKBLUE='\033[94m'
OKCYAN='\033[96m'
OKGREEN='\033[92m'
WARNING='\033[93m'
FAIL='\033[91m'
ENDC='\033[0m'
BOLD='\033[1m'
UNDERLINE='\033[4m'
## Takes a URL or URI and figures out if it's a URL or a URI
# \param ur A Spotify URL or URI
defur_type(ur):
spotify_url_prefix="https://open.spotify.com/"
spotify_uri_prefix="spotify:"
u="unknown"
if(ur.startswith(spotify_url_prefix)):
u="url"
elif(ur.startswith(spotify_uri_prefix)):
u="uri"
returnu
## Takes a URL or URI and figures out if it's a URL or a URI (using `urtype()`), then figures out and returns what type of entity (track, album, playlist, artist, whatever) it is