コード例 #1
0
 def setUpClass(self):
     # Required environment variables, set these before running!
     client_id = os.getenv('SPOTIFY_CLIENT_ID')
     client_secret = os.getenv('SPOTIFY_CLIENT_SECRET')
     refresh_token = os.getenv('SPOTIFY_REFRESH_TOKEN')
     user = spotify.SpotifyUser(refresh_token=refresh_token)
     self.api = spotify.SpotifyAPI(client_id, client_secret, user=user)
コード例 #2
0
def search(request):
    query = request.GET['query']
    query = query.replace("+",' ')
    client_id = '5244f03937d2403d95902683a070a162'
    client_secret = '784bdf33b03d4afdb6320be398b0fa78'
    s = spotify.SpotifyAPI(client_id,client_secret)
    track_info,seeds = s.get_songs_full(query)
    return render(request,'blog.html',{'tracks_info':track_info})
コード例 #3
0
def search_art(request):
    query_art = request.GET['query_art']
    query_art = query_art.replace("+",' ')
    client_id = '5244f03937d2403d95902683a070a162'
    client_secret = '784bdf33b03d4afdb6320be398b0fa78'
    s = spotify.SpotifyAPI(client_id,client_secret)
    get_artist = s.search({"artist": query_art}, search_type="artist")#obtener artistas relacionados a un hint
    y = get_artist['artists']['items'][0]['id']#toma el primer atistas del dict
    r_artists = s.related_artists_search(y)#realiza la busqueda de artistas relacionados con la id del primer artista(hint mas preciso)
    get_artist['related_artists'] = r_artists['artists'] #asigna valores para related artists en el dict    
    return render(request,'blog2.html',{'artist_info':get_artist})
コード例 #4
0
ファイル: views.py プロジェクト: NickJGG/mixjam
def callback(request):
    if request.GET and 'code' in request.GET:
        spot = spotify_auth.SpotifyAPI(client_id, client_secret, request.user,
                                       request.GET['code'])
        spot.perform_user_auth()

        request.user.userprofile.authorized = True
        request.user.userprofile.save()

        messages.success(request, 'Spotify account linked')

    return redirect('index')
コード例 #5
0
def tabla(request):
    client_id = '5244f03937d2403d95902683a070a162'
    client_secret = '784bdf33b03d4afdb6320be398b0fa78'
    s = spotify.SpotifyAPI(client_id,client_secret)
    df = pd.read_csv("kornbyte/top_tracks_csv/top.csv")
    dfnew = df.rename(columns={'Unnamed: 0': 'top','Unnamed: 1': 'track','Unnamed: 2':'artist','Note that these figures are generated using a formula that protects against any artificial inflation of chart positions.':'streams','Unnamed: 4':'open_url'})
    dfnew = dfnew.drop(0)
    df_five = dfnew.iloc[:50]
    df_five = df_five.to_json(orient = 'records')
    r = json.loads(df_five)
    get_info = {}
    cont = 0
    for i in r:
        hint_ = r[cont]['artist']
        get_info = s.get_artists_bi_hint(hint_)
        r[cont]['detail_info'] = get_info['artists']['items'][0]
        cont +=1    
    top_artists_details = r
    return render(request,'tables.html',{'top_tracks':r})
コード例 #6
0
def prueba_json(request):
    client_id = '5244f03937d2403d95902683a070a162'
    client_secret = '784bdf33b03d4afdb6320be398b0fa78'
    s = spotify.SpotifyAPI(client_id,client_secret)
    df = pd.read_csv("kornbyte/top_tracks_csv/top.csv")
    dfnew = df.rename(columns={'Unnamed: 0': 'top','Unnamed: 1': 'track','Unnamed: 2':'artist','Note that these figures are generated using a formula that protects against any artificial inflation of chart positions.':'streams','Unnamed: 4':'open_url'})
    dfnew = dfnew.drop(0)
    df_five = dfnew.iloc[:10]
    df_five = df_five.to_json(orient = 'records')
    r = json.loads(df_five)
    get_info = {}
    cont = 0
    for i in r:
        hint_ = r[cont]['artist']
        get_info = s.get_artists_bi_hint(hint_)
        r[cont]['detail_info'] = get_info['artists']['items'][0]
        cont +=1    
    top_artists_details = r

    # agregar al search_full los links a mp3.spotify
    #función para descargar la musica
    #ocupar get   
    return HttpResponse(top_artists_details)
コード例 #7
0
import spotify
import json
import requests
import csv
import pandas as pd
client_id = '5244f03937d2403d95902683a070a162'
client_secret = '784bdf33b03d4afdb6320be398b0fa78'
s = spotify.SpotifyAPI(client_id, client_secret)
get_track = s.search(
    {"artist": 'gojira'},
    search_type="artist")  #obtener artistas relacionados a un hint
y = get_track['artists']['items'][0]['id']  #toma el primer atistas del dict
r_artists = s.related_artists_search(
    y
)  #realiza la busqueda de artistas relacionados con la id del primer artista(hint mas preciso)
get_track['related_artists'] = r_artists[
    'artists']  #asigna valores para related artists en el dict
g = (json.dumps(get_track))
print(g)
#print(json.dumps(tracks_info))
#print(type(tracks_info[0]))
#url = 'https://p.scdn.co/mp3-preview/af237206f611b722f48620ece049aff3b8650e77?cid=5244f03937d2403d95902683a070a162'
#r = requests.get(url, allow_redirects=True)
#open('static/music-files/idtrack_preview.mp3', 'wb').write(r.content)
'''reader = csv.DictReader(open('kornbyte/top_tracks_csv/top.csv','rb',encoding="UTF-8"))
dict_ = {'hits':{}}
cont = 1
for line in reader:
    dict_ = {cont:line}
print(reader)'''
'''df = pd.read_csv("kornbyte/top_tracks_csv/top.csv")