jramosdc / datajournos1

Let's start using github
0 stars 0 forks source link

Python Library for the Spotify API #2

Open jramosdc opened 6 years ago

jramosdc commented 6 years ago

https://github.com/plamere/spotipy

jramosdc commented 6 years ago

@JaviGago Create a user in Spotify Developer and get your SECRETS

jramosdc commented 6 years ago
import spotipy
import spotipy.oauth2 as oauth2

credentials = oauth2.SpotifyClientCredentials(
        client_id="xxxxxxxxx",
        client_secret= "42xxxxxx")

token = credentials.get_access_token()

birdy_uri = 'spotify:artist:2WX2uTcsvV5OnS0inACecP'
spotify = spotipy.Spotify(auth=token)

results = spotify.artist_albums(birdy_uri, album_type='album')
albums = results['items']
while results['next']:
    results = spotify.next(results)
    albums.extend(results['items'])

for album in albums:
    print(album['name'])

Con esto ya podeis empezar a trastear, pero usas vuestras credenciales

jramosdc commented 6 years ago
import requests

headers = {
    'Authorization': 'Bearer BQD14NPBhoYseCefL6OzuBNTCr05wKRdoswnwMj7eYIq1hzqloOdQ4dnr1PxCgAccobf7LouLz2Zy_sc-3BLpICA5JkmiaqU9suhet7Rv2OJCmrPCH412PqGW96peEmTHEfbJgJL9A'
}

params = {
    'q': 'La Llamada',
    'type': 'track',
    'market': 'es',
    'limit': '1',
}

response = requests.get('https://api.spotify.com/v1/search', headers=headers, params=params)

results=response.json()
r=results['tracks']['items']

print(r[0]['id'])
print(r[0]['name'])
print(r[0]['popularity'])

Mejor aún

jramosdc commented 6 years ago

https://insights.spotify.com/us/2017/09/05/how-reggaeton-became-a-global-phenomenon-on-spotify/

jramosdc commented 6 years ago
import requests
import spotipy
import spotipy.oauth2 as oauth2
import pandas as pd

credentials = oauth2.SpotifyClientCredentials(
        client_id="YOUR API ID",
        client_secret= "YOUR SECRET")

token = credentials.get_access_token()

headers = {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': 'Bearer '+ token

 }

df = pd.read_csv("hoja.csv")
for index, row in df.iterrows():
    q = row['q']
    params = {'q': q, 'type': 'track', 'market': 'es', 'limit': '1'}
    response = requests.get('https://api.spotify.com/v1/search', headers=headers, params=params)

    results=response.json()
    r=results['tracks']['items']

    print(r[0]['artists'][0]['name'])
    print(r[0]['name'])
    print(r[0]['id'])
    print(r[0]['popularity'])
##params3  = {'id':'4aWmUDTfIPGksMNLV2rQP2' }

@Aitorbp @delrio27 Este código os puede ayudar mucho. Id probando y trabajad la manera de escribirlo en un csv con python

jramosdc commented 6 years ago

http://sortyourmusic.playlistmachinery.com/ @delrio27

jramosdc commented 6 years ago

Check this out! https://plot.ly/~jairobbva/12/ @delrio27

jramosdc commented 6 years ago

@jllopc cual es tu email?

jllopc commented 6 years ago

@jramosdc mi correo es joanllc94@gmail.com