libspotify

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

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

Go to latest
Published: Sep 30, 2013 License: Apache-2.0 Imports: 7 Imported by: 0

README

Golang libspotify bindings

Package spotify adds language bindings for libspotify in Go. The libspotify C API package allows third-party developers to write applications that utilize the Spotify music streaming service.

This is a work in progress. Expect this API to change. Patches are welcome.

Installing

Using go get

$ go get github.com/op/go-libspotify

After this command go-libspotify is ready to use. Its source will be in:

$GOROOT/src/pkg/github.com/op/go-libspotify

You can use go get -u -a to update all installed packages.

Documentation

For docs, see http://godoc.org/github.com/op/go-libspotify or run:

$ go doc github.com/op/go-libspotify

Documentation

Overview

Package libspotify adds language bindings for libspotify in Go. The libspotify C API package allows third-party developers to write applications that utilize the Spotify music streaming service.

Index

Constants

View Source
const (
	// The library version targeted does not match the one you claim you
	// support
	ErrBadAPIVersion Error = Error(C.SP_ERROR_BAD_API_VERSION)

	// Initialization of library failed - are cache locations etc. valid?
	ErrAPIInitializationFailed = Error(C.SP_ERROR_API_INITIALIZATION_FAILED)

	// The track specified for playing cannot be played
	ErrTrackNotPlayable = Error(C.SP_ERROR_TRACK_NOT_PLAYABLE)

	// The application key is invalid
	ErrBadApplicationKey = Error(C.SP_ERROR_BAD_APPLICATION_KEY)

	// Login failed because of bad username and/or password
	ErrBadUsernameOrPassword = Error(C.SP_ERROR_BAD_USERNAME_OR_PASSWORD)

	// The specified username is banned
	ErrUserBanned = Error(C.SP_ERROR_USER_BANNED)

	// Cannot connect to the Spotify backend system
	ErrUnableToContactServer = Error(C.SP_ERROR_UNABLE_TO_CONTACT_SERVER)

	// Client is too old, library will need to be updated
	ErrClientTooOld = Error(C.SP_ERROR_CLIENT_TOO_OLD)

	// Some other error occurred, and it is permanent (e.g. trying to relogin
	// will not help)
	ErrOtherPermanent = Error(C.SP_ERROR_OTHER_PERMANENT)

	// The user agent string is invalid or too long
	ErrBadUserAgent = Error(C.SP_ERROR_BAD_USER_AGENT)

	// No valid callback registered to handle events
	ErrMissingCallback = Error(C.SP_ERROR_MISSING_CALLBACK)

	// Input data was either missing or invalid
	ErrInvalidIndata = Error(C.SP_ERROR_INVALID_INDATA)

	// Index out of range
	ErrIndexOutOfRange = Error(C.SP_ERROR_INDEX_OUT_OF_RANGE)

	// The specified user needs a premium account
	ErrUserNeedsPremium = Error(C.SP_ERROR_USER_NEEDS_PREMIUM)

	// A transient error occurred.
	ErrOtherTransient = Error(C.SP_ERROR_OTHER_TRANSIENT)

	// The resource is currently loading
	ErrIsLoading = Error(C.SP_ERROR_IS_LOADING)

	// Could not find any suitable stream to play
	ErrNoStreamAvailable = Error(C.SP_ERROR_NO_STREAM_AVAILABLE)

	// Requested operation is not allowed
	ErrPermissionDenied = Error(C.SP_ERROR_PERMISSION_DENIED)

	// Target inbox is full
	ErrInboxIsFull = Error(C.SP_ERROR_INBOX_IS_FULL)

	// Cache is not enabled
	ErrNoCache = Error(C.SP_ERROR_NO_CACHE)

	// Requested user does not exist
	ErrNoSuchUser = Error(C.SP_ERROR_NO_SUCH_USER)

	// No credentials are stored
	ErrNoCredentials = Error(C.SP_ERROR_NO_CREDENTIALS)

	// Network disabled
	ErrNetworkDisabled = Error(C.SP_ERROR_NETWORK_DISABLED)

	// Invalid device ID
	ErrInvalidDeviceId = Error(C.SP_ERROR_INVALID_DEVICE_ID)

	// Unable to open trace file
	ErrCantOpenTraceFile = Error(C.SP_ERROR_CANT_OPEN_TRACE_FILE)

	// This application is no longer allowed to use the Spotify service
	ErrApplicationBanned = Error(C.SP_ERROR_APPLICATION_BANNED)

	// Reached the device limit for number of tracks to download
	ErrOfflineTooManyTracks = Error(C.SP_ERROR_OFFLINE_TOO_MANY_TRACKS)

	// Disk cache is full so no more tracks can be downloaded to offline mode
	ErrOfflineDiskCache = Error(C.SP_ERROR_OFFLINE_DISK_CACHE)

	// Offline key has expired, the user needs to go online again
	ErrOfflineExpired = Error(C.SP_ERROR_OFFLINE_EXPIRED)

	// This user is not allowed to use offline mode
	ErrOfflineNotAllowed = Error(C.SP_ERROR_OFFLINE_NOT_ALLOWED)

	// The license for this device has been lost. Most likely because the user
	// used offline on three other device
	ErrOfflineLicenseLost = Error(C.SP_ERROR_OFFLINE_LICENSE_LOST)

	// The Spotify license server does not respond correctly
	ErrOfflineLicenseError = Error(C.SP_ERROR_OFFLINE_LICENSE_ERROR)

	// A LastFM scrobble authentication error has occurred
	ErrLastFMAuthError = Error(C.SP_ERROR_LASTFM_AUTH_ERROR)

	// An invalid argument was specified
	ErrInvalidArgument = Error(C.SP_ERROR_INVALID_ARGUMENT)

	// An operating system error
	ErrSystemFailure = Error(C.SP_ERROR_SYSTEM_FAILURE)
)
View Source
const (
	// User not yet logged in
	ConnectionStateLoggedOut ConnectionState = C.SP_CONNECTION_STATE_LOGGED_OUT

	// Logged in against an Spotify accesspoint
	ConnectionStateLoggedIn = C.SP_CONNECTION_STATE_LOGGED_IN

	// Was logged in, but has now been disconnected
	ConnectionStateDisconnected = C.SP_CONNECTION_STATE_DISCONNECTED

	// Connection state is undefined
	ConnectionStateUndefined = C.SP_CONNECTION_STATE_UNDEFINED

	// Logged in, but in offline mode
	ConnectionStateOffline = C.SP_CONNECTION_STATE_OFFLINE
)
View Source
const (
	// Track is not available
	TrackAvailabilityUnavailable = TrackAvailability(C.SP_TRACK_AVAILABILITY_UNAVAILABLE)

	// Track is available and can be played
	TrackAvailabilityAvailable = TrackAvailability(C.SP_TRACK_AVAILABILITY_AVAILABLE)

	// Track can not be streamed using this account
	TrackAvailabilityNotStreamable = TrackAvailability(C.SP_TRACK_AVAILABILITY_NOT_STREAMABLE)

	// Track not available on artist's request
	TrackAvailabilityBannedByArtist = TrackAvailability(C.SP_TRACK_AVAILABILITY_BANNED_BY_ARTIST)
)
View Source
const (
	// Not marked for offline
	TrackOfflineNo = TrackOfflineStatus(C.SP_TRACK_OFFLINE_NO)
	// Waiting for download
	TrackOfflineWaiting = TrackOfflineStatus(C.SP_TRACK_OFFLINE_WAITING)
	// Currently downloading
	TrackOfflineDownloading = TrackOfflineStatus(C.SP_TRACK_OFFLINE_DOWNLOADING)
	// Downloaded OK and can be played
	TrackOfflineDone = TrackOfflineStatus(C.SP_TRACK_OFFLINE_DONE)
	// TrackOfflineStatus during download
	TrackOfflineTrackOfflineStatus = TrackOfflineStatus(C.SP_TRACK_OFFLINE_ERROR)
	// Downloaded OK but not playable due to expiery
	TrackOfflineDoneExpired = TrackOfflineStatus(C.SP_TRACK_OFFLINE_DONE_EXPIRED)
	// Waiting because device have reached max number of allowed tracks
	TrackOfflineLimitExceeded = TrackOfflineStatus(C.SP_TRACK_OFFLINE_LIMIT_EXCEEDED)
	// Downloaded OK and available but scheduled for re-download
	TrackOfflineDoneResync = TrackOfflineStatus(C.SP_TRACK_OFFLINE_DONE_RESYNC)
)
View Source
const (
	// Normal album
	AlbumTypeAlbum = AlbumType(C.SP_ALBUMTYPE_ALBUM)
	// Single
	AlbumTypeSingle = AlbumType(C.SP_ALBUMTYPE_SINGLE)
	// Compilation
	AlbumTypeCompilation = AlbumType(C.SP_ALBUMTYPE_COMPILATION)
	// Unknown type
	AlbumTypeUnknown = AlbumType(C.SP_ALBUMTYPE_UNKNOWN)
)

