lastfm

package
v0.0.0-...-051453a Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// MaxTracksPerScrobble is the maximum number of tracks that can be included in a single request to Scrobble
	MaxTracksPerScrobble = 50
)

Variables

This section is empty.

Functions

This section is empty.

Types

type API

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

func New

func New(cache *lazy.Value[string], key, secret, username, password string) *API

func (*API) LoveTrack

func (a *API) LoveTrack(ctx context.Context, t pianobar.Track) error

LoveTrack calls https://www.last.fm/api/show/track.love

func (*API) Scrobble

func (a *API) Scrobble(ctx context.Context, tracks ...pianobar.Track) error

Scrobble sends the provided track and all other pending scrobbles to https://www.last.fm/api/show/track.scrobble

func (*API) UnLoveTrack

func (a *API) UnLoveTrack(ctx context.Context, t pianobar.Track) error

UnLoveTrack calls https://www.last.fm/api/show/track.unlove

func (*API) UpdateNowPlaying

func (a *API) UpdateNowPlaying(ctx context.Context, t pianobar.Track) error

UpdateNowPlaying calls https://www.last.fm/api/show/track.updateNowPlaying

type Error

type Error struct {
	Code    int    `xml:"code,attr"`
	Message string `xml:",chardata"`
}

func (Error) Error

func (e Error) Error() string

type FeedbackProvider

type FeedbackProvider interface {
	// LoveTrack should be called for tracks that have received a Thumbs-Up from the user
	LoveTrack(ctx context.Context, t pianobar.Track) error
	// UnLoveTrack should be called for tracks that have been banned or un-loved by the user
	UnLoveTrack(ctx context.Context, t pianobar.Track) error
}

FeedbackProvider provides a way to translate pandora feedback on tracks to Last.FM

type Request

type Request url.Values

type Response

type Response[T any] struct {
	Status string `xml:"status,attr"`
	Error  *Error `xml:"error,omitempty"`

	Value T `xml:",any,omitempty"`
}

type ScrobbleResult

type ScrobbleResult struct {
	Accepted int `xml:"accepted,attr"`
	Ignored  int `xml:"ignored,attr"`

	Tracks []Track `xml:"scrobble"`
}

type Scrobbler

type Scrobbler interface {
	// Scrobble emits the specified tracks to Last.FM's track.Scrobble API. Tracks must meet the following criteria to be
	// accepted by Last.FM:
	//
	// * The track must be at least 30s long
	// * The track must have been played for at least half of its duration, or for at least 4 minutes
	//
	// These criteria should be checked by the caller before calling Scrobble.
	//
	// Any non-terminal error should save the tracks to be retried on the next scrobble request. Up to 50 tracks may be
	// queued for a single request. If the provided context is cancelled before the request can be made to Last.FM's API
	// it will be retried on the next request. If it is cancelled after the request has been sent but before the
	// response can be read, it will not be retried later.
	Scrobble(ctx context.Context, t ...pianobar.Track) error

	// UpdateNowPlaying submits the specified track to Last.FM's track.updateNowPlaying API
	UpdateNowPlaying(ctx context.Context, t pianobar.Track) error
}

Scrobbler sends track information to the Last.FM API as Scrobbles. It also provides a way to notify Last.FM of the track a user is currently listening to. If Scrobble returns a non-terminal error, the provided track is saved and re-tried on the next scrobble. The Last.FM API accepts up to 50 tracks in one scrobble request.

type Session

type Session struct {
	Name       string `xml:"name"`
	Key        string `xml:"key"`
	Subscriber int    `xml:"subscriber"`
}

type String

type String struct {
	Corrected bool   `xml:"corrected,attr"`
	Value     string `xml:",chardata"`
}

type Track

type Track struct {
	Track       String `xml:"track"`
	Artist      String `xml:"artist"`
	Album       String `xml:"album"`
	AlbumArtist String `xml:"albumArtist,omitempty"`
	Timestamp   int    `xml:"timestamp"`

	IgnoreReason String `xml:"ignoreMessage,omitempty"`
}

Jump to

Keyboard shortcuts

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