api

package
v0.0.0-...-e9c3984 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2021 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthorizeWithCode

func AuthorizeWithCode(id, secret, code string)

AuthorizeWithCode completes the Authorization process and stores your refresh and current access tokens in the config directory for Baton

func GetAuthorizationURL

func GetAuthorizationURL(id string) string

GetAuthorizationURL builds an Authorization URL for the user to navigate to from their ClientID

func PausePlayback

func PausePlayback(opts *Options) error

PausePlayback pauses playback on the current device

func RemoveSavedAlbum

func RemoveSavedAlbum(AlbumID string) (err error)

RemoveSavedAlbum takes in an AlbumID and removes it from the users library

func RemoveSavedTrack

func RemoveSavedTrack(trackID string) (err error)

RemoveSavedTrack takes in a TrackID and removes it from the users library

func SaveAlbum

func SaveAlbum(AlbumID string) (err error)

SaveAlbum takes in an AlbumID and saves it to the users library

func SaveTrack

func SaveTrack(trackID string) (err error)

SaveTrack takes in a TrackID and saves it to the users library

func SeekToPosition

func SeekToPosition(pos int, opts *Options) error

SeekToPosition skips to a position defined in seconds for the current playback

func SetRepeatMode

func SetRepeatMode(state string, opts *Options) error

SetRepeatMode allows you to set the Repeat Mode of the current device Allowed values are track, context, and off

func SetVolume

func SetVolume(vol int, opts *Options) error

SetVolume allows you to control the volume percentage of the device Allowed values are 0-100

func SkipToNext

func SkipToNext(opts *Options) error

SkipToNext skips to the next song within the current context

func SkipToPrevious

func SkipToPrevious(opts *Options) error

SkipToPrevious skips to the previous song within the current context

func StartPlayback

func StartPlayback(opts *PlayerOptions) error

StartPlayback can resume playback or change playback to a new URI/context

func ToggleShuffle

func ToggleShuffle(state bool, opts *Options) error

ToggleShuffle toggles the shuffle state on/off

func TransferPlayback

func TransferPlayback(opts *TransferOptions) error

Types

type Device

type Device struct {
	ID            string `json:"id"`
	IsActive      bool   `json:"is_active"`
	IsRestricted  bool   `json:"is_restricted"`
	Name          string `json:"name"`
	Type          string `json:"type"`
	VolumePercent int    `json:"volume_percent"`
}

The Device struct describes an available playback device

func GetDevices

func GetDevices() (d []Device, err error)

GetDevices returns a list of available playback devices

type Devices

type Devices struct {
	Devices []Device `json:"devices"`
}

The Devices struct is needed because the /devices endpoint returns the devices wrapped in a root object

type Followers

type Followers struct {
	Href  string `json:"href"`
	Total int    `json:"total"`
}

The Followers struct describes the followers for an artist, playlist, etc

type FullArtist

type FullArtist struct {
	ExternalUrls map[string]string `json:"external_urls"`
	Followers    *Followers        `json:"followers"`
	Genres       []string          `json:"genres"`
	Href         string            `json:"href"`
	ID           string            `json:"id"`
	Images       []Image           `json:"images"`
	Name         string            `json:"name"`
	Popularity   int               `json:"popularity"`
	Type         string            `json:"type"`
	URI          string            `json:"uri"`
}

The FullArtist struct describes a "Full" Artist object as defined by the Spotify Web API

type FullArtistsPaged

type FullArtistsPaged struct {
	Href     string       `json:"href"`
	Items    []FullArtist `json:"items"`
	Limit    int          `json:"limit"`
	Next     string       `json:"next"`
	Offset   int          `json:"offset"`
	Previous string       `json:"previous"`
	Total    int          `json:"total"`
}

The FullArtistsPaged struct is a slice of FullArtist objects wrapped in a Spotify paging object

type FullTrack

