Skip to content

Connecting to Discogs

tworrall edited this page Mar 11, 2019 · 7 revisions

Overview

Discogs is a website and crowdsourced database of information about audio recordings, including commercial releases, promotional releases, and bootleg or off-label releases.

More Information on Discogs

Prerequisites

Step 1: Include required gem for processing linked data

You will need to add the ruby-rdf/linkeddata gem that processes a large number of linked data serializations. The Discogs API returns JSON, not linked data. However, the Discogs Authority provides the option of converting the Discogs data to JSON-LD, and this process requires serialization.

gem 'linkeddata'

Step 2: Signup with GeoNames

You need to register for a Discogs account, which is explained on the Discogs authentication page. Create an application to receive a Consumer Key and Secret. Once you have those, you can run queries like this:

https://api.discogs.com/database/search?q=sinatra&type=release&key=CONSUMER_KEY&secret=CONSUMER_SECRET

You should see about 10 results for this URL.

Step 3: Generate Discogs configuration

Run this command to install the configuration files:

rails generate qa:discogs

Step 4: Register your Discogs account name in QA

Put the following statements in an initializer and restart the rails server.

Qa::Authorities::Discogs.discogs_key = 'CONSUMER_KEY'
Qa::Authorities::Discogs.discogs_secret = 'CONSUMER_SECRET'

Accessing via QA

Authority: geonames

Subauthorities:

  • master
  • release

NOTE: If no subauthority is specified, then all records that match the query term are returned.


Example search queries

Example search:

/qa/search/discogs/release?q=sinatra+the+modernaires

Result:

[
{
    "uri": "/Frank-Sinatra-And-The-Modernaires-Sorry-Why-Remind-Me/master/1177655",
    "id": "1177655",
    "label": "Frank Sinatra And The Modernaires - Sorry / Why Remind Me",
    "context": {
      "Image URL": [
        "https://img.discogs.com/2e-YoNr0dvmMgbzEN0hjHD6X0sU=/fit-in/600x580/filters:strip_icc():format(jpeg):mode_rgb():quality(90)/discogs-images/R-4212473-1358693671-5430.jpeg.jpg"
      ],
      "Year": [
        "1950"
      ],
      "Record Labels": [
        "Columbia"
      ],
      "Formats": [
        "Shellac",
        "10\"",
        "78 RPM"
      ],
      "Type": [
        "master"
      ]
    }
  },
  etc.
]

NOTE: The qa request is converted to the following Discogs request. This is for information only. You do not need to know this to use QA.

https://api.discogs.com/database/search?q=sinatra+the+modernaires&type=release&key=dummy_key&secret=dummy_secret

Examples term fetch request

When the format is JSON, Discogs data is returned without being altered. When the format is JSON-LD, the translation module converts the Discogs data into linked data relationships and maps Discogs terms to their corresponding BIBFRAME properties.

Example fetch, JSON format:

/qa/show/discogs/release/3380671

Result:

{ "status": "Accepted", "labels": [ { "name": "Blue Note" } ], "year": 1962, "artists": [ { "name": "Dexter Gordon" } ], "id": 3380671, "genres": [ "Jazz" ], "title": "A Swingin' Affair", "styles": [ "Hard Bop" ], "formats": [ { "qty": "1", "descriptions": [ "LP", "Album", "Mono" ], "name": "Vinyl" } ], etc. } NOTE: The qa request is converted to the following Discogs request. This is for information only. You do not need to know this to use QA.

https://api.discogs.com/releases/3380671

Example fetch, JSON-LD format:

/qa/show/discogs/master/950011?format=jsonld

Result:

{ "genres": [ "Jazz" ], "title": "Blue Moon / You Go To My Head", "year": 1952, "uri": "https://www.discogs.com/Billie-Holiday-And-Her-Orchestra-Blue-Moon-You-Go-To-My-Head/master/950011", "tracklist": [ { "duration": "", "position": "A", "type_": "track", "extraartists": [ { "join": "", "name": "Rodgers & Hart", "anv": "", "tracks": "", "role": "Written-By", "resource_url": "https://api.discogs.com/artists/604171", "id": 604171 } ], "title": "Blue Moon" }, { "duration": "", "position": "AA", "type_": "track", "extraartists": [ { "join": "", "name": "Haven Gillespie", "anv": "Gillespie", "tracks": "", "role": "Written-By", "resource_url": "https://api.discogs.com/artists/583502", "id": 583502 }, { "join": "", "name": "J. Fred Coots", "anv": "Coots", "tracks": "", "role": "Written-By", "resource_url": "https://api.discogs.com/artists/583506", "id": 583506 } ], "title": "You Go To My Head" } ], etc. } NOTE: The qa request is converted to the following Discogs request. This is for information only. You do not need to know this to use QA.

https://api.discogs.com/masters/950011

Example list all terms

Not supported


JavaScript example search and show

$('input#discogs').autocomplete({
  minLength: 3,
  source: function(request, response) {
   	$.ajax({
      url: '/qa/search/discogs/release', 
	  type: 'GET',
      dataType: 'json',
	  data: {
	    q: request.term,
	  },
      complete: function(xhr, status) {
        var results = $.parseJSON(xhr.responseText);
		if ( results.length > 0 ) {
          response(results);
        }
      } 
   	});
  },
  select: function(event, ui) {
    $.ajax({
      url: '/qa/show/discogs/' + ui.item.id, 
 		type: 'GET',
  	data: {
  	  format: 'jsonld',
  	  subauthority: ui.item.context.Type[0]
  	},
      dataType: 'json',
      complete: function(xhr, status) {
        var results = $.parseJSON(xhr.responseText);
  	  [ your function for rendering the results ] 
     	} 
    });
  }
});

Documentation

Discogs documents their API at... https://www.discogs.com/developers/

Clone this wiki locally