hrkfdn / ncspot

Cross-platform ncurses Spotify client written in Rust, inspired by ncmpc and the likes.
BSD 2-Clause "Simplified" License
4.79k stars 206 forks source link

Crash when trying to load deleted(?) song #1467

Open PedroMAdorno4 opened 3 weeks ago

PedroMAdorno4 commented 3 weeks ago

Describe the bug So, as we all know, a "Discover Weekly" playlist is made (or updated, idk) every week. My problem is, when I was trying to play it, the program crashed. The issue is there is a song in that playlist that I assume existed when the playlist was created, but then the song was deleted for some reason. Ncspot doesn't account for that, and tries to play it, thus crashing the application.

Maybe it is the playing that causes the issue, but from the backtrace I feel like it is an UI error because it tries to set the current length that was played from the song, but since it doesn't exist, Spotify's API returns a zero. But I feel like the solution should not just be guarding against that, but just to skip songs that have a 0 length (or not even trying to play them).

To Reproduce I tried reproducing with local files, but to no avail. If it's possible to access the playlist by id without authenticating as me, or adding the offending song (from the logs) to an existing playlist would be best, but otherwise I really have no ideas here.

Expected behavior I would expect the application to skip or ignore songs that no longer exist on the platform, or that have no valid reference to (thinking about local files).

Screenshots

Official spotify client image

Ncspot image

System (please complete the following information):

Backtrace/Debug log

Backtrace log

Empty spaces after the lines are 'unknown' elements

   0: 
   1: 
   2: 
   3: 
   4: 
   5: 
   6: 
   7: 
   8: 
   9: 
  10: 
  11: 
  12: 
  13: main
  14: 
  15: __libc_start_main
  16: 

