providers

package
v0.0.0-...-472a414 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: MIT Imports: 53 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package providers reads playlist metadata through public HTTP APIs and asks a service for the audio address the account is entitled to. The only media it decrypts is Beatport's player stream for the account's own Essential subscription (beatport_hls.go). Each instance belongs to one account.

Index

Constants

View Source
const AppleMusicLikedID = "liked"

AppleMusicLikedID names the owner's library & favourite songs view.

View Source
const (

	// BeatportClientID is the public client of Beatport's own API documentation page.
	BeatportClientID = "ryZ8LuyQVPqbK2mBX2Hwt4qSMtnWuTYSqBPO92yQ"
)
View Source
const (
	DefaultReccoURL = "https://api.reccobeats.com"
)
View Source
const GuestPlaylist = "[Guest / 临时加歌]"
View Source
const OwnerPlaylist = "[Stream / 临时下载]"
View Source
const SpotifyLikedID = "liked"

SpotifyLikedID names the owner's Liked Songs, which Spotify keeps outside playlists.

Variables

View Source
var ErrNoFullAudio = errors.New("netease: no full-length audio for this account")

ErrNoFullAudio means the account only gets a preview of this track, or nothing.

View Source
var ErrNoFullStream = errors.New("soundcloud: no full-length stream for this track")

ErrNoFullStream means the API only offers a preview of the track.

View Source
var ErrSpotifyAuthentication = errors.New("spotify: permanent authentication failure")
View Source
var ErrSpotifyDeviceAuthExpired = errors.New("spotify: device authorization expired or denied")
View Source
var ErrSpotifyPairingBusy = errors.New("spotify: authentication is busy")
View Source
var SpotifyBuiltinClientID = librespot.ClientIdHex

SpotifyBuiltinClientID is go-librespot's public desktop identity.

Functions

func Camelot

func Camelot(pitch, mode int) string

Camelot converts a pitch class and mode (1 major, 0 minor) to e.g. "8A".

func IsDeezerUserID

func IsDeezerUserID(s string) bool

IsDeezerUserID reports whether s has the form of a Deezer user ID.

func JSON

func JSON(ctx context.Context, c *http.Client, method, endpoint string, body io.Reader, headers http.Header, out any) error

JSON performs bounded HTTP I/O and deliberately omits response bodies from errors: authentication services sometimes echo cookies or access tokens.

func LoadSpotifyDeviceID

func LoadSpotifyDeviceID(stateDir string) (string, error)

LoadSpotifyDeviceID gives each deck its own identity, shared by AP and Zeroconf. O_CREATE|O_EXCL creates a 0600 file on exFAT/vfat as well as POSIX filesystems without ever overwriting an existing identity.

func ParseSpotifyLinks(text string) [][2]string

ParseSpotifyLinks returns the playlist/album references (kind, id) found in text.

func RandomID

func RandomID() string

func SaveJSON

func SaveJSON(path string, v any) error

SaveJSON replaces an owner credential file atomically with mode 0600. Guest credentials stay in memory and must never be passed here.

func SpotifyDeviceID

func SpotifyDeviceID(seed string) string

Types

type Album

type Album struct {
	ID      int64
	Name    string
	Size    int
	Artists []struct{ Name string }
}

Album is an album the account has saved.

type AppleMusic

type AppleMusic struct {
	BaseURL, WebURL string // api.music.apple.com and music.apple.com; tests override
	HTTP            *http.Client
	OwnerPath       string // where the owner's links and token are saved, mode 0600
	// HelperURL is the enginex-amd helper (LAN/VPS); empty disables downloads.
	HelperURL, HelperLoginURL, HelperToken string
	// contains filtered or unexported fields
}

