gotify

package module
v0.0.0-...-003c453 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 26, 2025 License: MIT Imports: 26 Imported by: 0

README

Gotify

This module aims to implement Spotify Web API bindings in an easy and simple while keeping advanced control possible.

The documentation from Spotify Web API can be referenced for the base implementation.

Next to the base implementation some helper function are present for easier use.
For all helper functions please refer to the files in the top level directory of this project.

Note that most of this project is untested, as such not all functions might not work as expected.
Do you're own testing and see if the functionality you need actually works.

Usage

Creating a GotifyPlayer for controlling a Spotify session can be done with this method:

gp := gotify.NewGotifyPlayer(
    "ClientID",                         // Use the ClientID of you're application.
    "http://127.0.0.1"                  // Use the redirect URL of you're application.
    gotify.ScopeUserModifyPlaybackState // Add all scopes you're application will use.
)

Authentication might be required depending on the functions you're applications will use. During authentication the user is directed to Spotify for oauth2 authentication, after this the user is redirected to the redirect URL. Authenticating the GotifyPlayer can be done by any of these methods:

err := gp.AuthenticateHTTP(5050)   // Listen on the given port at uri /spotify_auth_callback for http calls, redirect URL should point here.
err := gp.AuthenticateStdin()      // Listen on stdin, user should manualy paste the post authentication URL here.
err := gp.AuthenticateToken(token) // Authenticate using oauth2 token.

// Get current oauth2 token, this token can be stored and used later for authentication.
//
// Note that while the client is active the token will automatically be refreshed, changing the token in the process.
token, err := gp.Token()

After a GotifyPlayer is successfully created and authenticated the associated Spotify session can be controlled.
This can be done using either the Spotify references (base implementation) or the helpers.

The available Spotify references are:

Examples

Some examples for controlling a Spotify session using the Spotify references:

_ = gp.Albums.TODO() // TODO
_ = gp.Artists.TODO() // TODO
_ = gp.Audiobooks.TODO() // TODO
_ = gp.Categories.TODO() // TODO
_ = gp.Chapters.TODO() // TODO
_ = gp.Episodes.TODO() // TODO
_ = gp.Genres.TODO() // TODO
_ = gp.Markets.TODO() // TODO
_ = gp.Player.TODO() // TODO
_ = gp.Playlists.TODO() // TODO
_ = gp.Search.TODO() // TODO
_ = gp.Shows.TODO() // TODO
_ = gp.Tracks.TODO() // TODO
_ = gp.Users.TODO() // TODO

Some examples for controlling a Spotify session using the helpers:

// TODO

Structure