panicked at src/ui/statusbar.rs:194:21:
attempt to divide by zero
Details
[2024-06-14][21:49:55] [ureq::pool] [DEBUG] pulling stream from pool: https|api.spotify.com|443 -> Stream(RustlsStream)
[2024-06-14][21:49:55] [ureq::unit] [DEBUG] sending request (reused connection) GET https://api.spotify.com/v1/playlists/2KnF9S8AQ9bNsBmzQmnqsJ/tracks?market=from_token&limit=100&offset=100
[2024-06-14][21:49:55] [ureq::unit] [DEBUG] writing prelude: GET /v1/playlists/2KnF9S8AQ9bNsBmzQmnqsJ/tracks?market=from_token&limit=100&offset=100 HTTP/1.1
Host: api.spotify.com
User-Agent: ureq/2.9.1
Accept: */*
authorization: ***
[2024-06-14][21:49:55] [cursive_buffered_backend] [DEBUG] output_all_to_backend started
[2024-06-14][21:49:55] [cursive_buffered_backend] [DEBUG] output_all_to_backend finished
[2024-06-14][21:49:55] [ureq::response] [DEBUG] Streaming body until content-length: 184698
[2024-06-14][21:49:55] [ureq::unit] [DEBUG] response 200 to GET https://api.spotify.com/v1/playlists/2KnF9S8AQ9bNsBmzQmnqsJ/tracks?market=from_token&limit=100&offset=100
[2024-06-14][21:49:55] [ureq::pool] [DEBUG] adding stream to pool: https|api.spotify.com|443 -> Stream(RustlsStream)
[2024-06-14][21:49:55] [ncspot::ui::pagination] [DEBUG] fetching next page at offset 50
[2024-06-14][21:49:55] [ncspot::ui::pagination] [DEBUG] paginator is at end
[2024-06-14][21:49:55] [cursive_buffered_backend] [DEBUG] output_all_to_backend started
[2024-06-14][21:49:55] [cursive_buffered_backend] [DEBUG] output_all_to_backend finished
[2024-06-14][21:49:55] [cursive_buffered_backend] [DEBUG] output_all_to_backend started
[2024-06-14][21:49:55] [cursive_buffered_backend] [DEBUG] output_all_to_backend finished
[2024-06-14][21:49:56] [cursive_buffered_backend] [DEBUG] output_all_to_backend started
[2024-06-14][21:49:56] [cursive_buffered_backend] [DEBUG] output_all_to_backend finished
[2024-06-14][21:49:56] [cursive_buffered_backend] [DEBUG] output_all_to_backend started
[2024-06-14][21:49:56] [cursive_buffered_backend] [DEBUG] output_all_to_backend finished
[2024-06-14][21:49:56] [cursive_buffered_backend] [DEBUG] output_all_to_backend started
[2024-06-14][21:49:56] [cursive_buffered_backend] [DEBUG] output_all_to_backend finished
[2024-06-14][21:49:57] [cursive_buffered_backend] [DEBUG] output_all_to_backend started
[2024-06-14][21:49:57] [cursive_buffered_backend] [DEBUG] output_all_to_backend finished
[2024-06-14][21:49:57] [cursive_buffered_backend] [DEBUG] output_all_to_backend started
[2024-06-14][21:49:57] [cursive_buffered_backend] [DEBUG] output_all_to_backend finished
[2024-06-14][21:49:57] [cursive_buffered_backend] [DEBUG] output_all_to_backend started
[2024-06-14][21:49:57] [cursive_buffered_backend] [DEBUG] output_all_to_backend finished
[2024-06-14][21:49:58] [cursive_buffered_backend] [DEBUG] output_all_to_backend started
[2024-06-14][21:49:58] [cursive_buffered_backend] [DEBUG] output_all_to_backend finished
[2024-06-14][21:49:58] [cursive_buffered_backend] [DEBUG] output_all_to_backend started
[2024-06-14][21:49:58] [cursive_buffered_backend] [DEBUG] output_all_to_backend finished
[2024-06-14][21:49:59] [cursive_buffered_backend] [DEBUG] output_all_to_backend started
[2024-06-14][21:49:59] [cursive_buffered_backend] [DEBUG] output_all_to_backend finished
[2024-06-14][21:49:59] [cursive_buffered_backend] [DEBUG] output_all_to_backend started
[2024-06-14][21:49:59] [cursive_buffered_backend] [DEBUG] output_all_to_backend finished
[2024-06-14][21:49:59] [cursive_buffered_backend] [DEBUG] output_all_to_backend started
[2024-06-14][21:49:59] [cursive_buffered_backend] [DEBUG] output_all_to_backend finished
[2024-06-14][21:50:00] [cursive_buffered_backend] [DEBUG] output_all_to_backend started
[2024-06-14][21:50:00] [cursive_buffered_backend] [DEBUG] output_all_to_backend finished
[2024-06-14][21:50:00] [ncspot::spotify] [INFO] loading track: Track(Track { id: Some("5vCREmODQpdzOmcNOVsN6B"), uri: "spotify:track:5vCREmODQpdzOmcNOVsN6B", title: "", track_number: 2, disc_number: 1, duration: 0, artists: [""], artist_ids: ["0LyfQWJT6nXafLPZqxe9Of"], album: Some(""), album_id: Some("2rYTypyWXb39mGLdWKV7jA"), album_artists: ["Various Artists"], cover_url: None, url: "https://open.spotify.com/track/5vCREmODQpdzOmcNOVsN6B", added_at: Some(2024-06-10T03:00:00Z), list_index: 1, is_local: false, is_playable: Some(false) })
[2024-06-14][21:50:00] [ncspot::spotify] [INFO] sending command to worker: Load(Track(Track { id: Some("5vCREmODQpdzOmcNOVsN6B"), uri: "spotify:track:5vCREmODQpdzOmcNOVsN6B", title: "", track_number: 2, disc_number: 1, duration: 0, artists: [""], artist_ids: ["0LyfQWJT6nXafLPZqxe9Of"], album: Some(""), album_id: Some("2rYTypyWXb39mGLdWKV7jA"), album_artists: ["Various Artists"], cover_url: None, url: "https://open.spotify.com/track/5vCREmODQpdzOmcNOVsN6B", added_at: Some(2024-06-10T03:00:00Z), list_index: 1, is_local: false, is_playable: Some(false) }), true, 0)
[2024-06-14][21:50:00] [ncspot::spotify_worker] [INFO] player loading track: SpotifyId { id: 240649963210410953864476784835881438733, audio_type: Track }
[2024-06-14][21:50:00] [librespot_playback::player] [DEBUG] command=Load(SpotifyId { id: 240649963210410953864476784835881438733, audio_type: Track }, true, 0)
[2024-06-14][21:50:00] [librespot_playback::player] [TRACE] == Stopping sink ==
[2024-06-14][21:50:00] [ncspot::ipc] [INFO] removed socket at "/run/user/1000/ncspot/ncspot.sock"
hrkfdn commented 1 week ago

Could you link that playlist? I looked at https://open.spotify.com/playlist/2KnF9S8AQ9bNsBmzQmnqsJ (as indicated in the logs) but it seems to be a different one?

EDIT: Ah, the dynamic "Discover Weekly" has probably been refreshed now.. :disappointed:

julianjarjour commented 1 week ago

This also occurs with a blank artist at the top of my menu: image

PedroMAdorno4 commented 6 days ago

Could you link that playlist? I looked at https://open.spotify.com/playlist/2KnF9S8AQ9bNsBmzQmnqsJ (as indicated in the logs) but it seems to be a different one?

EDIT: Ah, the dynamic "Discover Weekly" has probably been refreshed now.. 😞

Yes, its a dynamic one. I could try to create one and wait for it to have a song deleted, but it would really be a shot in the dark. Can't it be reproduced with automated tests? If I can get you a response from spotify API that has a deleted song in it, could that be enough to push a fix? I could try to work something out, otherwise it will just be a waiting game

PedroMAdorno4 commented 6 days ago

I will try to add an already deleted track to a test playlist via the API. Since the song still exists and still has metadata (title, author, etc), it must still have an ID. It will just be a matter if spotify allows that operation or not.