Variables

View Source
var (
	ErrMissingApplicationKey = errors.New("spotify: application key is required")
)

Functions

This section is empty.

Types

type Album

type Album struct {
	// contains filtered or unexported fields
}

func (*Album) IsAvailable

func (a *Album) IsAvailable() bool

func (*Album) Name

func (a *Album) Name() string

Name returns the name of the album.

func (*Album) Type

func (a *Album) Type() AlbumType

Type returns the type of album.

func (*Album) Wait

func (a *Album) Wait()

func (*Album) Year

func (a *Album) Year() int

Year returns the release year.

type AlbumType

type AlbumType C.sp_albumtype

type Artist

type Artist struct {
	// contains filtered or unexported fields
}

func (*Artist) Name

func (a *Artist) Name() string

func (*Artist) Wait

func (a *Artist) Wait()

type Config

type Config struct {
	// ApplicationKey is required and can be acquired from developer.spotify.com.
	ApplicationKey []byte

	// ApplicationName is used to determine cache locations and user agent.
	ApplicationName string

	// UserAgent is used when communicating with Spotify. If left empty, it
	// will automatically be created based on ApplicationName.
	UserAgent string

	CacheLocation    string
	SettingsLocation string
}

Config represents the configuration setup when creating a new session.

type ConnectionState

