[GH-ISSUE #788] Command to save an album with CLI #319

Open
opened 2026-02-28 14:48:29 +03:00 by kerem · 5 comments
Owner

Originally created by @nacht-falter on GitHub (Apr 16, 2021).
Original GitHub issue: https://github.com/Rigellute/spotify-tui/issues/788

Hi,
thank you for freeing me from that cumbersome official Spotify Client!

Is there a way to save an album to the library from the command line (without entering the UI)? Ideally I would like to play an album and if at some point I decide I like it save it to the library.

Thanks!

Originally created by @nacht-falter on GitHub (Apr 16, 2021). Original GitHub issue: https://github.com/Rigellute/spotify-tui/issues/788 Hi, thank you for freeing me from that cumbersome official Spotify Client! Is there a way to save an album to the library from the command line (without entering the UI)? Ideally I would like to play an album and if at some point I decide I like it save it to the library. Thanks!
Author
Owner

@OrangeFran commented on GitHub (Apr 18, 2021):

Not yet but it would be pretty easy to implement a spt playback --save-album command. It's just a call to IoEvent::CurrentUserSavedAlbumAdd(String). If you want to do it yourself, go for it.

<!-- gh-comment-id:821957349 --> @OrangeFran commented on GitHub (Apr 18, 2021): Not yet but it would be pretty easy to implement a `spt playback --save-album` command. It's just a call to `IoEvent::CurrentUserSavedAlbumAdd(String)`. If you want to do it yourself, go for it.
Author
Owner

@nacht-falter commented on GitHub (Apr 19, 2021):

If you want to do it yourself, go for it.

I'd love to but I wouldn't know how, sorry.

<!-- gh-comment-id:822400417 --> @nacht-falter commented on GitHub (Apr 19, 2021): > If you want to do it yourself, go for it. I'd love to but I wouldn't know how, sorry.
Author
Owner

@OrangeFran commented on GitHub (Apr 19, 2021):

No worries, maybe I'll find some time this week to do it myself.

<!-- gh-comment-id:822438150 --> @OrangeFran commented on GitHub (Apr 19, 2021): No worries, maybe I'll find some time this week to do it myself.
Author
Owner

@nacht-falter commented on GitHub (Sep 21, 2022):

No worries, maybe I'll find some time this week to do it myself.

Hi,
did you ever get around to taking a look at this?
If not, could you point me in the right direction towards implementing it myself? I don't know where to start.
Cheers!

<!-- gh-comment-id:1253453807 --> @nacht-falter commented on GitHub (Sep 21, 2022): > No worries, maybe I'll find some time this week to do it myself. Hi, did you ever get around to taking a look at this? If not, could you point me in the right direction towards implementing it myself? I don't know where to start. Cheers!
Author
Owner

@OrangeFran commented on GitHub (Sep 21, 2022):

Hey, maybe use this as a starting point (used to like a song):

        // Get the id of the current song
        let id = match c.item {
          Some(i) => match i {
            PlayingItem::Track(t) => t.id.ok_or_else(|| anyhow!("item has no id")),
            PlayingItem::Episode(_) => Err(anyhow!("saving episodes not yet implemented")),
          },
          None => Err(anyhow!("no item playing")),
        }?;

        // Want to like but is already liked -> do nothing
        // Want to like and is not liked yet -> like
        if s && !self.is_a_saved_track(&id).await {
          self
            .net
            .handle_network_event(IoEvent::ToggleSaveTrack(id))
            .await;
        // Want to dislike but is already disliked -> do nothing
        // Want to dislike and is liked currently -> remove like
        } else if !s && self.is_a_saved_track(&id).await {
          self
            .net
            .handle_network_event(IoEvent::ToggleSaveTrack(id))
            .await;
        }

The variable s is a bool and reflects if the song should be liked (true) or disliked (false).

Use something like this to check for the command line flag:

      if let Some(vol) = matches.value_of("volume") {
        cli.volume(vol.to_string()).await?;
      }

And make sure to enable the flag by adding to src/cli/clap.rs.
Hope this helps.

<!-- gh-comment-id:1253760888 --> @OrangeFran commented on GitHub (Sep 21, 2022): Hey, maybe use this as a starting point (used to like a song): ``` rust // Get the id of the current song let id = match c.item { Some(i) => match i { PlayingItem::Track(t) => t.id.ok_or_else(|| anyhow!("item has no id")), PlayingItem::Episode(_) => Err(anyhow!("saving episodes not yet implemented")), }, None => Err(anyhow!("no item playing")), }?; // Want to like but is already liked -> do nothing // Want to like and is not liked yet -> like if s && !self.is_a_saved_track(&id).await { self .net .handle_network_event(IoEvent::ToggleSaveTrack(id)) .await; // Want to dislike but is already disliked -> do nothing // Want to dislike and is liked currently -> remove like } else if !s && self.is_a_saved_track(&id).await { self .net .handle_network_event(IoEvent::ToggleSaveTrack(id)) .await; } ``` The variable `s` is a bool and reflects if the song should be liked (true) or disliked (false). Use something like this to check for the command line flag: ``` rust if let Some(vol) = matches.value_of("volume") { cli.volume(vol.to_string()).await?; } ``` And make sure to enable the flag by adding to `src/cli/clap.rs`. Hope this helps.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/spotify-tui#319
No description provided.