This project is structured as follows:

  • Gotify (/gotify.go; Entrypoint and main functions to get started)
  • lib (/lib/lib.go; Contains functions and variables that are used throughout the project)
  • Spotify References (/*/*.go; Implements base as documented in Spotify Web API)
  • Sonos Reference Helpers (Ex: /*.go; Build upon the base implementation for easier use)

Documentation

Index

Constants

View Source
const (
	RepeatTrack   = lib.RepeatTrack
	RepeatContext = lib.RepeatContext
	RepeatOff     = lib.RepeatOff

	TimeRangeLongTerm   = lib.TimeRangeLongTerm
	TimeRangeMediumTerm = lib.TimeRangeMediumTerm
	TimeRangeShortTerm  = lib.TimeRangeShortTerm
)
View Source
const (
	ScopeUgcImageUpload            scope = "ugc-image-upload"            // Write access to user-provided images.
	ScopeUserReadPlaybackState     scope = "user-read-playback-state"    // Read access to a user’s player state.
	ScopeUserModifyPlaybackState   scope = "user-modify-playback-state"  // Write access to a user’s playback state
	ScopeUserReadCurrentlyPlaying  scope = "user-read-currently-playing" // Read access to a user’s currently playing content.
	ScopeAppRemoteControl          scope = "app-remote-control"          // Remote control playback of Spotify. This scope is currently available to Spotify iOS and Android SDKs.
	ScopeStreaming                 scope = "streaming"                   // Control playback of a Spotify track. This scope is currently available to the Web Playback SDK. The user must have a Spotify Premium account.
	ScopePlaylistReadPrivate       scope = "playlist-read-private"       // Read access to user's private playlists.
	ScopePlaylistReadCollaborative scope = "playlist-read-collaborative" // Include collaborative playlists when requesting a user's playlists.
	ScopePlaylistModifyPrivate     scope = "playlist-modify-private"     // Write access to a user's private playlists.
	ScopePlaylistModifyPublic      scope = "playlist-modify-public"      // Write access to a user's public playlists.
	ScopeUserFollowModify          scope = "user-follow-modify"          // Write/delete access to the list of artists and other users that the user follows.
	ScopeUserFollowRead            scope = "user-follow-read"            // Read access to the list of artists and other users that the user follows.
	ScopeUserReadPlaybackPosition  scope = "user-read-playback-position" // Read access to a user’s playback position in a content.
	ScopeUserTopRead               scope = "user-top-read"               // Read access to a user's top artists and tracks.
	ScopeUserReadRecentlyPlayed    scope = "user-read-recently-played"   // Read access to a user’s recently played tracks.
	ScopeUserLibraryModify         scope = "user-library-modify"         // Write/delete access to a user's "Your Music" library.
	ScopeUserLibraryRead           scope = "user-library-read"           // Read access to a user's library.
	ScopeUserReadEmail             scope = "user-read-email"             // Read access to user’s email address.
	ScopeUserReadPrivate           scope = "user-read-private"           // Read access to user’s subscription details (type of user account).
	ScopeUserPersonalized          scope = "user-personalized"           // Get personalized content for the user.
	ScopeUserSoaLink               scope = "user-soa-link"               // Link a partner user account to a Spotify user account
	ScopeUserSoaUnlink             scope = "user-soa-unlink"             // Unlink a partner user account from a Spotify account
	ScopeSoaManageEntitlements     scope = "soa-manage-entitlements"     // Modify entitlements for linked users
	ScopeSoaManagePartner          scope = "soa-manage-partner"          // Update partner information
	ScopeSoaCreatePartner          scope = "soa-create-partner"          // Create new partners, platform partners only
)

Variables

This section is empty.

Functions

This section is empty.

Types

type GotifyPlayer

type GotifyPlayer struct {
	URL string

	Albums     albums.Albums
	Artists    artists.Artists
	Audiobooks audiobooks.Audiobooks
	Categories categories.Categories
	Chapters   chapters.Chapters
	Episodes   episodes.Episodes
	Markets    markets.Markets
	Player     player.Player
	Playlists  playlists.Playlists
	Search     search.Search
	// Shows      shows.Shows
	Tracks tracks.Tracks
	Users  users.Users
	// contains filtered or unexported fields
}

func NewGotifyPlayer

func NewGotifyPlayer(clientID, redirectURL string, scopes ...scope) *GotifyPlayer

func (*GotifyPlayer) AuthenticateHTTP

func (gp *GotifyPlayer) AuthenticateHTTP(port uint16) error

Authenticate using local http server.

func (*GotifyPlayer) AuthenticateStdin

func (gp *GotifyPlayer) AuthenticateStdin() error

Authenticate using stdin.

func (*GotifyPlayer) AuthenticateToken

func (gp *GotifyPlayer) AuthenticateToken(token *oauth2.Token) error

Authenticate using a token.

func (*GotifyPlayer) Next

func (gp *GotifyPlayer) Next() error

func (*GotifyPlayer) Pause

func (gp *GotifyPlayer) Pause() error

func (*GotifyPlayer) Play

func (gp *GotifyPlayer) Play() error

func (*GotifyPlayer) Previous

func (gp *GotifyPlayer) Previous() error

func (*GotifyPlayer) Repeat

func (gp *GotifyPlayer) Repeat(state lib.RepeatMode) error

func (*GotifyPlayer) Seek

func (gp *GotifyPlayer) Seek(position time.Duration) error

func (*GotifyPlayer) Send

func (gp *GotifyPlayer) Send(method lib.HTTPMethod, action string, options [][2]string, body []byte) ([]byte, error)

func (*GotifyPlayer) Shuffle

func (gp *GotifyPlayer) Shuffle(state bool) error

func (*GotifyPlayer) Token

func (gp *GotifyPlayer) Token() (*oauth2.Token, error)

Token get current active token.

func (*GotifyPlayer) Volume

func (gp *GotifyPlayer) Volume(volume int) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL