elmoiv / azapi

Get Lyrics from AZLyrics.com like a Boss ~(0_0)~
GNU General Public License v3.0
121 stars 12 forks source link

[Solved] .getLyrics Errors #4

Closed VocAddict closed 4 years ago

VocAddict commented 4 years ago

Describe the bug

I've been having issues with this library I worked on implementing into phonetic-songs and at one point I thought it was the way I phrased the code but then as seen in the screenshot, the same piece of code gave two different outputs immediately after each other so I knew it wasn't from my side.

Along with AttributeError: 'NoneType' object has no attribute 'strip', I would get Exception('Artist or Title not found!'), TypeError: string indices must be integers, TypeError: write() argument must be str, not None and IndexError: list index out of range all with the same piece of code. Perhaps something to do with the way it is fetching the data from AZLyrics?

To Reproduce

Steps to reproduce the behavior:

api = AZlyrics()
search_terms = input('Enter lyrics: ')
songs = api.search(search_terms, category='songs')   
song_url = songs[0]['url']
artist_name = songs[0]['artist']
song_title = songs[0]['name']
lyrics = api.getLyrics(url = song_url, save=False).strip()
filename = (artist_name + ' - ' + song_title + '.txt')
if Path('in/').exists():
  basepath = Path('in/')
else:
  os.mkdir('in')
  if Path('in/').exists():
    basepath = Path('in/')
  with open(basepath/filename,'w', encoding='latin-1') as export:
    export.write(lyrics)
    export.close()
...

Would also get it with

api = AZlyrics()
artist_name = input('Type in the name of the artist: ')
song_title = input('Type in the title of the song: ')
lyrics = api.getLyrics(artist = artist_name, title = song_title, save=False).strip()
filename = (artist_name + ' - ' + song_title + '.txt')
if Path('in/').exists():
  basepath = Path('in/')
else:
  os.mkdir('in')
  if Path('in/').exists():
    basepath = Path('in/')
  with open(basepath/filename,'w', encoding='latin-1') as export:
    export.write(lyrics)
    export.close()
...

Expected behavior Lyrical output

Screenshots image

Desktop (please complete the following information):

Additional context A collection of the errors thrown with various songs/lyrics

elmoiv commented 4 years ago

I left this project since 2019. Thanks for opening this issue. I am working on overall improvements on this project. Stay sharp!

elmoiv commented 4 years ago

Finally finished my exams. I am re-implementing the whole API with a lot of fixes and improvements.

Patience is a virtue

elmoiv commented 4 years ago

Hey @VocAddict , I just published my new polished version. Go check it out. If your issues got solved, please close this issue. If not, show me a trace of your bugs and I will do my best to solve them.

VocAddict commented 4 years ago

Hey! Thanks for the update, the aritst + title feature works like a charm (just need to modify my script to not try to write when it gets a 404 error on a search) but the removal of the search via lyrics feature is a bit of a drag. I don't know if I'm missing something but it doesn't seem like there's an alternative for it?

elmoiv commented 4 years ago

The previous search feature was not for lyrics. I think you used it incorrectly. It was for songs titles, artist and albums but not for lyrics.

With the new update you can now use search engines to get accurate results. You can even search with title only and get the corresponding song under the entered jaro accuracy.

I will put Searching by Lyrics in my future #TODO list :)

If your issue is solved, kindly close this issue.

elmoiv commented 4 years ago

Hey, I just found a workaround to search by lyrics.

from azapi import AZlyrics
API = AZlyrics('google', 0.001)
# This is from Bebe Rexha - In The Name of Love
API.title = 'If I told you this was only gonna hurt'
API.getLyrics()

Output:

"If I told you this was only gonna hurt\nIf I warned you that the fire's gonna burn\nWould you walk in? Would you let me do it first?\nDo it all in the name of love\nWould you let me lead you even when you're blind?\nIn the darkness, in the middle of the night\nIn the silence, when there's no one by your side\nWould you call in the name of love?\n\nIn the name of love, name of love\nIn the name of love, name of love\n\nIn the name of\nLove\nIn the name, name\nLove\nIn the name, name\nLove\n\nIf I told you we could bathe in all the lights\nWould you rise up, come and meet me in the sky?\nWould you trust me when you're jumping from the heights?\nWould you fall in the name of love?\nWhen there's madness, when there's poison in your head\nWhen the sadness leaves you broken in your bed\nI will hold you in the depths of your despair\nAnd it's all in the name of love\n\nIn the name of love, name of love\nIn the name of love, name of love\n\nIn the name of\nLove\nIn the name, name\nLove\nIn the name, name\nLove\n\nI wanna testify\nScream in the holy light\nYou bring me back to life\nAnd it's all in the name of love\nI wanna testify\nScream in the holy light\nYou bring me back to life\nAnd it's all in the name of love\n\nIn the name of love, name of love\nIn the name of love, name of love\n\nIn the name of\nLove\nIn the name, name\nLove\nIn the name, name\nLove\nIn the name of\nLove\nIn the name, name\nLove\nIn the name of\nLove\nIn the name of\nLove\nIn the name of\nLove"
VocAddict commented 4 years ago

Great, yeah this works. Thanks a lot!