spotify

package
v0.0.0-...-dc15420 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultHeaders = http.Header{
		"Host":                      {"open.spotify.com"},
		"Connection":                {"keep-alive"},
		"Upgrade-Insecure-Requests": {"1"},
		"User-Agent":                {"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:148.0) Gecko/20100101 Firefox/148.0"},
		"Accept":                    {"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"},
		"Accept-Encoding":           {"gzip, deflate, br, zstd"},
		"Accept-Language":           {"en-US,en;q=0.9"},
		"Priority":                  {"u=0, i"},
		"Sec-Fetch-Dest":            {"document"},
		"Sec-Fetch-Mode":            {"navigate"},
		"Sec-Fetch-Site":            {"none"},
		"Sec-Fetch-User":            {"?1"},

		http.HeaderOrderKey: {
			"Host",
			"Connection",
			"Upgrade-Insecure-Requests",
			"User-Agent",
			"Accept",
			"Accept-Encoding",
			"Accept-Language",
			"Priority",
			"Sec-Fetch-Dest",
			"Sec-Fetch-Mode",
			"Sec-Fetch-Site",
			"Sec-Fetch-User",
		},
	}
)
View Source
var DefaultPlaylist = "https://open.spotify.com/playlist/46zFIvDlqCi1iNdZVTtGAp" // random hyperpop playlist I found LOL

Functions

func DecodeSecret

func DecodeSecret(cipher string) []byte

func FetchBundleURL

func FetchBundleURL(ctx context.Context) (string, error)

func FetchServerTime

func FetchServerTime(ctx context.Context) (*int64, error)

func GenerateTotp

func GenerateTotp(secret []byte, timestamp int64) string

Types

type AccessTokenResponse

type AccessTokenResponse struct {
	ClientID                         string `json:"clientId"`
	AccessToken                      string `json:"accessToken"`
	AccessTokenExpirationTimestampMs int64  `json:"accessTokenExpirationTimestampMs"`
	IsAnonymous                      bool   `json:"isAnonymous"`
	Notes                            string `json:"_notes,omitempty"`
}

type AddedAt

type AddedAt struct {
	ISOString string `json:"isoString"`
}

type AlbumOfTrack

type AlbumOfTrack struct {
	Name     string      `json:"name"`
	URI      string      `json:"uri"`
	Artists  ArtistItems `json:"artists"`
	CoverArt CoverArt    `json:"coverArt"`
}

type ArtistItem

type ArtistItem struct {
	URI     string        `json:"uri"`
	Profile ArtistProfile `json:"profile"`
}

type ArtistItems

type ArtistItems struct {
	Items []ArtistItem `json:"items"`
}

type ArtistProfile

type ArtistProfile struct {
	Name string `json:"name"`
}

type Client

type Client struct {
	AccessTokenResponse AccessTokenResponse
	ClientTokenResponse ClientTokenResponse
	// contains filtered or unexported fields
}

func NewClient

func NewClient() (*Client, error)

func (*Client) GetAccessToken

func (c *Client) GetAccessToken() (AccessTokenResponse, error)

func (*Client) GetClientToken

func (c *Client) GetClientToken() (ClientTokenResponse, error)

func (*Client) GetPlaylist

func (c *Client) GetPlaylist(playlistID string) (*PlaylistResponse, error)

func (*Client) Setup

func (c *Client) Setup() error

type ClientTokenResponse

type ClientTokenResponse struct {
	GrantedTokenResponse GrantedTokenResponse `json:"granted_token"`
}

type ContentRating

type ContentRating struct {
	Label string `json:"label"`
}

type CoverArt

type CoverArt struct {
	Sources []ImageSource `json:"sources"`
}

type GrantedTokenResponse

type GrantedTokenResponse struct {
	Token string `json:"token"`
}

type ImageSource

type ImageSource struct {
	Height int    `json:"height"`
	Width  int    `json:"width"`
	URL    string `json:"url"`
}

type PagingInfo

type PagingInfo struct {
	Limit  int `json:"limit"`
	Offset int `json:"offset"`
}

type Playability

type Playability struct {
	Playable bool   `json:"playable"`
	Reason   string `json:"reason"`
}

type PlaylistContentPage

type PlaylistContentPage struct {
	Typename   string         `json:"__typename"`
	Items      []PlaylistItem `json:"items"`
	PagingInfo PagingInfo     `json:"pagingInfo"`
	TotalCount int            `json:"totalCount"`
}

type PlaylistData

type PlaylistData struct {
	PlaylistV2 PlaylistV2 `json:"playlistV2"`
}

type PlaylistItem

type PlaylistItem struct {
	UID     string         `json:"uid"`
	AddedAt AddedAt        `json:"addedAt"`
	ItemV2  TrackWrapperV2 `json:"itemV2"`
}

type PlaylistResponse

type PlaylistResponse struct {
	Data PlaylistData `json:"data"`
}

func (*PlaylistResponse) Tracks

func (p *PlaylistResponse) Tracks() []TrackData

type PlaylistV2

type PlaylistV2 struct {
	Typename    string              `json:"__typename"`
	Name        string              `json:"name"`
	Description string              `json:"description"`
	URI         string              `json:"uri"`
	Followers   int                 `json:"followers"`
	Content     PlaylistContentPage `json:"content"`
	SharingInfo SharingInfo         `json:"sharingInfo"`
}

type SecretEntry

type SecretEntry struct {
	Version int    `json:"version"`
	Cipher  string `json:"cipher"`
}

func FetchSecrets

func FetchSecrets(ctx context.Context, bundleURL string) ([]SecretEntry, error)

func PickActiveSecret

func PickActiveSecret(secrets []SecretEntry, version int) (SecretEntry, error)

type SharingInfo

type SharingInfo struct {
	ShareID  string `json:"shareId"`
	ShareURL string `json:"shareUrl"`
}

type TotpResult

type TotpResult struct {
	Version    int    `json:"version"`
	Totp       string `json:"totp"`
	TotpServer string `json:"totpServer"`
	ClientTime int64  `json:"clientTime"`
	ServerTime *int64 `json:"serverTime,omitempty"`
	Cipher     string `json:"-"`
}

func BuildTotp

func BuildTotp(ctx context.Context, version int, bundleURL string) (TotpResult, error)

type TrackData

type TrackData struct {
	Typename      string        `json:"__typename"`
	Name          string        `json:"name"`
	URI           string        `json:"uri"`
	TrackNumber   int           `json:"trackNumber"`
	DiscNumber    int           `json:"discNumber"`
	Playcount     string        `json:"playcount"`
	MediaType     string        `json:"mediaType"`
	TrackDuration TrackDuration `json:"trackDuration"`
	Artists       ArtistItems   `json:"artists"`
	AlbumOfTrack  AlbumOfTrack  `json:"albumOfTrack"`
	Playability   Playability   `json:"playability"`
	ContentRating ContentRating `json:"contentRating"`
}

func (TrackData) AlbumArtistNames

func (t TrackData) AlbumArtistNames() []string

func (TrackData) ArtistNames

func (t TrackData) ArtistNames() []string

func (TrackData) LargestCoverURL

func (t TrackData) LargestCoverURL() string

func (TrackData) TrackID

func (t TrackData) TrackID() string

type TrackDuration

type TrackDuration struct {
	TotalMilliseconds int `json:"totalMilliseconds"`
}

type TrackWrapperV2

type TrackWrapperV2 struct {
	Typename string    `json:"__typename"`
	Data     TrackData `json:"data"`
}

Jump to

Keyboard shortcuts

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