Rigellute / spotify-tui

Spotify for the terminal written in Rust 🚀
MIT License
17.35k stars 518 forks source link

Command to save an album with CLI #788

Open nacht-falter opened 3 years ago

nacht-falter commented 3 years ago

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!

OrangeFran commented 3 years ago

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.

nacht-falter commented 3 years ago

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

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

OrangeFran commented 3 years ago

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

nacht-falter commented 2 years ago

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!

OrangeFran commented 2 years ago

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.