reteps / lrc_kit

A library for searching, downloading, and parsing song lyrics in LRC format in python.
MIT License
24 stars 1 forks source link

Exceptions during search not handled #4

Open SimonIT opened 3 years ago

SimonIT commented 3 years ago
AttributeError: 'NoneType' object has no attribute 'group'
  File "services.py", line 42, in wrapper
    return func(*args, **kwargs)
  File "services.py", line 89, in _lrckit
    result = engine.search(search)
  File "lrc_kit\providers.py", line 92, in search
    res = provider(**self.kwargs).search(search_request)
  File "lrc_kit\providers.py", line 45, in search
    raise e
  File "lrc_kit\providers.py", line 34, in search
    lrc = self.fetch(val)
  File "lrc_kit\providers.py", line 406, in fetch
    match = re.search(lyric_regex, lyrics_page).group(1)
TypeError: 'NoneType' object is not subscriptable
  File "services.py", line 42, in wrapper
    return func(*args, **kwargs)
  File "services.py", line 89, in _lrckit
    result = engine.search(search)
  File "lrc_kit\providers.py", line 92, in search
    res = provider(**self.kwargs).search(search_request)
  File "lrc_kit\providers.py", line 45, in search
    raise e
  File "lrc_kit\providers.py", line 34, in search
    lrc = self.fetch(val)
  File "lrc_kit\providers.py", line 512, in fetch
    lyric_text = lyrics[1].replace('<br />','')
reteps commented 3 years ago

Can you provide the code used to generate this error.

SimonIT commented 3 years ago
    my_ses = requests.Session()
    my_ses.proxies.update(Config.PROXY)
    engine = ComboLyricsProvider(session=my_ses)
    search = SearchRequest(song.artist, song.name)
    result = engine.search(search)
reteps commented 3 years ago

What is Config.PROXY's value

SimonIT commented 3 years ago

It's an empty dictionary

reteps commented 3 years ago

Ok, and finally what is the song you are using? I need this because I suspect the engine is having trouble with that specific song or case.

SimonIT commented 3 years ago

https://www.syair.info/lyrics/modjo/lady/Ykx5VQ https://www.megalobiz.com/lrc/maker/Beyonc%C3%A9+-+Single+Ladies+%28Put+a+Ring+on+It%29.54733707 These are the lyrics where the exceptions happen

reteps commented 3 years ago

I see.

https://www.syair.info/lyrics/modjo/lady/Ykx5VQ does not have valid LRC text.

See the LRC regex we match against:

line_regex = re.compile(r'\[(?:(\d+):)?(\d+)(?:\.(\d+))?\]([^\[]+)')

Normally we get matches like this: image

And what the lady modjo file looks like:

image

reteps commented 3 years ago

What do you think the library should do when it sees a Lyrics File like this and cannot parse it?

reteps commented 3 years ago

I think I could change the return cases of the providers from:

return Lyrics(full_text)

to

try:
   return Lyrics(full_text)
except InvalidLyricsException:
   return None
reteps commented 3 years ago

I will be able to implement that later this week.

SimonIT commented 3 years ago

I think that's valid. I had this already multiple times.

I handle this in https://github.com/doakey3/pylrc correct If you look here https://de.wikipedia.org/wiki/LRC_(Dateiformat)#Aufbau, it's also an example how to shorten lyrics with duplicate lines

reteps commented 3 years ago

Ok I can change the parsing later this week. Basically the tag processing and text processing will be split up then we have to sort the lyrics based on the time.

reteps commented 2 years ago

I no longer have time to fix this issue, but open to PRs! :)