type FullTrack struct {
	Album            *SimpleAlbum      `json:"album"`
	Artists          []SimpleArtist    `json:"artists"`
	AvailableMarkets []string          `json:"available_markets"`
	DiscNumber       int               `json:"disc_number"`
	DurationMs       int               `json:"duration_ms"`
	Explicit         bool              `json:"explicit"`
	ExternalIDs      map[string]string `json:"external_ids"`
	ExternalUrls     map[string]string `json:"external_urls"`
	Href             string            `json:"href"`
	ID               string            `json:"id"`
	IsPlayable       bool              `json:"is_playable"`
	LinkedFrom       *TrackLink        `json:"linked_from"`
	Name             string            `json:"name"`
	Popularity       int               `json:"popularity"`
	PreviewURL       string            `json:"preview_url"`
	TrackNumber      int               `json:"track_number"`
	Type             string            `json:"type"`
	URI              string            `json:"uri"`
}

The FullTrack struct describes a "Full" Track object as defined by the Spotify Web API

type FullTracksPaged

type FullTracksPaged struct {
	Href     string      `json:"href"`
	Items    []FullTrack `json:"items"`
	Limit    int         `json:"limit"`
	Next     string      `json:"next"`
	Offset   int         `json:"offset"`
	Previous string      `json:"previous"`
	Total    int         `json:"total"`
}

The FullTracksPaged struct is a slice of FullTrack objects wrapped in a Spotify paging object

type Image

type Image struct {
	Height int    `json:"height"`
	URL    string `json:"url"`
	Width  int    `json:"width"`
}

The Image struct describes an album, artist, playlist, etc image

type Options

type Options struct {
	DeviceID string `json:"device_id,omitempty" url:"device_id,omitempty"`
	Market   string `json:"market,omitempty" url:"market,omitempty"`
}

The Options struct describes options that can be used by the majority of API endpoints

type PlayerContext

type PlayerContext struct {
	Type         string            `json:"type"`
	Href         string            `json:"href"`
	ExternalUrls map[string]string `json:"external_urls"`
	URI          string            `json:"uri"`
}

The PlayerContext struct describes the current context of what is playing on the active device. ex. The context could be an "album" which can then be derived from the URI The can be used to determine that "One More Time by Daft Punk" that the user is listening to is actually in a user created playlist and that the context is NOT the album versiom, for instance

type PlayerOffsetOptions

type PlayerOffsetOptions struct {
	Position int    `json:"position,omitempty" url:"position,omitempty"`
	URI      string `json:"uri,omitempty" url:"uri,omitempty"`
}

The PlayerOffsetOptions describes how to set the offset within a context when controlling playback For example, you can use Position to specify track number within an album OR you can use the URI to point to that same track directly

type PlayerOptions

type PlayerOptions struct {
	DeviceID   string               `json:"device_id,omitempty" url:"device_id,omitempty"`
	ContextURI string               `json:"context_uri,omitempty" url:"context_uri,omitempty"`
	URIs       []string             `json:"uris,omitempty" url:"uris,omitempty"`
	Offset     *PlayerOffsetOptions `json:"offset,omitempty" url:"offset,omitempty"`
}

The PlayerOptions struct describes options that are specific to the /me/player endpoints

type PlayerState

type PlayerState struct {
	Device       *Device        `json:"device"`
	RepeatState  string         `json:"repeat_state"`
	ShuffleState bool           `json:"shuffle_state"`
	Context      *PlayerContext `json:"context"`
	Timestamp    int            `json:"timestamp"`
	ProgressMs   int            `json:"progress_ms"`
	IsPlaying    bool           `json:"is_playing"`
	Item         *FullTrack     `json:"item"`
}

The PlayerState struct describes the current playback state of Spotify

func GetPlayerState

func GetPlayerState(opts *Options) (ps PlayerState, err error)

GetPlayerState returns the active device, whether the player is paused, progress of current song, and other playback information

type PlaylistTrack

type PlaylistTrack struct {
	AddedAt *time.Time `json:"added_at"`
	AddedBy *User      `json:"added_by"`
	IsLocal bool       `json:"is_local"`
	Track   FullTrack  `json:"track"`
}

The PlaylistTrack struct describes a Playlist Track object as defined by the Spotify Web API

type PlaylistTrackLinks struct {
	Href  string `json:"href"`
	Total int    `json:"total"`
}

The PlaylistTrackLinks struct describes a Playlist Track Link object as defined by the Spotify Web API

type PlaylistTracksPaged

type PlaylistTracksPaged struct {
	Href     string          `json:"href"`
	Items    []PlaylistTrack `json:"items"`
	Limit    int             `json:"limit"`
	Next     string          `json:"next"`
	Offset   int             `json:"offset"`
	Previous string          `json:"previous"`
	Total    int             `json:"total"`
}

The PlaylistTracksPaged struct is a slice of PlaylistTrack objects wrapped in a Spotify paging object

func GetNextTracksForPlaylist

func GetNextTracksForPlaylist(url string) (pt PlaylistTracksPaged, err error)

GetNextTracksForPlaylist takes in the Next field from the paging objects returned from GetTracksForPlaylist and allows you to move forward through the tracks

func GetTracksForPlaylist

func GetTracksForPlaylist(userID, playlistID string) (pt PlaylistTracksPaged, err error)

GetTracksForPlaylist returns a list of PlaylistTrack objects in a paging object for the given user and playlist

type SavedAlbum

type SavedAlbum struct {
	AddedAt *time.Time  `json:"added_at"`
	Album   SimpleAlbum `json:"album"`
}

The SavedAlbum struct describes a Saved Track object as defined by the Spotify Web API

type SavedAlbumsPaged

type SavedAlbumsPaged struct {
	Href     string       `json:"href"`
	Items    []SavedAlbum `json:"items"`
	Limit    int          `json:"limit"`
	Next     string       `json:"next"`
	Offset   int          `json:"offset"`
	Previous string       `json:"previous"`
	Total    int          `json:"total"`
}

The SavedAlbumsPaged struct is a slice of SavedAlbum objects wrapped in a Spotify paging object

func GetNextSavedAlbums

func GetNextSavedAlbums(url string) (sr *SavedAlbumsPaged, err error)

GetNextSavedAlbums takes in the Next fields from the paging objects returned from Saved Albums and moves forward through the results

func GetSavedAlbums

func GetSavedAlbums(opts *SearchOptions) (result *SavedAlbumsPaged, err error)

GetSavedAlbums returns a list of all the albums the user has saved

type SavedTrack

type SavedTrack struct {
	AddedAt *time.Time `json:"added_at"`
	Track   FullTrack  `json:"track"`
}

The SavedTrack struct describes a Saved Track object as defined by the Spotify Web API

type SavedTracksPaged

type SavedTracksPaged struct {
	Href     string       `json:"href"`
	Items    []SavedTrack `json:"items"`
	Limit    int          `json:"limit"`
	Next     string       `json:"next"`
	Offset   int          `json:"offset"`
	Previous string       `json:"previous"`
	Total    int          `json:"total"`
}

The SavedTracksPaged struct is a slice of SavedTrack objects wrapped in a Spotify paging object

func GetNextSavedTracks

func GetNextSavedTracks(url string) (sr *SavedTracksPaged, err error)

GetNextSavedTracks takes in the Next fields from the paging objects returned from Saved and moves forward through the results

func GetSavedTracks

func GetSavedTracks(opts *SearchOptions) (result *SavedTracksPaged, err error)

GetSavedTracks returns a list of all the songs the user has saved

type SearchOptions

type SearchOptions struct {
	Market string `json:"market,omitempty" url:"market,omitempty"`
	Limit  int    `json:"limit,omitempty" url:"limit,omitempty"`
	Offset int    `json:"offset,omitempty" url:"offset,omitempty"`
}

