danguilherme / spotivy

:musical_score: Download music videos from Spotify playlists
https://danguilherme.github.io/blog/spotivy
MIT License
85 stars 11 forks source link

Fix app crashes if media was not found on YouTube #10

Closed lnfnunes closed 6 years ago

lnfnunes commented 6 years ago

This PR fixes issue #9

Result: image

lnfnunes commented 6 years ago

@danguilherme please check again!

danguilherme commented 6 years ago

That's very odd, but I'm trying to reproduce the issue now (in the develop branch first), and it always returns results from the YouTube search, thus not causing the original error.

I'm running:

$ node index.js playlist "Bostjan Bele" 37i9dQZF1DWTvNyxOwkztu --verbose # running locally
[spotivy v0.4.3]
                  [DEBUG] Loaded options:
 {
  "spotifyClientId": "xxx",
  "spotifyClientSecret": "xxx",
  "youtubeKey": "xxx",
  "output": "/home/danguilherme/git/danguilherme/spotivy/media",
  "format": "video",
  "quality": "highest",
  "flat": false,
  "audio": false,
  "username": "Bostjan Bele",
  "playlists": [
    "37i9dQZF1DWTvNyxOwkztu"
  ]
}
Saving media to '/home/danguilherme/git/danguilherme/spotivy/media'

                  [DEBUG] Spotify login
   [Downloading playlist] Chillout Lounge
                  [DEBUG] Fetching playlist tracks (37i9dQZF1DWTvNyxOwkztu)
                  [DEBUG] Fetch paginated: "getPlaylistTracks"
                  [DEBUG] Fetch paginated: loading 0..20
                  [DEBUG] Fetch paginated: loaded  20/90
                  [DEBUG] Fetch paginated: pushing down the stream
      [Downloading track] Daxten - Late Nights
                  [DEBUG] Search video: search "Daxten - Late Nights"
                  [DEBUG] Fetch paginated: next page
                  [DEBUG] Search video: 20 item(s) returned # <---- HERE - in yours, it doesn't return anything
                  [DEBUG] Search music video: None of the videos is considered a good result
                  [DEBUG] Search music video: selected "Daxten - Late Nights", by Stackin' Records
                  [DEBUG] Download from: https://www.youtube.com/watch?v=WjeZjeM0liY
                  [DEBUG] Download to  : /home/danguilherme/git/danguilherme/spotivy/media/Chillout Lounge/Daxten - Late Nights.mp4
                  [DEBUG] Finish write: Daxten - Late Nights
... continues ...

Do you have any idea on why this happens?

lnfnunes commented 6 years ago

Hummm... think I got it! image

This don't mean shouldn't download the video/audio, this only says no "good" result was found and the first one will be downloaded...

So, the bug (issue) is when the function searchVideo returns an empty array!

To simulate the bug, change line 31 resolve(results.items); to resolve([]);

My test case was wrong in the first... fixed now with an update. image

lnfnunes commented 6 years ago

Hey, @danguilherme could you test it again? If you find anything else please let me know

danguilherme commented 6 years ago

Sounds great, thanks!