listenbrainz

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

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

Go to latest
Published: Jan 28, 2023 License: GPL-3.0 Imports: 5 Imported by: 2

README

go-listenbrainz

This is a Go package to wrap the ListenBrainz API.

TODO
[ ] add more tests
[ ] wrap the API to check a profile

Documentation

Index

Constants

View Source
const (
	// Maximum overall listen size in bytes, to prevent egregious spamming.
	MaxListenSize = 10240
	// The maximum number of listens returned in a single GET request.
	MaxItemsPerGet = 100
	// The default number of listens returned in a single GET request.
	DefaultItemsPerGet = 25
	// The maximum number of tags per listen.
	MaxTagsPerListen = 50
	// The maximum length of a tag
	MaxTagSize = 64
)

source: https://listenbrainz.readthedocs.io/en/latest/dev/api.html#constants

Variables

This section is empty.

Functions

func GetListenHistory

func GetListenHistory(user string) (*http.Response, error)

GetListenHistory fetches the listen history of the given user.

func GetSubmissionTime

func GetSubmissionTime(d time.Duration) (time.Duration, error)

GetSubmissionTime returns the number of seconds after which a track should be submitted.

func SubmitPlayingNow

func SubmitPlayingNow(track Track, token string) (*http.Response, error)

SubmitPlayingNow posts the given track to ListenBrainz as what's playing now.

func SubmitRequest

func SubmitRequest(json []byte, token string) (*http.Response, error)

SubmitRequest creates and executes a request containing the JSON that's passed, to the account delineated by the token.

func SubmitSingle

func SubmitSingle(track Track, token string, time int64) (*http.Response, error)

SubmitSingle posts the given track to ListenBrainz as a single listen with the given time.

Types

type Payload

type Payload struct {
	ListenedAt int64 `json:"listened_at,omitempty"`
	Track      `json:"track_metadata"`
}

Payload is a helper struct for marshalling the JSON payload

type Payloads

type Payloads []Payload

Payloads is a helper struct for marshalling the JSON payload

type Submission

type Submission struct {
	ListenType string    `json:"listen_type"`
	Payloads   []Payload `json:"payload"`
}

Submission is a struct for marshalling the JSON payload

func FormatPlayingNow

func FormatPlayingNow(track Track) Submission

FormatPlayingNow formats a Track as a playing_now Submission.

func FormatSingle

func FormatSingle(track Track, time int64) Submission

FormatSingle formats a Track as a single Submission.

type Track

type Track struct {
	Title  string `json:"track_name"`
	Artist string `json:"artist_name"`
	Album  string `json:"release_name"`
}

Track is a helper struct for marshalling the JSON payload

Jump to

Keyboard shortcuts

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