70 lines
1.8 KiB
Python
70 lines
1.8 KiB
Python
import info_imp
|
|
import json
|
|
import test
|
|
import random
|
|
|
|
client_id = info_imp.datinho['sp_client_id']
|
|
client_secret = info_imp.datinho['sp_client_secret']
|
|
|
|
sp = test.SpotifyAPI(client_id, client_secret)
|
|
|
|
songs = []
|
|
name = []
|
|
cover = []
|
|
|
|
# Uses the getSong function from songrand.py to get a list of all the songs URLs in playlist
|
|
|
|
def getSongList(lista):
|
|
dict1 = sp.getPlayTracks()
|
|
dict2 = dict1['items']
|
|
for songs in dict2:
|
|
dict3 = songs['track']
|
|
for songs_def in dict3['external_urls'].values():
|
|
lista.append(songs_def)
|
|
return lista
|
|
|
|
# Uses the getNameSong function from sonrand.py to get a list of all the songs names in playlist
|
|
|
|
def getNameSong(lista):
|
|
dict1 = sp.getPlayTracks()
|
|
dict2 = dict1['items']
|
|
for songs in dict2:
|
|
dict3 = songs['track']
|
|
for songs_def in dict3['external_ids'].values():
|
|
lista.append(dict3['name'])
|
|
return lista
|
|
|
|
# Uses the getCover function from songrand.py to get a list of all the song cover URLs in playlist
|
|
|
|
def getCover(lista):
|
|
dict1 = sp.getPlayTracks()
|
|
dict2 = dict1['items']
|
|
for songs in dict2:
|
|
dict3 = songs['track']
|
|
for songs_def in dict3['album'].values():
|
|
dict4 = dict3['album']
|
|
for things1 in dict4['images']:
|
|
dict5 = dict4['images']
|
|
for things2 in dict5:
|
|
dict6 = things2
|
|
for things3 in dict6:
|
|
if things3 not in lista:
|
|
lista.append(dict6['url'])
|
|
return lista
|
|
|
|
|
|
# Picks a random number between 0 and len(lista)-1 to fit list indexes
|
|
|
|
def pickNumber(lista):
|
|
num = len(lista) - 1
|
|
pick = random.randrange(0, num)
|
|
return pick
|
|
|
|
# Picks the element [numberGaveByPickNumberFunction] and returns that value
|
|
|
|
def pickList(num, lista):
|
|
fin3 = lista[num]
|
|
return fin3
|
|
|
|
|