ca

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2018 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package ca (Cover Art) is responsible for getting cover art for albums over the internet.

It does that by first querying the MusicBrainz web service for a releaseID using the artist name and album name. Then using this ID it quries the Cover Art Archive for the corresponding album front art.

The two APIs in questin are as follows:

Index

Constants

This section is empty.

Variables

View Source
var ErrImageNotFound = errors.New("image not found")

ErrImageNotFound is returned by the Get* functions when no suitable cover image was found anywhere.

Functions

This section is empty.

Types

type Client

type Client struct {
	sync.Mutex

	// MinScore is the minimal accepted score above which a release is considered
	// a match for the search in the Music Brainz API. The API returns a list of
	// matches and every one of them comes with a "score" metric in 0-100 scale
	// which represents how good a match is this result for the query. 100 means
	// absolutely sure. By lowering this score you may receive more images but
	// some of them may be inaccurate.
	MinScore int
	// contains filtered or unexported fields
}

Client is a client for the Cover Arts Archive. It supports getting images from the Cover Arts Archive and automatically throttles itself so that it does not make too many requests at once. It is safe for concurrent use.

It works in two steps:

* Gets a list of mbids (aka release IDs) from the Music Brainz API which are above MinScore.

* Uses the mbids for fetching a cover art from the Cover Art Archive. The first release ID which has a cover art wins.

Why a list of mbids? Because a certain album may have many records in Music Brainz which correspond to different releases for this album. Perhaps for multiple years or countries. Generally all releases have the same cover art. So we accept any of them.

It implements CovertArtFinder.

func NewClient

func NewClient(useragent string, delay time.Duration) *Client

NewClient returns fully configured Client.

The kind people at MusicBrainz provide their API at no cost for everyone to use. For that reason they have kindly asked for all applications to throttle their usage as much as possible and do not exceed one request per second. So we are good citizen and throttle ourselves. More info: https://musicbrainz.org/doc/XML_Web_Service/Rate_Limiting For this reason the delayer and delay are defined here.

Throttling is done with the help of the arguments `useragent` and a `delay`. The user agent is used for representing itself when contacting the Music Brainz API. It is required so that they can use it for throttling and filtering out bad applications. The delay is used to throttle requests to the API. No more than one request per `delay` will be made.

func (*Client) GetFrontImage

func (c *Client) GetFrontImage(
	ctx context.Context,
	artist,
	album string,
) (CoverArtImage, error)

GetFrontImage returns the front image for particular `album` from `artist`.

type CoverArtImage

type CoverArtImage = cca.CoverArtImage

CoverArtImage represents a cover image from the Cover Arts Archive.

type CovertArtFinder

type CovertArtFinder interface {
	GetFrontImage(ctx context.Context, artist, album string) (CoverArtImage, error)
}

CovertArtFinder defines a type which is capable of finding

Jump to

Keyboard shortcuts

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