AppleMusic reads playlists from Apple Music's catalog (public playlist and album links, no account) and, with the owner's media-user-token, from their library (#65). Audio downloads are supplied by the enginex-amd helper.

func (*AppleMusic) CredGen

func (a *AppleMusic) CredGen() uint64

CredGen returns a monotonic counter incremented when owner credentials change.

func (*AppleMusic) DeveloperToken

func (a *AppleMusic) DeveloperToken(ctx context.Context) (string, error)

DeveloperToken is the token the phone page hands to MusicKit JS.

func (*AppleMusic) Download

func (a *AppleMusic) Download(ctx context.Context, t Track) (*AppleMusicAudio, error)

func (*AppleMusic) DownloadTo

func (a *AppleMusic) DownloadTo(ctx context.Context, t Track, dstDir, name string) (*AppleMusicAudio, error)

DownloadTo writes on the destination filesystem and publishes only a complete file.

func (*AppleMusic) FavoriteAlbums

func (a *AppleMusic) FavoriteAlbums(ctx context.Context) ([]AppleMusicAlbum, error)

FavoriteAlbums lists saved library albums and any pasted album links.

func (*AppleMusic) Forget

func (a *AppleMusic) Forget() error

Forget clears the owner's account credentials and links in memory and removes the persisted owner file, leaving any configured download helper intact.

func (*AppleMusic) HelperConfig

func (a *AppleMusic) HelperConfig() AppleMusicHelperConfig

func (*AppleMusic) HelperLogin2FA

func (a *AppleMusic) HelperLogin2FA(ctx context.Context, code string) (AppleMusicHelperStatus, error)

func (*AppleMusic) HelperLoginBegin

func (a *AppleMusic) HelperLoginBegin(ctx context.Context, username, password string) (AppleMusicHelperStatus, error)

func (*AppleMusic) HelperStatus

func (a *AppleMusic) HelperStatus(ctx context.Context) AppleMusicHelperStatus

func (*AppleMusic) Load

func (a *AppleMusic) Load() error

Load reads the saved owner login; a missing file is no login.

func (*AppleMusic) Logout

func (a *AppleMusic) Logout() error

Logout clears the owner's account credentials on sign-out.

func (*AppleMusic) Owner

func (a *AppleMusic) Owner() AppleMusicOwner

Owner is the saved login, for the phone page to amend.

func (*AppleMusic) Playlists

func (a *AppleMusic) Playlists(ctx context.Context) ([]Playlist, error)

Playlists lists the saved links first, then the library. One broken link does not hide the others.

func (*AppleMusic) ProbeHelper

func (a *AppleMusic) ProbeHelper(ctx context.Context, cooldown time.Duration) AppleMusicHelperStatus

ProbeHelper checks helper status at most once per cooldown when unready so an offline helper does not stall every gateway browse or search request.

func (*AppleMusic) Ready

func (a *AppleMusic) Ready() bool

Ready reports whether there is anything to show: a link, a library login, or an active helper session.

func (*AppleMusic) Search

func (a *AppleMusic) Search(ctx context.Context, query string) ([]Track, error)

Search looks up songs in the owner's storefront; no account is needed.

func (*AppleMusic) SearchPlaylists

func (a *AppleMusic) SearchPlaylists(ctx context.Context, query string) ([]Playlist, error)

SearchPlaylists looks up catalog playlists in the owner's storefront.

func (*AppleMusic) SetHelper

func (a *AppleMusic) SetHelper(helperURL, loginURL, token string)

func (*AppleMusic) SetOwner

func (a *AppleMusic) SetOwner(ctx context.Context, o AppleMusicOwner) error

SetOwner checks and saves a login from the phone page. Links that do not open are refused, so a typo never becomes an empty playlist on the deck.

func (*AppleMusic) Tracks

func (a *AppleMusic) Tracks(ctx context.Context, id string) ([]Track, error)

type AppleMusicAlbum

type AppleMusicAlbum struct {
	ID         string
	ListID     string
	Name       string
	ArtistName string
	TrackCount int
}

AppleMusicAlbum is a saved album from the owner's library or pasted album links.

type AppleMusicAudio

type AppleMusicAudio struct {
	Path       string
	SampleRate int
	Channels   int
	Bits       int
	Lossless   bool
}

Download asks the enginex-amd helper for a FLAC of t. The helper owns the Apple Music session; the deck only receives the finished file. AppleMusicAudio is the helper's finished file and quality.

type AppleMusicHelperConfig

type AppleMusicHelperConfig struct {
	URL      string `json:"url"`
	LoginURL string `json:"loginUrl"`
	Token    string `json:"token"`
}

AppleMusicHelperConfig is persisted separately from the browsing account.

type AppleMusicHelperStatus

type AppleMusicHelperStatus struct {
	Configured bool   `json:"configured"`
	Online     bool   `json:"online"`
	SignedIn   bool   `json:"signedIn"`
	LoginState string `json:"loginState"`
	Message    string `json:"message"`
	Error      string `json:"error,omitempty"`
}
type AppleMusicLink struct{ Storefront, Kind, ID string }

AppleMusicLink is one parsed music.apple.com playlist or album address.

func ParseAppleMusicLinks(text string) []AppleMusicLink

ParseAppleMusicLinks finds every playlist or album link in pasted text, as Share → Copy Link gives them. Unknown text is ignored.

func (AppleMusicLink) URL

func (l AppleMusicLink) URL() string

URL is the short form saved for the owner.

type AppleMusicOwner

type AppleMusicOwner struct {
	Links      []string `json:"links,omitempty"`
	UserToken  string   `json:"mediaUserToken,omitempty"`
	Storefront string   `json:"storefront,omitempty"`
	DevToken   string   `json:"developerToken,omitempty"` // optional override of the web player's token
}

AppleMusicOwner is what the phone page saves.

type AudioFeatures

type AudioFeatures struct {
	ID               string  `json:"id"`
	Energy           float64 `json:"energy"`
	Danceability     float64 `json:"danceability"`
	Valence          float64 `json:"valence"`
	Acousticness     float64 `json:"acousticness"`
	Instrumentalness float64 `json:"instrumentalness"`
	Speechiness      float64 `json:"speechiness"`
	Liveness         float64 `json:"liveness"`
	Tempo            float64 `json:"tempo"`
}

AudioFeatures represents the audio feature metrics returned by ReccoBeats.

func ExtractReccoBeatsAudioFeatures

func ExtractReccoBeatsAudioFeatures(ctx context.Context, client *http.Client, baseURL string, audio io.Reader) (AudioFeatures, error)

ExtractReccoBeatsAudioFeatures extracts audio features from an audio stream via POST /v1/analysis/audio-features.

func FetchReccoBeatsAudioFeatures

func FetchReccoBeatsAudioFeatures(ctx context.Context, client *http.Client, baseURL, trackID string) (AudioFeatures, error)

FetchReccoBeatsAudioFeatures retrieves the audio features for a given track ID via GET /v1/track/{id}/audio-features.

func FilterByAudioFeatures

func FilterByAudioFeatures(items []AudioFeatures, minEnergy, maxEnergy, minDance, maxDance, minValence, maxValence float64) []AudioFeatures

FilterByAudioFeatures filters items by energy, danceability, and valence min/max bounds.

type BPMConfig

type BPMConfig struct {
	SoundCloudClientID string `json:"soundcloudClientId,omitempty"`
	SoundCloudSecret   string `json:"soundcloudClientSecret,omitempty"`
	SoundCloudToken    string `json:"soundcloudToken,omitempty"`
	GetSongBPMKey      string `json:"getSongBpmKey,omitempty"`
}

BPMConfig holds the optional keys of services that need one.

type BPMInfo

type BPMInfo struct {
	BPM float64 `json:"bpm"`
	Key string  `json:"key,omitempty"`
	// Measured marks a value analysed from the audio file on this deck. Catalog
	// values are only a preview for list rows and can never replace it.
	Measured bool `json:"measured,omitempty"`
}

type BPMStore

type BPMStore struct {
	Path, ConfigPath string
	HTTP             *http.Client
	ReccoURL         string
	SoundCloudURL    string
	GetSongURL       string
	DeezerURL        string
	// SoundCloudAuth is the token store shared with the SoundCloud source.
	SoundCloudAuth *SoundCloudAuth
	// Spotify returns the owner's login, if any, for finding a track's IDs.
	Spotify func() *Spotify
	// PreviewBPM estimates tempo and key from a preview clip, for tracks too new
	// for any catalog. It is the last resort and never replaces a measured value.
	PreviewBPM func(ctx context.Context, previewURL string) BPMInfo
	// PreviewAllowed overrides the accepted clip hosts in tests.
	PreviewAllowed func(*url.URL) bool
	// contains filtered or unexported fields
}

func (*BPMStore) Apply

func (b *BPMStore) Apply(tracks []Track)

Apply fills in what is already known.

func (*BPMStore) Config

func (b *BPMStore) Config() BPMConfig

Config reads the optional service keys.

func (*BPMStore) Enrich

func (b *BPMStore) Enrich(ctx context.Context, tracks []Track)

Enrich fills a list in place from the cache and one quick batch lookup. Lists must open at once, so everything else is looked up behind the scenes and shows the next time the list opens.

func (*BPMStore) Put

func (b *BPMStore) Put(t Track, info BPMInfo) error

Put records a tempo for a track. A measured value replaces a looked-up one, and never the other way round.

func (*BPMStore) SaveConfig

func (b *BPMStore) SaveConfig(v BPMConfig) error

SaveConfig writes the optional service keys under b.mu so concurrent readers and writers serialize cleanly.

func (*BPMStore) UpdateConfig

func (b *BPMStore) UpdateConfig(fn func(*BPMConfig)) error

UpdateConfig atomically reads, modifies, and writes BPMConfig under b.mu.

type Beatport

type Beatport struct {
	BaseURL string
	HTTP    *http.Client
	Path    string
	// contains filtered or unexported fields
}

Beatport is one account. Path keeps its login (0600); empty keeps it in memory. The owner's instance is shared, because every refresh replaces the refresh token.

func (*Beatport) Download

func (b *Beatport) Download(ctx context.Context, id string, lossless bool) (location, ext string, err error)

Download finds the signed address of a track's file at the best quality the subscription allows: FLAC, then 256k AAC (Professional), then 128k AAC (Advanced). ext is flac or mp4. Essential gets none of them and uses SaveStream instead.

func (*Beatport) Forget

func (b *Beatport) Forget() error

Forget drops the login, in memory and on disk.

func (*Beatport) Login

func (b *Beatport) Login(ctx context.Context, username, password string) error

Login signs in as Beatport's website does, then exchanges the session for an API token. The password is not kept; when the refresh token runs out, the owner logs in again.

func (*Beatport) Playlists

func (b *Beatport) Playlists(ctx context.Context) ([]Playlist, error)

Playlists lists the account's own playlists, then Beatport's newest charts, so a new account still has something to browse.

func (*Beatport) Ready

func (b *Beatport) Ready() bool

Ready reports whether there is a login.

func (*Beatport) SaveStream

func (b *Beatport) SaveStream(ctx context.Context, id string, w io.WriteSeeker) error

SaveStream writes a track's stream to w as an MP4 file.

func (*Beatport) Search

func (b *Beatport) Search(ctx context.Context, query string) ([]Track, error)

func (*Beatport) SetToken

func (b *Beatport) SetToken(t BeatportToken) error

SetToken replaces the login and saves it.

func (*Beatport) Token

func (b *Beatport) Token() BeatportToken

Token returns the current login, which the relay hands on to the deck.

func (*Beatport) Tracks

func (b *Beatport) Tracks(ctx context.Context, id string) ([]Track, error)

type BeatportToken

type BeatportToken struct {
	Access  string    `json:"access_token"`
	Refresh string    `json:"refresh_token,omitempty"`
	Expiry  time.Time `json:"expiry,omitzero"`
}

BeatportToken is an account login. Expiry is zero when unknown (a pasted token).

func ParseBeatportToken

func ParseBeatportToken(text string) (BeatportToken, error)

ParseBeatportToken reads a pasted token: the JSON Beatport's token endpoint returns, or the bare access token.

type Deezer

type Deezer struct {
	BaseURL string
	UserID  string
	// ARL is the owner's Deezer login cookie, kept with the linked profile.
	ARL string
	// GatewayURL overrides https://www.deezer.com in tests.
	GatewayURL string
	HTTP       *http.Client
}

func (*Deezer) ByID

func (d *Deezer) ByID(ctx context.Context, id string) (Track, error)

func (*Deezer) ByISRC

func (d *Deezer) ByISRC(ctx context.Context, isrc string) (Track, error)

func (*Deezer) ChartPlaylists

func (d *Deezer) ChartPlaylists(ctx context.Context) ([]Playlist, error)

func (*Deezer) IdentifyARL

func (d *Deezer) IdentifyARL(ctx context.Context, arl string) (string, error)

IdentifyARL asks Deezer whose login cookie this is, and never echoes it.

func (*Deezer) Playlists

func (d *Deezer) Playlists(ctx context.Context) ([]Playlist, error)

func (*Deezer) ResolveUser

func (d *Deezer) ResolveUser(ctx context.Context, raw string) (string, error)

ResolveUser finds the user ID in an ID, a profile or playlist link, or a short link, whose redirects are followed only within Deezer's own hosts.

func (*Deezer) Search

func (d *Deezer) Search(ctx context.Context, query string) ([]Track, error)

func (*Deezer) SearchPlaylists

func (d *Deezer) SearchPlaylists(ctx context.Context, query string) ([]Playlist, error)

func (*Deezer) Tracks

func (d *Deezer) Tracks(ctx context.Context, id string) ([]Track, error)

type NASConfig

type NASConfig struct {
	Protocol string `json:"protocol"` // "webdav", "subsonic", "plex", "smb"
	URL      string `json:"url"`      // e.g. "https://nas.example.com/music" or "http://192.168.1.10:4533"
	Username string `json:"username,omitempty"`
	Password string `json:"password,omitempty"`
	Token    string `json:"token,omitempty"` // Plex X-Plex-Token or Bearer token
	Enabled  bool   `json:"enabled"`
}

type Netease

type Netease struct {
	BaseURL    string
	WebURL     string // overrides https://music.163.com in tests
	HTTP       *http.Client
	CookiePath string

	Cookie string
	UserID int64
	// contains filtered or unexported fields
}

Netease speaks to music.163.com directly, or to a NeteaseCloudMusicApi-compatible service when BaseURL is set.

func (*Netease) AudioURL

func (n *Netease) AudioURL(ctx context.Context, id string, lossless, allowLossy bool) (string, error)

AudioURL returns the address NetEase gives this account for a track at the best quality on offer, starting at 320k MP3 unless lossless is wanted. Previews never count: a DJ must not load 30 seconds of a song. When lossy audio is forbidden, a lossless request never tries the MP3 levels.

func (*Netease) BeginQR

func (n *Netease) BeginQR(ctx context.Context) (QRLogin, error)

func (*Netease) FavoriteAlbums

func (n *Netease) FavoriteAlbums(ctx context.Context) ([]Album, error)

FavoriteAlbums lists the albums the account has saved.

func (*Netease) LoggedIn

func (n *Netease) LoggedIn() bool

LoggedIn reports whether a user cookie is bound, safe against concurrent login.

func (*Netease) Playlists

func (n *Netease) Playlists(ctx context.Context) ([]Playlist, error)

func (*Netease) PollQR

func (n *Netease) PollQR(ctx context.Context, key string) (int, error)

func (*Netease) Search

func (n *Netease) Search(ctx context.Context, query string) ([]Track, error)

func (*Netease) SearchPlaylists

func (n *Netease) SearchPlaylists(ctx context.Context, query string) ([]Playlist, error)

func (*Netease) Tracks

func (n *Netease) Tracks(ctx context.Context, id string) ([]Track, error)

type Playlist

type Playlist struct {
	ID    string `json:"id"`
	Title string `json:"title"`
	Count int    `json:"count"`
}

type Provider

type Provider interface {
	Playlists(context.Context) ([]Playlist, error)
	Tracks(context.Context, string) ([]Track, error)
}

Listing methods may return an ordered successful prefix together with an error. A non-nil error means the list is incomplete, including auth failures.

type QRLogin

type QRLogin struct {
	Key  string `json:"key"`
	URL  string `json:"url"`
	Code int    `json:"code"`
}

type RateLimited

type RateLimited struct{ RetryAfter time.Duration }

RateLimited is a 429 with the wait its Retry-After header asked for (0: none given). It reads and matches as StatusError(429), so older checks still hold.

func (*RateLimited) As

func (e *RateLimited) As(target any) bool

func (*RateLimited) Error

func (e *RateLimited) Error() string

func (*RateLimited) Is

func (e *RateLimited) Is(target error) bool

type SelfHostedProvider

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

func NewSelfHostedProvider

func NewSelfHostedProvider(cfg NASConfig, c *http.Client) *SelfHostedProvider

func (*SelfHostedProvider) Config

func (p *SelfHostedProvider) Config() NASConfig

func (*SelfHostedProvider) DownloadTrack

func (p *SelfHostedProvider) DownloadTrack(ctx context.Context, trackID, destDir string) (string, error)

func (*SelfHostedProvider) PlaylistTracks

func (p *SelfHostedProvider) PlaylistTracks(ctx context.Context, playlistID string) ([]Track, error)

func (*SelfHostedProvider) Playlists

func (p *SelfHostedProvider) Playlists(ctx context.Context) ([]Playlist, error)

func (*SelfHostedProvider) Search

func (p *SelfHostedProvider) Search(ctx context.Context, query string) ([]Track, error)

func (*SelfHostedProvider) Tracks

func (p *SelfHostedProvider) Tracks(ctx context.Context, playlistID string) ([]Track, error)

Tracks implements the Provider interface.

type SoundCloud

type SoundCloud struct {
	BaseURL  string
	HTTP     *http.Client
	ClientID string
	Secret   string
	Token    string // a user's own token, which also reaches private content
	Auth     *SoundCloudAuth
	UserID   int64
	Username string
	WebURL   string // overrides the web API in tests
	SiteURL  string // overrides soundcloud.com in tests
	// contains filtered or unexported fields
}

func (*SoundCloud) HasGoPlus

func (s *SoundCloud) HasGoPlus(ctx context.Context) bool

HasGoPlus reports whether the logged-in account has a Go/Go+ subscription, which is what makes preview-only (SNIP) tracks play in full. An app token or public profile never does. A failed /me lookup counts as no and is retried.

func (*SoundCloud) Identify

func (s *SoundCloud) Identify(ctx context.Context) error

Identify fills in the account behind a user's token. An app token has no user.

func (*SoundCloud) Media

func (s *SoundCloud) Media(ctx context.Context, id string, lossless bool) (SoundCloudMedia, error)

Media finds where to download a track's whole audio from. The preview address is never used, however it is offered. Lossless also looks for the original upload, which is far larger: a stream of an hour-long set is 60 MB, the WAV 600 MB.

func (*SoundCloud) Playlists

func (s *SoundCloud) Playlists(ctx context.Context) ([]Playlist, error)

Playlists lists Likes, the account's own playlists, then the ones it liked.

func (*SoundCloud) ResolveUser

func (s *SoundCloud) ResolveUser(ctx context.Context, raw string) error

ResolveUser finds a profile from a link, a share link or a username. An app token is enough, since profiles are public.

func (*SoundCloud) Search

func (s *SoundCloud) Search(ctx context.Context, query string) ([]Track, error)

func (*SoundCloud) SearchPlaylists

func (s *SoundCloud) SearchPlaylists(ctx context.Context, query string) ([]Playlist, error)

func (*SoundCloud) Tracks

func (s *SoundCloud) Tracks(ctx context.Context, id string) ([]Track, error)

type SoundCloudAuth

type SoundCloudAuth struct {
	TokenURL string
	Path     string
	HTTP     *http.Client
	// contains filtered or unexported fields
}

SoundCloudAuth exchanges an app's credentials for an access token. SoundCloud limits how often that may happen, so the token is shared and kept in a file.

func (*SoundCloudAuth) HasUser

func (a *SoundCloudAuth) HasUser() bool

HasUser reports whether the owner logged in with an account.

func (*SoundCloudAuth) SetUser

func (a *SoundCloudAuth) SetUser(access, refresh string, expiry time.Time) error

SetUser stores the owner's account login. Empty values clear it.

func (*SoundCloudAuth) Token

func (a *SoundCloudAuth) Token(ctx context.Context, id, secret string) (string, error)

Token returns a valid access token for the app.

func (*SoundCloudAuth) UserToken

func (a *SoundCloudAuth) UserToken(ctx context.Context, id, secret string) (string, error)

UserToken returns the owner's token, renewing it when it is about to expire. The lock also keeps two callers from spending the same rotating refresh token.

type SoundCloudMedia

type SoundCloudMedia struct {
	Ext  string // mp3, or mp4 for AAC
	URLs []string
	// Original is the uploader's own file (often WAV or FLAC), offered only when
	// lossless was asked for and the uploader allows downloads.
	Original string
}

SoundCloudMedia is a track's audio: one address, or a list of segments to join.

type Spotify

type Spotify struct {
	BaseURL, AccountsURL, ClientID, TokenPath string
	CredsPath, DeviceID                       string

	StreamURL           string
	LinksPath, EmbedURL string // public playlist links (spotify_links.go)
	AudioKey            []byte
	HTTP                *http.Client

	Token Token
	// contains filtered or unexported fields
}

func (*Spotify) AcceptToken

func (s *Spotify) AcceptToken(ctx context.Context, t Token) error

func (*Spotify) BeginDeviceAuth

func (s *Spotify) BeginDeviceAuth(ctx context.Context) (*SpotifyDeviceAuth, error)

func (*Spotify) BeginPKCE

func (s *Spotify) BeginPKCE(state, redirect string) (authURL, verifier string)

BeginPKCE returns an authorization URL and a private verifier. The caller binds state, verifier, redirect URI and expiry to the initiating session.

func (*Spotify) Close

func (s *Spotify) Close()

func (*Spotify) CompletePKCE

func (s *Spotify) CompletePKCE(ctx context.Context, code, verifier, redirect string) error

func (*Spotify) ConnectZeroconf

func (s *Spotify) ConnectZeroconf(ctx context.Context, username string, blob []byte) error

ConnectZeroconf accepts the decrypted outer DH payload. ConnectBlob implements the inner SHA1(deviceID)/PBKDF2/AES-192-ECB/XOR authentication envelope.

func (*Spotify) DeviceAuthorizationEnabled

func (s *Spotify) DeviceAuthorizationEnabled() bool

func (*Spotify) DownloadAudio

func (p *Spotify) DownloadAudio(ctx context.Context, trackID, dstDir string) (string, error)

DownloadAudio fetches audio stream for trackID and writes it to dstDir as spotify-<trackID>.ogg.

func (*Spotify) ExchangeOAuthCredentials

func (s *Spotify) ExchangeOAuthCredentials(ctx context.Context) error

ExchangeOAuthCredentials turns streaming-scoped OAuth into reusable AP login. Custom HTTP endpoints retain the offline test/PKCE path.

func (s *Spotify) HasLinks() bool

HasLinks reports whether any public playlist link is saved.

func (*Spotify) HasStoredCredentials

func (s *Spotify) HasStoredCredentials() bool

func (*Spotify) HasToken

func (s *Spotify) HasToken() bool

HasToken reports whether a login token is present, safe against concurrent refresh.

func (*Spotify) LoadToken

func (s *Spotify) LoadToken() error

LoadToken accepts the common OAuth2 expiry string and numeric expires_at.

func (*Spotify) Logout

func (s *Spotify) Logout() error

func (*Spotify) Playlists

func (s *Spotify) Playlists(ctx context.Context) ([]Playlist, error)

func (*Spotify) PollDeviceAuthorization

func (s *Spotify) PollDeviceAuthorization(ctx context.Context, d *SpotifyDeviceAuth) (bool, error)

PollDeviceAuthorization makes at most one request, honoring interval/slow_down.

func (*Spotify) Search

func (s *Spotify) Search(ctx context.Context, query string) ([]Track, error)

func (*Spotify) SearchPlaylists

func (s *Spotify) SearchPlaylists(ctx context.Context, query string) ([]Playlist, error)

func (*Spotify) SetClientID

func (s *Spotify) SetClientID(id string)

SetClientID serializes app changes with OAuth token refresh.

func (s *Spotify) SetLinks(ctx context.Context, text string) (int, error)

SetLinks replaces the saved public playlists with those named in text and returns how many were read. A link that cannot be read fails the whole call.

func (*Spotify) SetToken

func (s *Spotify) SetToken(t Token) error

SetToken installs and saves a token obtained elsewhere, such as the cloud relay.

func (*Spotify) Tracks

func (s *Spotify) Tracks(ctx context.Context, id string) ([]Track, error)

type SpotifyConnectInfo

type SpotifyConnectInfo struct {
	Status         int    `json:"status"`
	StatusString   string `json:"statusString"`
	SpotifyError   int    `json:"spotifyError"`
	Version        string `json:"version"`
	DeviceID       string `json:"deviceID"`
	RemoteName     string `json:"remoteName"`
	PublicKey      string `json:"publicKey"`
	DeviceType     string `json:"deviceType"`
	LibraryVersion string `json:"libraryVersion"`
	AccountReq     string `json:"accountReq"`
	TokenType      string `json:"tokenType"`
	Scope          string `json:"scope"`
}

SpotifyConnectInfo represents the Zeroconf getInfo response payload.

type SpotifyConnectKey

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

SpotifyConnectKey is this process's Zeroconf key pair.

func SpotifyConnectKeyPair

func SpotifyConnectKeyPair() *SpotifyConnectKey

SpotifyConnectKeyPair returns the key pair, generated once per process.

func (*SpotifyConnectKey) DecryptBlob

func (k *SpotifyConnectKey) DecryptBlob(clientKey, blob string) ([]byte, error)

DecryptBlob opens addUser's blob with the phone's clientKey: iv(16) | AES-128-CTR data | HMAC-SHA1(20), keyed from SHA1 of the shared secret. A wrong MAC is an error.

func (*SpotifyConnectKey) PublicKey

func (k *SpotifyConnectKey) PublicKey() string

PublicKey is what getInfo advertises.

type SpotifyConnectResponse

type SpotifyConnectResponse struct {
	Status       int    `json:"status"`
	StatusString string `json:"statusString"`
	SpotifyError int    `json:"spotifyError"`
}

SpotifyConnectResponse represents standard response for Spotify Connect operations.

type SpotifyConnectUser

type SpotifyConnectUser struct {
	Action      string `json:"action"`
	UserName    string `json:"userName"`
	Blob        string `json:"blob"`
	AccessToken string `json:"accessToken"`
	ClientKey   string `json:"clientKey"`
}

SpotifyConnectUser represents the Zeroconf addUser request payload.

type SpotifyDeviceAuth

type SpotifyDeviceAuth struct {
	VerificationURL string
	UserCode        string
	Expires         time.Time
	// contains filtered or unexported fields
}

SpotifyDeviceAuth keeps the private device code out of JSON/UI responses.

type StatusError

type StatusError int

StatusError is a refused request's HTTP status, so callers can tell 401 or 404 apart.

func (StatusError) Error

func (e StatusError) Error() string

type Token

type Token struct {
	Scope        string    `json:"scope,omitempty"`
	Username     string    `json:"username,omitempty"`
	AccessToken  string    `json:"access_token"`
	RefreshToken string    `json:"refresh_token,omitempty"`
	TokenType    string    `json:"token_type,omitempty"`
	ExpiresIn    int64     `json:"expires_in,omitempty"`
	Expiry       time.Time `json:"expiry,omitempty"`
	ExpiresAt    int64     `json:"expires_at,omitempty"`
	ClientID     string    `json:"client_id,omitempty"`
}

type Track

type Track struct {
	ID         string   `json:"id"`
	CatalogID  string   `json:"catalogId,omitempty"`
	Title      string   `json:"title"`
	Artist     string   `json:"artist"`
	Artists    []string `json:"artists,omitempty"`
	Album      string   `json:"album,omitempty"`
	ISRC       string   `json:"isrc,omitempty"`
	DurationMS int64    `json:"durationMs"`
	Provider   string   `json:"provider"`
	BPM        float64  `json:"bpm,omitempty"`
	Key        string   `json:"key,omitempty"`    // Camelot, e.g. 8A
	Rating     int      `json:"rating,omitempty"` // 1-5 stars
	// PreviewOnly marks a SoundCloud Go+ track that plays only a preview without a Go+ login.
	PreviewOnly bool `json:"previewOnly,omitempty"`
	// CoverURL is the album artwork, embedded in the downloaded file for the deck.
	CoverURL string `json:"coverUrl,omitempty"`
	// ThumbURL is a smaller version for list rows, where the service offers one.
	ThumbURL string `json:"-"`
	// Preview is Deezer's public 30-second MP3, used only to estimate tempo.
	Preview string `json:"-"`
}

Jump to

Keyboard shortcuts

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