Documentation ¶
Index ¶
- Constants
- func ConfigValue(key string) string
- func NewAuthenticator() (*spotify.Authenticator, error)
- func NewToken(ds DiskplayerServer) (*oauth2.Token, error)
- func Pause(c Client) error
- func PlayPath(c Client, p string) error
- func PlayUri(c Client, u string) error
- func ReadConfig(n string)
- func ReadToken() (*oauth2.Token, error)
- func Record(url string, fullPath string) error
- func SaveToken(token *oauth2.Token) error
- type CallbackHandler
- type Client
- type DiskplayerServer
- type ErrorPage
- type IndexPage
- type RealDiskplayerServer
- type SpotifyClient
Constants ¶
const ( DEFAULT_CONFIG_NAME = "diskplayer" STATE_IDENTIFIER = "abc123" RECORD_FILENAME = "recorder.filename" RECORD_FOLDER_PATH = "recorder.folder_path" RECORD_SERVER_PORT = "recorder.server_port" SPOTIFY_CALLBACK_URL = "spotify.callback_url" SPOTIFY_CLIENT_ID = "spotify.client_id" SPOTIFY_CLIENT_SECRET = "spotify.client_secret" SPOTIFY_DEVICE_NAME = "spotify.device_name" TOKEN_PATH = "token.path" )
Variables ¶
This section is empty.
Functions ¶
func ConfigValue ¶
ConfigValue returns the configuration value identified by the provided key. If none is found the application quits with an error message and exit code 1.
func NewAuthenticator ¶
func NewAuthenticator() (*spotify.Authenticator, error)
NewAuthenticator returns a Spotify authenticator object configured with the required callback URL, client IT and client secret. An error is returned if one is encountered
func NewToken ¶
func NewToken(ds DiskplayerServer) (*oauth2.Token, error)
NewToken will create a new OAuth2 token request. The user will be prompted to visit a URL, and after access is granted a new OAuth2 token is returned. An error is returned if encountered.
func Pause ¶
Pause will pause the Spotify playback if the Diskplayer is the currently active Spotify device. An error is returned if one is encountered.
func PlayPath ¶
PlayPath will play an album or playlist by reading a Spotify URI from a file whose filepath is passed into the function. An error is returned if one is encountered.
func PlayUri ¶
PlayURI will play the album or playlist Spotify URI that is passed in to the function. An error is returned if one is encountered.
func ReadConfig ¶
func ReadConfig(n string)
ReadConfig reads in the configuration values from the diskplayer.yaml configuration file.
func ReadToken ¶
ReadToken will attempt to deserialize a token whose path is defined in the diskplayer.yaml configuration file under the token.file_path field. Returns a pointer to an oauth2 token object or any error encountered.
func Record ¶
Record takes in a web URL which links to a Spotify album or playlist and records the corresponding Spotify ID to the filepath specified in the diskplayer.yaml configuration file under the recorder.file_path field. The web URL should be something like https://open.spotify.com/album/1S7mumn7D4riEX2gVWYgPO Returns an error if one is encountered.
Types ¶
type CallbackHandler ¶
type CallbackHandler struct {
// contains filtered or unexported fields
}
func (CallbackHandler) ServeHTTP ¶
func (h CallbackHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
An implementation of the Handler ServeHTTP function for the CallbackHandler struct.
type DiskplayerServer ¶
type RealDiskplayerServer ¶
type RealDiskplayerServer struct {
// contains filtered or unexported fields
}
func NewDiskplayerServer ¶
func NewDiskplayerServer(a *spotify.Authenticator, ch chan *oauth2.Token) *RealDiskplayerServer
NewDiskplayerServer returns a new DiskplayerServer instance. The arguments are required if the server instance is to be used to obtain a new Spotify auth token.
func (*RealDiskplayerServer) Authenticator ¶
func (s *RealDiskplayerServer) Authenticator() *spotify.Authenticator
func (*RealDiskplayerServer) RunCallbackServer ¶
func (s *RealDiskplayerServer) RunCallbackServer() (*http.Server, error)
RunCallbackServer creates a web server running on the port defined in the configuration file under the spotify. callback_url field. A pointer to the server object is returned so that it can be shutdown when no longer needed.
func (*RealDiskplayerServer) RunRecordServer ¶
func (s *RealDiskplayerServer) RunRecordServer() error
RunRecordServer creates a web server running on the port defined in the configuration file under the recorder. server_port field. Files are served directly from the "static" folder.
func (*RealDiskplayerServer) TokenChannel ¶
func (s *RealDiskplayerServer) TokenChannel() chan *oauth2.Token
type SpotifyClient ¶
type SpotifyClient struct {
// contains filtered or unexported fields
}
func NewClient ¶
func NewClient(a *spotify.Authenticator, t *oauth2.Token) *SpotifyClient
Returns an authenticated Spotify client object, or an error if encountered.
func (*SpotifyClient) Pause ¶
func (sc *SpotifyClient) Pause() error
Pause will pause playback for the currently active device.
func (*SpotifyClient) PlayOpt ¶
func (sc *SpotifyClient) PlayOpt(opt *spotify.PlayOptions) error
PlayOpt will initiate playback on the device as specified in the PlayOptions.
func (*SpotifyClient) PlayerDevices ¶
func (sc *SpotifyClient) PlayerDevices() ([]spotify.PlayerDevice, error)
PlayerDevices will return a list of available Spotify devices. An error is returned if encountered.
func (*SpotifyClient) TransferPlayback ¶
func (sc *SpotifyClient) TransferPlayback(deviceID spotify.ID, play bool) error
TransferPlayback will transfer the Spotify playback to the specified device.