The SearchOptions struct describes the possible optional arguments for the Search function

type SearchResults

type SearchResults struct {
	Artists   *FullArtistsPaged     `json:"artists"`
	Albums    *SimpleAlbumsPaged    `json:"albums"`
	Tracks    *FullTracksPaged      `json:"tracks"`
	Playlists *SimplePlaylistsPaged `json:"playlists"`
}

The SearchResults struct describes the potential results of any search against the Spotify API

func GetNextSearchResults

func GetNextSearchResults(url string) (sr *SearchResults, err error)

GetNextSearchResults takes in the Next fields from the paging objects returned from Search and allows you to move forward through the results

func Search(q, types string, opts *SearchOptions) (sr SearchResults, err error)

Search queries the Spotify API based on the given query and options and returns the results wrapped in paging objects

type SimpleAlbum

type SimpleAlbum struct {
	AlbumType        string            `json:"album"`
	Artists          []SimpleArtist    `json:"artists"`
	AvailableMarkets []string          `json:"available_markets"`
	ExternalUrls     map[string]string `json:"external_urls"`
	Href             string            `json:"href"`
	ID               string            `json:"id"`
	Images           []Image           `json:"images"`
	Name             string            `json:"name"`
	Type             string            `json:"type"`
	URI              string            `json:"uri"`
}

The SimpleAlbum struct describes a "Simple" Album object as defined by the Spotify Web API

type SimpleAlbumsPaged

type SimpleAlbumsPaged struct {
	Href     string        `json:"href"`
	Items    []SimpleAlbum `json:"items"`
	Limit    int           `json:"limit"`
	Next     string        `json:"next"`
	Offset   int           `json:"offset"`
	Previous string        `json:"previous"`
	Total    int           `json:"total"`
}

The SimpleAlbumsPaged struct is a slice of SimpleAlbum objects wrapped in a Spotify paging object

func GetAlbumsForArtist

func GetAlbumsForArtist(artistID string) (pa SimpleAlbumsPaged, err error)

GetAlbumsForArtist returns a list of "Simple" Album objects in a paging object for the given artist

func GetNextAlbumsForArtist

func GetNextAlbumsForArtist(url string) (pa SimpleAlbumsPaged, err error)

GetNextAlbumsForArtist takes in the Next field from the paging objects returned from GetAlbumsForArtist and allows you to move forward through the albums

type SimpleArtist

type SimpleArtist struct {
	ExternalUrls map[string]string `json:"external_urls"`
	Href         string            `json:"href"`
	ID           string            `json:"id"`
	Name         string            `json:"name"`
	Type         string            `json:"type"`
	URI          string            `json:"uri"`
}

The SimpleArtist struct describes a "Simple" Artist object as defined by the Spotify Web API

type SimplePlaylist

type SimplePlaylist struct {
	Collaborative bool                `json:"collaborative"`
	ExternalUrls  map[string]string   `json:"external_urls"`
	Href          string              `json:"href"`
	ID            string              `json:"id"`
	Images        []Image             `json:"images"`
	Name          string              `json:"name"`
	Owner         *User               `json:"owner"`
	Public        bool                `json:"public"`
	SnapshotID    string              `json:"snapshot_id"`
	Tracks        *PlaylistTrackLinks `json:"tracks"`
	Type          string              `json:"type"`
	URI           string              `json:"uri"`
}

The SimplePlaylist struct describes a "Simple" Playlist object as defined by the Spotify Web API

type SimplePlaylistsPaged

type SimplePlaylistsPaged struct {
	Href     string           `json:"href"`
	Items    []SimplePlaylist `json:"items"`
	Limit    int              `json:"limit"`
	Next     string           `json:"next"`
	Offset   int              `json:"offset"`
	Previous string           `json:"previous"`
	Total    int              `json:"total"`
}

