I have a dataset structured with title of a track used in a film, title of the film, year of the film. I need to find the uri of the track on spotify using python. I need to search every tracks by the title and the year of the film
this is an example of what i try
import spotipy
from spotipy.oauth2 import SpotifyClientCredentials
import json
credentials = json.load(open('autorizzazione.json'))
client_id = credentials['client_id']
client_secret = credentials['client_secret']
client_credentials_manager =
SpotifyClientCredentials(client_id=client_id,client_secret=client_secret)
sp = spotipy.Spotify(client_credentials_manager=client_credentials_manager)
listasong =pd.read_csv("dataset.csv")
research = sp.search([listasong["track"][0],listasong["year"][0]] , limit=1, offset=0, type=["track, year"] , market=None) ##track is the name of the column that contain the title of the song
this gave me error because it say my research is poorly. In a second moment i need to switch year with title_film to search by title of the song, and title of the album, because often the album or the compilation on spotify have the name of the film in it.
The q
of search(q, limit=10, offset=0, type='track', market=None)
should be one string. Also, year
is not a type.
Bellow is my rewritten and fixed code:
import spotipy
from spotipy.oauth2 import SpotifyClientCredentials
import pandas as pd
import json
credentials = json.load(open('autorizzazione.json'))
client_id = credentials['client_id']
client_secret = credentials['client_secret']
auth_manager = SpotifyClientCredentials(client_id=client_id, client_secret=client_secret)
sp = spotipy.Spotify(auth_manager=auth_manager)
listasong = pd.read_csv("dataset.csv")
q = f"track:\"{listasong['track'][0]}\" year:{listasong['year'][0]}"
research = sp.search(q=q, limit=1, offset=0, type="track", market=None)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.