Repository: aome510/spotify-player (language: rust)

Issue:
error loading playlists without images 
**Describe the bug**
`images` can be `null` in some playlists. seems to be true for some old playlists, but also empty playlists

**To Reproduce**
1. Create an empty playlist.
2. Remove `Playlist_cache.json` 
3. Start `spotify_player`
4. Note empty playlists window

**Expected behaviour**
Playlists should load

**Log and backtrace**
Relevant log line

```2024-03-25T01:17:07.902710Z ERROR client_request{request=GetUserPlaylists}: spotify_player::client::handlers: Failed to handle client request: json parse error: invalid type: null, expected a sequence at line 1 column 392: invalid type: null, expected a sequence at line 1 column 392```

**Screenshots**
If applicable, add screenshots to help explain your problem.
![20240324_18h21m59s_grim](https://github.com/aome510/spotify-player/assets/868700/bc1a10b2-c662-41cc-a232-b66001a81e0d)


**Environment**

- OS: Arch
- Application version: 0.17.1

**Additional context**
example problematic json
```{"href":"https://api.spotify.com/v1/users/.../playlists?offset=0&limit=1","limit":1,"next":"https://api.spotify.com/v1/users/.../playlists?offset=1&limit=1","offset":0,"previous":null,"total":43,"items":[{"collaborative":false,"description":"","external_urls":{"spotify":"https://open.spotify.com/playlist/..."},"href":"https://api.spotify.com/v1/playlists/...","id":"...","images":null,"name":"My Playlist #26","owner":{"display_name":"...","external_urls":{"spotify":"https://open.spotify.com/user/..."},"href":"https://api.spotify.com/v1/users/...","id":"...","type":"user","uri":"spotify:user:..."},"primary_color":null,"public":true,"snapshot_id":"...","tracks":{"href":"https://api.spotify.com/v1/playlists/.../tracks","total":0},"type":"playlist","uri":"spotify:playlist:..."}]}```


Discussion / hints:

Fix patch:
diff --git a/.dir-locals.el b/.dir-locals.el
index 6bf7425e..c8fe8be5 100644
--- a/.dir-locals.el
+++ b/.dir-locals.el
@@ -1,4 +1,6 @@
 ;;; Directory Local Variables
 ;;; For more information see (info "(emacs) Directory Variables")
 
-((rustic-mode . ((lsp-rust-features . ["lyric-finder" "image" "notify" "clipboard"]))))
+((rustic-mode . ((eglot-workspace-configuration
+                  . (:rust-analyzer (:cargo (:features ["lyric-finder" "image" "notify" "clipboard"])
+                                     :check (:command "clippy")))))))
diff --git a/spotify_player/src/client/mod.rs b/spotify_player/src/client/mod.rs
index 4ff122c9..2765a0af 100644
--- a/spotify_player/src/client/mod.rs
+++ b/spotify_player/src/client/mod.rs
@@ -15,7 +15,7 @@ use librespot_connect::spirc::Spirc;
 use librespot_core::session::Session;
 use rspotify::{
     http::Query,
-    model::{FullPlaylist, Market},
+    model::{FullPlaylist, Market, Page, SimplifiedPlaylist},
     prelude::*,
 };
 
@@ -47,9 +47,7 @@ struct TrackData {
 const SPOTIFY_API_ENDPOINT: &str = "https://api.spotify.com/v1";
 
 fn market_query() -> Query<'static> {
-    let mut payload = Query::with_capacity(1);
-    payload.insert("market", "from_token");
-    payload
+    Query::from([("market", "from_token")])
 }
 
 impl Client {
@@ -678,10 +676,18 @@ impl Client {
 
     /// gets all playlists of the current user
     pub async fn current_user_playlists(&self) -> Result<Vec<Playlist>> {
+        // TODO: this should use `rspotify::current_user_playlists_manual` API instead of `internal_call`
+        // See: https://github.com/ramsayleung/rspotify/issues/459
         let first_page = self
-            .spotify
-            .current_user_playlists_manual(Some(50), None)
+            .internal_call::<Page<SimplifiedPlaylist>>(
+                &format!("{SPOTIFY_API_ENDPOINT}/me/playlists"),
+                &Query::from([("limit", "50")]),
+            )
             .await?;
+        // let first_page = self
+        //     .spotify
+        //     .current_user_playlists_manual(Some(50), None)
+        //     .await?;
 
         let playlists = self.all_paging_items(first_page, &Query::new()).await?;
         Ok(playlists.into_iter().map(|p| p.into()).collect())


Test patch: