[GH-ISSUE #16] Implement methods to control playback #15

Closed
opened 2026-02-28 14:46:21 +03:00 by kerem · 11 comments
Owner

Originally created by @Ciavarella on GitHub (Oct 7, 2019).
Original GitHub issue: https://github.com/Rigellute/spotify-tui/issues/16

Would be awsome if you could add next and previous track.

I know that there is some issues with:
"The auth token does not currently automatically refresh - when you leave spotify-tui running for a while, you won't be able to control playback. And you'll need to quit and restart to get it working again."

I had the same issue, i checked if the current token is valid. You could probably do this in a nicer way but when a user signs in the first time you get:

{
 "access_token" : "NgAagA...Um_SHo",
 "expires_in" : "3600",
 "refresh_token" : "NgCXRK...MzYjw"
}

The expires_in tells you when the access_token expires. You can use it to decide when to get a new access_token. Then use the refresh_token to get a new access_token.

You can renew the access_token by using a refresh_token. This token is provided to you when you first make the request to authenticate the user. You should save that refresh_token if you don't already do so. The refresh_token is valid forever but you can't control playback with the refresh_token.

To get a new access_token with the refresh_token: (JavaScript)

    const res = await fetch(
      `${this.baseUrl}/auth/refresh_token?refresh_token=${refreshKey}`,
      {
        method: 'GET'
      }
    );

You will then get a new access_token that you can use to control playback.

Documentation from Spotify on how to use the refresh_token to access a new access_token.

https://developer.spotify.com/documentation/ios/guides/token-swap-and-refresh/

btw, love what you have made! Great work!

Originally created by @Ciavarella on GitHub (Oct 7, 2019). Original GitHub issue: https://github.com/Rigellute/spotify-tui/issues/16 Would be awsome if you could add next and previous track. I know that there is some issues with: "The auth token does not currently automatically refresh - when you leave spotify-tui running for a while, you won't be able to control playback. And you'll need to quit and restart to get it working again." I had the same issue, i checked if the current token is valid. You could probably do this in a nicer way but when a user signs in the first time you get: ``` { "access_token" : "NgAagA...Um_SHo", "expires_in" : "3600", "refresh_token" : "NgCXRK...MzYjw" } ``` The expires_in tells you when the access_token expires. You can use it to decide when to get a new access_token. Then use the refresh_token to get a new access_token. You can renew the access_token by using a refresh_token. This token is provided to you when you first make the request to authenticate the user. You should save that refresh_token if you don't already do so. The refresh_token is valid forever but you can't control playback with the refresh_token. To get a new access_token with the refresh_token: (JavaScript) ``` const res = await fetch( `${this.baseUrl}/auth/refresh_token?refresh_token=${refreshKey}`, { method: 'GET' } ); ``` You will then get a new access_token that you can use to control playback. Documentation from Spotify on how to use the refresh_token to access a new access_token. https://developer.spotify.com/documentation/ios/guides/token-swap-and-refresh/ btw, love what you have made! Great work!
kerem closed this issue 2026-02-28 14:46:21 +03:00
Author
Owner

@jq-rs commented on GitHub (Oct 8, 2019):

Yes, next and previous song keyboard shortcuts would be awesome!

<!-- gh-comment-id:539318279 --> @jq-rs commented on GitHub (Oct 8, 2019): Yes, next and previous song keyboard shortcuts would be awesome!
Author
Owner

@Rigellute commented on GitHub (Oct 8, 2019):

I absolutely need to implement this.

In keeping with vim style key bindings, which do you think would work best?

  1. ; for next and , for previous
  2. n for next and N for previous

If you have any preferences, let me know!

<!-- gh-comment-id:539403337 --> @Rigellute commented on GitHub (Oct 8, 2019): I absolutely need to implement this. In keeping with vim style key bindings, which do you think would work best? 1. `;` for next and `,` for previous 1. `n` for next and `N` for previous If you have any preferences, let me know!
Author
Owner

@Rigellute commented on GitHub (Oct 8, 2019):

And regarding implementing auto refresh of tokens, I have a plan for it.

<!-- gh-comment-id:539403582 --> @Rigellute commented on GitHub (Oct 8, 2019): And regarding implementing auto refresh of tokens, I have a plan for it.
Author
Owner

@tommilligan commented on GitHub (Oct 8, 2019):

Would like to help with this, I can either dive in or you can let me know when you have specific tasks that need doing.

My vote would be for n and N for playback bindings

<!-- gh-comment-id:539430850 --> @tommilligan commented on GitHub (Oct 8, 2019): Would like to help with this, I can either dive in or you can let me know when you have specific tasks that need doing. My vote would be for `n` and `N` for playback bindings
Author
Owner

@Ciavarella commented on GitHub (Oct 8, 2019):

I absolutely need to implement this.

In keeping with vim style key bindings, which do you think would work best?

  1. ; for next and , for previous
  2. n for next and N for previous

If you have any preferences, let me know!

I would go with 2. n for next and N for previous.
Or why not n for next and p for previous? Im not really a fan of uppercase commands.

Github uses n and p
Screenshot 2019-10-08 at 11 41 20

<!-- gh-comment-id:539435580 --> @Ciavarella commented on GitHub (Oct 8, 2019): > I absolutely need to implement this. > > In keeping with vim style key bindings, which do you think would work best? > > 1. `;` for next and `,` for previous > 2. `n` for next and `N` for previous > > If you have any preferences, let me know! I would go with 2. `n` for next and `N` for previous. Or why not `n` for next and `p` for previous? Im not really a fan of uppercase commands. Github uses `n` and `p` <img width="500" alt="Screenshot 2019-10-08 at 11 41 20" src="https://user-images.githubusercontent.com/31614316/66385340-9f78d680-e9c0-11e9-8ac1-25cfbee08800.png">
Author
Owner

@gallagth commented on GitHub (Oct 8, 2019):

Following this, another vote for n and p!

<!-- gh-comment-id:539441423 --> @gallagth commented on GitHub (Oct 8, 2019): Following this, another vote for `n` and `p`!
Author
Owner

@jq-rs commented on GitHub (Oct 8, 2019):

Another vote for n and p.

These are the Github peer review shortcuts too, so many of us know them by heart. As @Ciavarella already mentions.

<!-- gh-comment-id:539455000 --> @jq-rs commented on GitHub (Oct 8, 2019): Another vote for `n` and `p`. These are the Github peer review shortcuts too, so many of us know them by heart. As @Ciavarella already mentions.
Author
Owner

@ohhskar commented on GitHub (Oct 9, 2019):

I vote for n and N in keeping with vim style bindings.

<!-- gh-comment-id:539988550 --> @ohhskar commented on GitHub (Oct 9, 2019): I vote for `n` and `N` in keeping with vim style bindings.
Author
Owner

@Rigellute commented on GitHub (Oct 9, 2019):

Token refresh has now been implemented! github.com/Rigellute/spotify-tui@df34c32143

Will be available in the next release.

Huge thanks to @fangyi-zhou

<!-- gh-comment-id:540040164 --> @Rigellute commented on GitHub (Oct 9, 2019): Token refresh has now been implemented! https://github.com/Rigellute/spotify-tui/commit/df34c321439bfb82af093c5010b7ec94e255f3c7 Will be available in the next release. Huge thanks to @fangyi-zhou
Author
Owner

@jq-rs commented on GitHub (Oct 10, 2019):

I am now missing also volume controls..

Token refresh and repeat works great!

<!-- gh-comment-id:540469620 --> @jq-rs commented on GitHub (Oct 10, 2019): I am now missing also volume controls.. Token refresh and repeat works great!
Author
Owner

@Rigellute commented on GitHub (Oct 13, 2019):

Playback controls update:

I'm going to close this issue and reopen one for controlling volume.

<!-- gh-comment-id:541410678 --> @Rigellute commented on GitHub (Oct 13, 2019): Playback controls update: - @samcal has implemented skipping tracks https://github.com/Rigellute/spotify-tui/pull/51 - PR here implementing seek functionality https://github.com/Rigellute/spotify-tui/pull/56 I'm going to close this issue and reopen one for controlling volume.
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#15
No description provided.