type ConnectionState C.sp_connectionstate

Connection state describes the state of the connection of a session.

type Credentials

type Credentials struct {
	// Username is the spotify username.
	Username string

	// Password for the spotify username.
	Password string

	// Blob is an opaque data chunk used when logging in instead of password. If
	// login is successful and the remember flag set to true, this should be the
	// data blob retrieved from CredentialsBlobUpdates.
	Blob []byte
}

Credentials are used when logging a user in.

type Error

type Error C.sp_error

func (Error) Error

func (e Error) Error() string

type Popularity

type Popularity int

Popularity is in the range [0, 100].

type SearchOptions

type SearchOptions struct {
	// Track is the number of tracks to search for
	Track SearchSpec

	// Album is the number of albums to search for
	Album SearchSpec

	// Artist is the number of artists to search for
	Artist SearchSpec

	// Playlist is the number of playlists to search for
	Playlist SearchSpec

	// Type is the search type. Defaults to normal searching.
	Type SearchType
}

SearchOptions contains offsets and limits for the search query.

type SearchSpec

type SearchSpec struct {
	// Search result offset
	Offset int

	// Search result limitation
	Count int
}

type SearchType

type SearchType C.sp_search_type
const (
	SearchStandard SearchType = SearchType(C.SP_SEARCH_STANDARD)
	SearchSuggest             = SearchType(C.SP_SEARCH_SUGGEST)
)

type Session

type Session struct {
	// contains filtered or unexported fields
}

Session is the representation of a Spotify session.

func NewSession

func NewSession(config *Config) (*Session, error)

NewSession creates a new session based on the given configuration.

func (*Session) Close

func (s *Session) Close() error

Close closes the session, making the session unusable for any future calls. This call releases the session internally back to libspotify and shuts the background processing thread down.

func (*Session) ConnectionState

func (s *Session) ConnectionState() ConnectionState

