Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search function doesn't result in the same result every time #860

Open
chaitanya-gvs opened this issue Sep 24, 2022 · 3 comments
Open

Search function doesn't result in the same result every time #860

chaitanya-gvs opened this issue Sep 24, 2022 · 3 comments
Labels

Comments

@chaitanya-gvs
Copy link

Describe the bug
The search function for tracks sometimes results in an empty array even though the songs are available on Spotify.

Your code
image

songURIList = [] # List to store the URIs
for idx,_ in tqdm(dfBillbaords[0:10].iterrows()):

    artist = dfBillbaords['Artist'][idx]
    track = dfBillbaords['Song'][idx]
    year = dfBillbaords['Year'][idx]

    searchResults = sp.search(q=f"artist: {artist} track: {track} year: {year}",type='track')

    if len(searchResults['tracks']['items'])>0:
        songURI = searchResults['tracks']['items'][0]['uri']   #Getting the URI of the first track in search result
    else:
        songURI = 'Unavailable'   #Assigning URI as 'Unavailable' 
    songURIList.append(songURI)
    time.sleep(5)

Expected behavior
The search result should be the same every time.
However the search result changes every time I run. It is not reproducible.

Output
Case 1:
image
Case 2:
image

Notice the difference in outputs between the two cases above,
The output is quite erratic and changing with every re-run.
The search function is failing to fetch the songs even if they're available.

Environment:

  • OS: Windows 11
  • Python version: 3.8.8
  • spotipy version: 2.2
  • IDE : Jupyter Notebook IDE
@dpnem
Copy link

dpnem commented Sep 25, 2022

I believe this is an Spotify API issue with the single quotes (') in the track names. If you remove the single quote from the track titles, you should be good.

Here's a quick search I did on "search track with single quote"

@chaitanya-gvs
Copy link
Author

I don't think that's the case.
I have searched for tracks without single quotes in their names as well. And it still repeats.

@stephanebruckert
Copy link
Member

@Chaitanya98 your example does not really show that spotipy or the Spotify API is the issue.

Perhaps, your initial dataframe isn't the same or isn't ordered the same way every time?

I don't want to know what tqdm() is doing, but your example could be simplified to do the exact same query every time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants