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
- Variables
- type Album
- type AlbumType
- type Artist
- type Config
- type ConnectionState
- type Credentials
- type Error
- type Popularity
- type SearchOptions
- type SearchSpec
- type SearchType
- type Session
- func (s *Session) Close() error
- func (s *Session) ConnectionState() ConnectionState
- func (s *Session) ConnectionStateUpdates() <-chan struct{}
- func (s *Session) CredentialsBlobUpdates() <-chan []byte
- func (s *Session) FlushCaches() error
- func (s *Session) Login(c Credentials, remember bool) error
- func (s *Session) LoginUpdates() <-chan error
- func (s *Session) Logout() error
- func (s *Session) LogoutUpdates() <-chan struct{}
- func (s *Session) Relogin() error
- func (s *Session) Search(query string, opts *SearchOptions) *search
- type Track
- func (t *Track) Album() *Album
- func (t *Track) Artist(n int) *Artist
- func (t *Track) Artists() int
- func (t *Track) Availability() TrackAvailability
- func (t *Track) Disc() int
- func (t *Track) Duration() time.Duration
- func (t *Track) Error() error
- func (t *Track) Index() int
- func (t *Track) IsAutoLinked() bool
- func (t *Track) IsLocal() bool
- func (t *Track) IsPlaceholder() bool
- func (t *Track) IsStarred() bool
- func (t *Track) Name() string
- func (t *Track) OfflineStatus() TrackOfflineStatus
- func (t *Track) PlayableTrack() *Track
- func (t *Track) Popularity() Popularity
- func (t *Track) Wait()
- type TrackAvailability
- type TrackOfflineStatus
Constants ¶
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) )
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 )
const ( 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) )
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) )
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 ¶
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 ¶
type AlbumType ¶
type AlbumType C.sp_albumtype
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 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 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 ¶
NewSession creates a new session based on the given configuration.
func (*Session) Close ¶
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 ¶
CredentialsBlobUpdates returns a channel used to get updates for credential blobs.
func (*Session) FlushCaches ¶
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 ¶
LoginUpdates returns a channel used to get notified when the session has been logged in.
func (*Session) Logout ¶
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 ¶
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) Availability ¶
func (t *Track) Availability() TrackAvailability
Availability returns the track availability.
func (*Track) Index ¶
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 ¶
IsAutoLinked returns true if the track is auto-linked to another track.
func (*Track) IsPlaceholder ¶
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 ¶
IsStarred returns true if the track is starred by the currently logged in user.
func (*Track) OfflineStatus ¶
func (t *Track) OfflineStatus() TrackOfflineStatus
func (*Track) PlayableTrack ¶
func (*Track) Popularity ¶
func (t *Track) Popularity() Popularity
Popularity returns the popularity for the track.
type TrackAvailability ¶
type TrackAvailability C.sp_track_availability
type TrackOfflineStatus ¶
type TrackOfflineStatus C.sp_track_offline_status