The SimplePlaylistsPaged struct is a slice of SimplePlaylist objects wrapped in a Spotify paging object

func GetMyPlaylists

func GetMyPlaylists() (pt *SimplePlaylistsPaged, err error)

GetMyPlaylists takes in the Next field from the paging objects returned from GetTracksForPlaylist and allows you to move forward through the tracks

func GetNextMyPlaylists

func GetNextMyPlaylists(url string) (pt *SimplePlaylistsPaged, err error)

GetNextMyPlaylists takes in the Next fields from the paging objects returned from me/playlists and allows you to move forward through the results

type SimpleTrack

type SimpleTrack struct {
	Artists          []SimpleArtist    `json:"artists"`
	AvailableMarkets []string          `json:"available_markets"`
	DiscNumber       int               `json:"disc_number"`
	DurationMs       int               `json:"duration_ms"`
	Explicit         bool              `json:"explicit"`
	ExternalUrls     map[string]string `json:"external_urls"`
	Href             string            `json:"href"`
	ID               string            `json:"id"`
	IsPlayable       bool              `json:"is_playable"`
	LinkedFrom       *TrackLink        `json:"linked_from"`
	Name             string            `json:"name"`
	PreviewURL       string            `json:"preview_url"`
	TrackNumber      int               `json:"track_number"`
	Type             string            `json:"type"`
	URI              string            `json:"uri"`
}

The SimpleTrack struct describes a "Simple" Track object as defined by the Spotify Web API

type SimpleTracksPaged

type SimpleTracksPaged struct {
	Href     string        `json:"href"`
	Items    []SimpleTrack `json:"items"`
	Limit    int           `json:"limit"`
	Next     string        `json:"next"`
	Offset   int           `json:"offset"`
	Previous string        `json:"previous"`
	Total    int           `json:"total"`
}

The SimpleTracksPaged struct is a slice of SimpleTrack objects wrapped in a Spotify paging object

func GetNextTracksForAlbum

func GetNextTracksForAlbum(url string) (pt SimpleTracksPaged, err error)

GetNextTracksForAlbum takes in the Next field from the paging objects returned from GetTracksForAlbum and allows you to move forward through the tracks

func GetTracksForAlbum

func GetTracksForAlbum(albumID string) (pt SimpleTracksPaged, err error)

GetTracksForAlbum returns a list of "Simple" Track objects in a paging object for the given album

type Tokens

type Tokens struct {
	AccessToken    string        `json:"access_token"`
	TokenType      string        `json:"token_type"`
	ExpiresIn      time.Duration `json:"expires_in"`
	ExpirationDate time.Time     `json:"expiration_date"`
	ClientID       string        `json:"client_id"`
	ClientSecret   string        `json:"client_secret"`
	RefreshToken   string        `json:"refresh_token"`
	Scope          string        `json:"scope"`
}

The Tokens struct describes a combination of the items returned from Spotify's API Authorization process as well as Baton-created fields to store in your config directory

type TrackLink struct {
	ExternalUrls map[string]string `json:"external_urls"`
	Href         string            `json:"href"`
	ID           string            `json:"id"`
	Type         string            `json:"type"`
	URI          string            `json:"uri"`
}

The TrackLink struct describes a TrackLink object as defined by the Spotify Web API

type TransferOptions

type TransferOptions struct {
	DeviceIDs []string `json:"device_ids" url:"device_ids"`
	Play      bool     `json:"play,omitempty" url:"play,omitempty"`
}

type User

type User struct {
	DisplayName  string            `json:"display_name"`
	ExternalUrls map[string]string `json:"external_urls"`
	Followers    *Followers        `json:"followers"`
	Href         string            `json:"href"`
	ID           string            `json:"id"`
	Images       []Image           `json:"images"`
	Type         string            `json:"type"`
	URI          string            `json:"uri"`
}

The User struct describes a User object as defined by the Spotify Web API

Jump to

Keyboard shortcuts

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