ConnectionState returns the current connection state for the session.

func (*Session) ConnectionStateUpdates

func (s *Session) ConnectionStateUpdates() <-chan struct{}

ConnectionStateUpdates returns a channel used to get updates on the connection state.

func (*Session) CredentialsBlobUpdates

func (s *Session) CredentialsBlobUpdates() <-chan []byte

CredentialsBlobUpdates returns a channel used to get updates for credential blobs.

func (*Session) FlushCaches

func (s *Session) FlushCaches() error

FlushCaches makes libspotify write all data that is meant to be stored on disk to the disk immediately. libspotify does this periodically by itself and also on logout. Under normal conditions this shouldn't be needed.

func (*Session) Login

func (s *Session) Login(c Credentials, remember bool) error

Login logs the the specified username and password combo. This initiates the login in the background.

An application MUST NEVER store the user's password in clear text. If automatic relogin is required, use Relogin.

func (*Session) LoginUpdates

func (s *Session) LoginUpdates() <-chan error

LoginUpdates returns a channel used to get notified when the session has been logged in.

func (*Session) Logout

func (s *Session) Logout() error

Logout logs the currently logged in user out

Always call this before terminating the application and libspotify is currently logged in. Otherwise, the settings and cache may be lost.

func (*Session) LogoutUpdates

func (s *Session) LogoutUpdates() <-chan struct{}

LogoutUpdates returns a channel used to get notified when the session has been logged out.

func (*Session) Relogin

func (s *Session) Relogin() error

Relogin logs the remembered user in if the last user which logged in, logged in with the remember flag set to true.

If no credentials are stored, this will return ErrNoCredentials.

func (*Session) Search

func (s *Session) Search(query string, opts *SearchOptions) *search

Search searches Spotify for track, album, artist and / or playlists.

type Track

type Track struct {
	// contains filtered or unexported fields
}

func (*Track) Album

func (t *Track) Album() *Album

Album returns the album of the track.

func (*Track) Artist

func (t *Track) Artist(n int) *Artist

func (*Track) Artists

func (t *Track) Artists() int

func (*Track) Availability

func (t *Track) Availability() TrackAvailability

Availability returns the track availability.

func (*Track) Disc

func (t *Track) Disc() int

Disc returns the disc number for the track.

func (*Track) Duration

func (t *Track) Duration() time.Duration

Duration returns the length of the current track.

func (*Track) Error

func (t *Track) Error() error

Error returns an error associated with a track.

func (*Track) Index

func (t *Track) Index() int

Position returns the position of a track on its disc. It starts at 1 (relative the corresponding disc).

This function returns valid data only for tracks appearing in a browse artist or browse album result (otherwise returns 0).

func (*Track) IsAutoLinked

func (t *Track) IsAutoLinked() bool

IsAutoLinked returns true if the track is auto-linked to another track.

func (*Track) IsLocal

func (t *Track) IsLocal() bool

IsLocal returns true if the track is a local file.

func (*Track) IsPlaceholder

func (t *Track) IsPlaceholder() bool

IsPlaceholder returns true if the track is a placeholder. Placeholder tracks are used to store other objects than tracks in the playlist. Currently this is used in the inbox to store artists, albums and playlists.

TODO Use sp_link_create_from_track() to get a link object that points to the real object this "track" points to.

func (*Track) IsStarred

func (t *Track) IsStarred() bool

IsStarred returns true if the track is starred by the currently logged in user.

func (*Track) Name

func (t *Track) Name() string

Name returns the track name.

func (*Track) OfflineStatus

func (t *Track) OfflineStatus() TrackOfflineStatus

func (*Track) PlayableTrack

func (t *Track) PlayableTrack() *Track

func (*Track) Popularity

func (t *Track) Popularity() Popularity

Popularity returns the popularity for the track.

func (*Track) Wait

func (t *Track) Wait()

type TrackAvailability

type TrackAvailability C.sp_track_availability

type TrackOfflineStatus

type TrackOfflineStatus C.sp_track_offline_status

Directories

Path Synopsis
examples
gospshell command

Jump to

Keyboard shortcuts

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