fm16191 / spotify-recorder

Recorder for Spotify. Not a YouTube downloader !!!
30 stars 6 forks source link

Heroku not returning valid JSON crashes the application. #9

Closed ch-morpurgo closed 8 months ago

ch-morpurgo commented 8 months ago

Hello there, and thanks for the time you have invested.

I cloned the repository just today and followed the installation process.

If I ran the application, it was working nicely, until the point where add_lyrics tried to talk to heroku to get json for the lyrics. If heroku returns non-valid json (for example if it simply is a 404 request) the application crashes. To avoid that, I updated the add_lyrics method to include a simple try catch block and print the exception to the terminal.

Because I do not have the possibility to upload a branch with my fix, here is the change I made to the api.py

# api.py: commit 66e855a at line 297
url = f"https://spotify-lyric-api.herokuapp.com/?trackid={track_id}&format=lrc"
        res = requests.get(url)
        if res.status_code == 200 and res.headers.get('Content-Type') == 'application/json':
            try:
                lrc_lyrics = res.json()
            except ValueError as e:
                DERROR(f"Invalid JSON response: {res.text}")
                return
        else:
            DERROR(f"Failed to get lyrics. Status: {res.status_code}, Content-Type: {res.headers.get('Content-Type')}, Response: {res.text}")
            return

This results in the continuation of the application if, for example, a playlist is to be recorded.

Example output:

[+] File saved at songs/747uuGEtwq0i0R05VVWxvd/Liftoff_-_Reel_Waves.mp3
[2023 Nov.08 14:16:04] Failed to get lyrics. Status: 404, Content-Type: text/html; charset=utf-8, Response: <!DOCTYPE html>
<html>
  <head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta charset="utf-8">
    <title>Heroku | Application Error</title>
    <style media="screen">
      html,body,iframe {
        margin: 0;
        padding: 0;
      }
      html,body {
        height: 100%;
        overflow: hidden;
      }
      iframe {
        width: 100%;
        height: 100%;
        border: 0;
      }
    </style>
  </head>
  <body>
    <iframe src="//www.herokucdn.com/error-pages/no-such-app.html"></iframe>
  </body>
</html>

There probably is a solution to fix the heroku URL, but I am not interested in the lyrics at all and thought this might help someone who has trouble getting it working.

fm16191 commented 8 months ago

Hi, and thank you for your interest in the app !

It appears that the Heroku app is down and that case was not handled... no unit tests, mb! Until fixing the underlying issue, I'll push your fixes, thank you !

Also, since you are not interested in lyrics at all, you may want to consider the --lyrics-mode=none option that suits your case :) Lyrics are added by default unless otherwise specified.