spotcontrol

package module
v0.0.0-...-cd9aefc Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2018 License: MIT Imports: 27 Imported by: 0

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 ArtistInsightsResponse

type ArtistInsightsResponse struct {
	Name                 string          `json:"name"`
	DisplayURL           string          `json:"mainImageUrl"`
	GlobalChartPosition  int64           `json:"globalChartPosition"`
	MonthlyListenerCount int64           `json:"monthlyListeners"`
	FollowerCount        int64           `json:"followerCount"`
	FollowingCount       int64           `json:"followingCount"`
	CityListenerCounts   []CityListeners `json:"cities"`
}

type ArtistMetadataResponse

type ArtistMetadataResponse struct {
	ArtistInfo struct {
		Uri       string  `json:"uri"`
		Name      string  `json:"name"`
		Portraits []Image `json:"portraits"`
	} `json:"info"`
	TopTracks struct {
		Tracks []PlayCountTrack `json:"tracks"`
	} `json:"top_tracks"`
	CreatorAbout struct {
		MonthlyListeners    int64 `json:"monthlyListeners"`
		GlobalChartPosition int64 `json:"globalChartPosition"`
	} `json:"creator_about"`
}

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 CityListeners

type CityListeners struct {
	Country       string `json:"country"`
	Region        string `json:"region"`
	City          string `json:"city"`
	ListenerCount int64  `json:"listeners"`
}

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 Image

type Image struct {
	Uri string `json:"uri"`
}

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 PlayCountTrack

type PlayCountTrack struct {
	Uri       string `json:"uri"`
	PlayCount int64  `json:"playcount"`
	Name      string `json:"name"`
	Release   struct {
		Uri   string `json:"uri"`
		Name  string `json:"name"`
		Cover Image  `json:"cover"`
	} `json:"release"`
	Explicit bool `json:"explicit"`
}

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) GetArtistInsights

func (c *SpircController) GetArtistInsights(artistId string) (*ArtistInsightsResponse, error)

func (*SpircController) GetArtistMeta

func (c *SpircController) GetArtistMeta(artistId string) (*ArtistMetadataResponse, error)

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