spotcontrol

package module
v0.0.0-...-869dc3f Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2017 License: MIT Imports: 27 Imported by: 1

README

spotcontrol

Spotcontrol is an open source library for controlling spotify connect devices based on the librespot project.

Spotcontrol is a golang port of a small subset of the librespot functionality, focusing soley on controlling other devices, it does not offer any support for actual music playback. A simple cli is included in the examples folder and demonstrates the key features of the library (loading tracks, playing, pausing).

Installation

This package can be installed using:

go get github.com/badfortrains/spotcontrol

Usage

To use the package look at the example micro-controller, and see the godoc

go doc github.com/badfortrains/spotcontrol

Documentation

Overview

Package spotcontol contains functions to remotely control spotify connect devices.

Index

Constants

View Source
const FOLD int = 16
View Source
const KEYP int = 13
View Source
const N int = 16

Variables

This section is empty.

Functions

func ConvertTo62

func ConvertTo62(raw []byte) string

Types

type Album

type Album struct {
	Artists []Artist `json:"artists"`
	Image   string   `json:"image"`
	Name    string   `json:"name"`
	Uri     string   `json:"uri"`
}

type Artist

type Artist struct {
	Image string `json:"image"`
	Name  string `json:"name"`
	Uri   string `json:"uri"`
}

type BlobInfo

type BlobInfo struct {
	Username    string
	DecodedBlob string
}

func BlobFromDiscovery

func BlobFromDiscovery(deviceName string) *BlobInfo

Advertise spotify service via mdns. Waits for user to connect to 'spotcontrol' device. Extracts login data and returns login BlobInfo.

type ConnectDevice

type ConnectDevice struct {
	Name   string
	Ident  string
	Url    string
	Volume int
}

Represents an available spotify connect device. For mdns devices not yet authenitcated, Ident will be "" and Url will be the address to pass to ConnectToDevie.

type OAuth

type OAuth struct {
	AccessToken  string `json:"access_token"`
	RefreshToken string `json:"refresh_token"`
	Scope        string `json:"scope"`
	Error        string
}

func GetOauthAccessToken

func GetOauthAccessToken(code string, redirectUri string, clientId string, clientSecret string) (*OAuth, error)

type SearchResult

type SearchResult struct {
	Artists struct {
		Hits  []Artist `json:"hits"`
		Total int      `json:"total"`
	} `json:"artists"`
	Albums struct {
		Hits  []Album `json:"hits"`
		Total int     `json:"total"`
	} `json:"albums"`
	Tracks struct {
		Hits  []Track `json:"hits"`
		Total int     `json:"total"`
	} `json:"tracks"`
	Error error
}

type SpircController

type SpircController struct {
	SavedCredentials []byte
	// contains filtered or unexported fields
}

func Login

func Login(username string, password string, deviceName string) (*SpircController, error)

Login to spotify using username, password

func LoginBlob

func LoginBlob(username string, blob string, deviceName string) (*SpircController, error)

func LoginBlobFile

func LoginBlobFile(cacheBlobPath, deviceName string) (*SpircController, error)

Login from credentials at cacheBlobPath previously saved by LoginDiscovery.

func LoginDiscovery

func LoginDiscovery(cacheBlobPath, deviceName string) (*SpircController, error)

Registers spotcontrol as a spotify conenct device via mdns. When user connects, logs on to spotify and saves credentials in file at cacheBlobPath. Once saved, the blob credentials allow the program to connect to other spotify connect devices and control them.

func LoginOauth

func LoginOauth(deviceName string) (*SpircController, error)

func LoginOauthToken

func LoginOauthToken(accessToken string, deviceName string) (*SpircController, error)

func LoginSaved

func LoginSaved(username string, authData []byte, deviceName string) (*SpircController, error)

func (*SpircController) ConnectToDevice

func (c *SpircController) ConnectToDevice(address string)

Connect to spotify-connect device at address (local network path). Uses credentials from saved blob to authenticate.

func (*SpircController) GetPlaylist

func (c *SpircController) GetPlaylist(id string) (*Spotify.SelectedListContent, error)

func (*SpircController) GetRootPlaylist

func (c *SpircController) GetRootPlaylist() (*Spotify.SelectedListContent, error)

func (*SpircController) GetTrack

func (c *SpircController) GetTrack(id string) (*Spotify.Track, error)

func (*SpircController) ListDevices

func (c *SpircController) ListDevices() []ConnectDevice

List active spotify-connect devices that can be sent commands

func (*SpircController) ListMdnsDevices

func (c *SpircController) ListMdnsDevices() ([]ConnectDevice, error)

Lists devices on local network advertising spotify connect service (_spotify-connect._tcp.).

func (*SpircController) LoadTrack

func (c *SpircController) LoadTrack(ident string, gids []string) error

Load given list of tracks on spotify connect device with given ident. Gids are formated base62 spotify ids.

func (*SpircController) LoadTrackIds

func (c *SpircController) LoadTrackIds(ident string, ids string) error

Load comma seperated tracks

func (*SpircController) Search

func (c *SpircController) Search(search string) (*SearchResult, error)

func (*SpircController) SendHello

func (c *SpircController) SendHello() error

Sends a 'hello' command to all spotify connect devices. Active devices will respond with a 'notify' updating their state.

func (*SpircController) SendPause

func (c *SpircController) SendPause(ident string) error

Sends a 'pause' command to spotify connect device with given ident.

func (*SpircController) SendPlay

func (c *SpircController) SendPlay(ident string) error

Sends a 'play' command to spotify connect device with given ident.

func (*SpircController) SendVolume

func (c *SpircController) SendVolume(ident string, volume int) error

func (*SpircController) Suggest

func (c *SpircController) Suggest(search string) (*SuggestResult, error)

type SuggestResult

type SuggestResult struct {
	Sections []struct {
		RawItems json.RawMessage `json:"items"`
		Typ      string          `json:"type"`
	} `json:"sections"`
	Albums  []Artist
	Artists []Album
	Tracks  []Track
	TopHits []TopHit
	Error   error
}

type TopHit

type TopHit struct {
	Image string `json:"image"`
	Name  string `json:"name"`
	Uri   string `json:"uri"`
	Log   struct {
		Origin string `json:"origin"`
		TopHit string `json:"top_hit"`
	} `json:"log"`
	Artists []Artist `json:"artists"`
	Album   Album    `json:"album"`
}

type Track

type Track struct {
	Album      Album    `json:"album"`
	Artists    []Artist `json:"artists"`
	Image      string   `json:"image"`
	Name       string   `json:"name"`
	Uri        string   `json:"uri"`
	Duration   int      `json:"duration"`
	Popularity int      `json:"popularity"`
}

Directories

Path Synopsis
examples
Package Spotify is a generated protocol buffer package.
Package Spotify is a generated protocol buffer package.

Jump to

Keyboard shortcuts

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