cddb

package module
v0.0.0-...-82af12d Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2019 License: MIT Imports: 6 Imported by: 0

README

Gracenote → FreeDB Proxy

What is this?

This is a proxy that allows FreeDB aware software to access metadata from the Gracenote CD database.

The root cddb package can also be used as a rudimentary Gracenote library.

Table of Contents

Configuration

The proxy requires a valid Gracenote Client and User ID. You can get these at https://developer.gracenote.com/web-api.

The proxy provides multiple ways to configure it's settings. Configuration values are taken with the following priority: Command line switch > Environment variable > Compile time option

Command line switches
Switch Description
-address The address to listen on
-port The port to listen on (default "8080")
-client Gracenote Client ID
-user Gracenote User ID
General Environment Variables
Variable Description
ADDR The address to listen on
PORT The port to listen on
CLIENT_KEY Gracenote Client ID
USER_KEY Gracenote User ID

CLIENT_KEY and USER_KEY can be configured for App Engine using the gracenote.yaml file in cmd/cddb.

App Engine Environment Variables

Note that the end user typically does not have to set these, they're handled by Google App Engine.

Variable Description
USING_APPENGINE Whether the program should use App Engine specific features
GOOGLE_CLOUD_PROJECT The Project ID associated with your application
GAE_SERVICE The service name of your application
GAE_VERSION The version label of the current application
Compile-time configuration

Go provides a way to set variable values at compile time, this can be used to easily change the default values for variables. This can be done using the -X linker flag during building.

This example will set the default address to 127.0.0.1 and the default port to 8888: go build -ldflags "-X main.addr=127.0.0.1 -X main.port=8888"

importpath.name Description
main.addr The address to listen on
main.port The port to listen on
github.com/Hakkin/cddb/cmd/cddb/config.Client Gracenote Client ID
github.com/Hakkin/cddb/cmd/cddb/config.User Gracenote User ID

Building + Running / Deploying

The proxy can be ran as either a standalone program or through Google App Engine.

Standalone

Simply run go build in the cmd/cddb directory. Once built, you can start the proxy by running cddb. You must supply valid Gracenote User and Client IDs (see configuration).

Google App Engine

There are multiple configuration files in cmd/cddb you must fill out before deploying to Google App Engine.

File Description
gracenote.yaml Contains your Gracenote Client and User IDs
appengine.json Contains your App Engine credentials file in JSON format

Once these are filled out, you can deploy the proxy using gcloud app deploy from cmd/cddb.

Usage

Once running, you can use the proxy by settings the FreeDB server in your client to http://[domain]/cddb, where [domain] is the address or domain the proxy is listening on (see configuration).

Some clients require additional configuration, pages have been created to help configure various clients:

Advanced Usage
Parameters

The proxy allows you to set certain parameters using the URL path: http://[domain]/cddb[/language][/country]

  • language
    • Specifies the preferred language for the returned metadata.
      For the proxy, this only affects the returned genre name.
      This should be a 3 character ISO 639-2 code.
  • country
    • Specifies the country to use for the "genre hierarchy".
      This should be a 3 character ISO 3166-1 alpha-3 code.
      Please refer to the examples below and the Gracenote API documentation for the specific use of this parameter.

Examples:


The default response:

http://[domain]/cddb
Genre: Asian Hip-Hop/Rap

Setting the language to German:

http://[domain]/cddb/ger
Genre: Asiatischer Hip-Hop/Rap

This simply translates the genre into the preferred language, but doesn't otherwise modify it.


Setting the language to English and the country to Japan:

http://[domain]/cddb/eng/jpn
Genre: Hip-Hop/Rap

Notice how with the country set to Japan, the genre no longer has the "Asian" specifier.


You can read more about the effects of these parameters on Gracenote's WebAPI Documentation: language + country

Documentation

Index

Constants

View Source
const (
	CommandFetch = "ALBUM_FETCH"
	CommandTOC   = "ALBUM_TOC"
)

Constants for supported Gracenote commands.

Variables

This section is empty.

Functions

This section is empty.

Types

type Album

type Album struct {
	ID         string  `xml:"GN_ID"`
	Artist     string  `xml:"ARTIST"`
	Title      string  `xml:"TITLE"`
	Date       int     `xml:"DATE"`
	Genre      string  `xml:"GENRE"`
	TrackCount int     `xml:"TRACK_COUNT"`
	Tracks     []Track `xml:"TRACK"`
}

type Auth

type Auth struct {
	Client string `xml:"CLIENT"`
	User   string `xml:"USER"`
}

Auth stores the required authentication strings needed to use the Gracenote API.

type Client

type Client struct {
	// Auth stores the required authentication strings needed to use
	// the Gracenote API.
	//
	// Both Client and User fields of Auth are required, an error will be
	// returned if either are empty.
	Auth Auth `xml:"AUTH"`

	// Language sets the LANG parameter of the Gracenote request.
	//
	// If Language is empty, it will be omitted from the query.
	Language string `xml:"LANG,omitempty"`

	// Country sets the COUNTRY parameter of the Gracenote request.
	//
	// If Country is empty, it will be omitted from the query.
	Country string `xml:"COUNTRY,omitempty"`

	// HTTPClient is the HTTP client used to query the Gracenote API.
	//
	// If HTTPClient is nil, http.DefaultClient is used.
	HTTPClient *http.Client `xml:"-"`
}

A client to query Gracenote.

For specifics on the effects of the Language and Country parameters, please refer to the follow articles: https://developer.gracenote.com/sites/default/files/web/webapi/Content/music-web-api/Setting%20the%20Language%20Preference.html

https://developer.gracenote.com/sites/default/files/web/webapi/Content/music-web-api/Specifying%20a%20Country%20Specific.html

func (*Client) Do

func (c *Client) Do(q *Query) (*Response, error)

func (*Client) SetAuth

func (c *Client) SetAuth(client string, user string)

func (*Client) SetCountry

func (c *Client) SetCountry(country string)

func (*Client) SetHTTPClient

func (c *Client) SetHTTPClient(httpClient *http.Client)

func (*Client) SetLanguage

func (c *Client) SetLanguage(language string)

type Query

type Query struct {
	Command string `xml:"CMD,attr"`
	ID      string `xml:"GN_ID,omitempty"`
	TOC     *TOC   `xml:"TOC,omitempty"`
}

Gracenote query

Command field is required, an error will be returned if it is empty.

func (*Query) SetCommand

func (q *Query) SetCommand(command string)

func (*Query) SetID

func (q *Query) SetID(id string)

func (*Query) SetTOC

func (q *Query) SetTOC(offsets string)

type Response

type Response struct {
	Status string  `xml:"STATUS,attr"`
	Albums []Album `xml:"ALBUM"`
}

type TOC

type TOC struct {
	Offsets string `xml:"OFFSETS,omitempty"`
}

TOC describes the Table of Contents of an Audio CD.

Gracenote expects the TOC to contain the absolute frame offset to the start of each track, with the final offset being the total CD length in frames. Each offset should be separated by a space.

Gracenote expects the offsets to include the lead-in frames of the CD, and will return an error if the TOC contains any offset less than 1.

type Track

type Track struct {
	Number int    `xml:"TRACK_NUM"`
	ID     string `xml:"GN_ID"`
	Artist string `xml:"ARTIST"`
	Title  string `xml:"TITLE"`
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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