moehmeni / syncedlyrics

Get an LRC format (synchronized) lyrics for your music
MIT License
188 stars 18 forks source link

TypeError: list indices must be integers or slices, not str #35

Closed igorgukasyan closed 1 month ago

igorgukasyan commented 1 month ago

Hello,

While running a loop with syncedlyrics.search(), I sometimes face the following issue:

lrc = syncedlyrics.search("Synthetic Dream lextrical", allow_plainformat=True) Traceback (most recent call last): File "\<stdin>", line 1, in \<module> File "/anaconda3/lib/python3.11/site-packages/syncedlyrics/__init__.py",_ line 59, in search _l = provider.get_lrc(search_term) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/anaconda3/lib/python3.11/site-packages/syncedlyrics/providers/musixmatch.py", line 120, in get_lrc tracks = body["track_list"]


TypeError: list indices must be integers or slices, not str

my code:
``` python
for index, row in combined_data.iterrows():
    song = row['combined'] 
    lyrics = syncedlyrics.search(song, allow_plain_format=True)  
    data.at[index, 'lyrics'] = lyrics
````

What partially helped me was ```time.sleep(180)``` after each error and retrying the same values before skipping, yet it does not always work.
moehmeni commented 1 month ago

Hi, Apparently It is because of captcha request from MusixMatch,. You can clone the repo for latest changes that I just made so you can test again and please let me know if the problem persisted.

jagauthier commented 1 month ago

Can you implement it so that the return code for not finding lyrics is different than the return code for this error? It makes the wrapper for this function not know the difference. If there isn't a lyric, I want to move on. If there is an API issue, I want to wait and retry.

moehmeni commented 1 month ago

@jagauthier You can somehow grab all the info with the logs (-v or setting level to debug), but in case of API error, it checks the next providers so you would not get a limit most likely. Why would you wait for API limits when there are other providers?

jagauthier commented 1 month ago

Maybe I am using it wrong, but in my code:

    print(f"Seeking: '{artist}', '{title}', {fullpath}")
    try:
        lrc = syncedlyrics.search(f"{artist} {title}", allow_plain_format=True, save_path=lrc_file_name, providers=providers)
    except TypeError:
        type_error = True
    except:
        lrc = None
        other_exception = True

where providers = ["NetEase", "LrcLib", "Musixmatch", ]

It only ever uses MusixMatch. I've never got a lyric hit from one of the other providers. If I change the providers and remove MusixMatch then use a extremely popular artist and album (Taylor Swift and Midnights)

providers = ["NetEase", "LrcLib" ]

I get no lyrical hits.

0%, 0: /data/containers/plex/data/Music/Taylor Swift/Midnights (2022)/Taylor Swift - Midnights - 01 - Lavender Haze.mp3
Seeking: 'Taylor Swift', 'Lavender Haze', /data/containers/plex/data/Music/Taylor Swift/Midnights (2022)/Taylor Swift - Midnights - 01 - Lavender Haze.mp3
**Lyrics not found.**
5%, 0: /data/containers/plex/data/Music/Taylor Swift/Midnights (2022)/Taylor Swift - Midnights - 02 - Maroon.mp3
Seeking: 'Taylor Swift', 'Maroon', /data/containers/plex/data/Music/Taylor Swift/Midnights (2022)/Taylor Swift - Midnights - 02 - Maroon.mp3
**Lyrics not found.**
10%, 0: /data/containers/plex/data/Music/Taylor Swift/Midnights (2022)/Taylor Swift - Midnights - 03 - Anti‐Hero.mp3
Seeking: 'Taylor Swift', 'Anti-Hero', /data/containers/plex/data/Music/Taylor Swift/Midnights (2022)/Taylor Swift - Midnights - 03 - Anti‐Hero.mp3
**Lyrics not found.**