Skip to content

Instantly share code, notes, and snippets.

@kevinmichaelchen
Last active November 2, 2024 21:55
Show Gist options
  • Save kevinmichaelchen/553fecb2ed61efc7119a2757d7d5cf16 to your computer and use it in GitHub Desktop.
Save kevinmichaelchen/553fecb2ed61efc7119a2757d7d5cf16 to your computer and use it in GitHub Desktop.
MusicBrainz API + Data Schema

GraphQL

https://graphbrainz.fly.dev lets you do cool GraphQL queries.

Page through an artist's albums

query {
  lookup {
    artist(mbid: "144ef525-85e9-40c3-8335-02c32d0861f3") {
      name
      id
      releaseGroups(
        first: 2
        type: ALBUM
      ) {
        totalCount
        pageInfo {
          endCursor
        }
        edges {
          cursor
          node {
            title
            primaryType
          }
        }
      }
    }
  }
}

SQL

The data include 3.4m release groups, 4.3m releases, 33m recordings, and 47m tracks.

Artist PK GID / MBID
John Mayer 33563 144ef525-85e9-40c3-8335-02c32d0861f3
Katy Perry 315753 122d63fc-8671-43e4-9752-34e846d62a9c
Phoebe Bridgers 1360060 96855c21-b832-4366-ba12-0d2330c36a86

Get artist

SELECT a.gid,
       a.name,
       a.begin_date_year AS birth_year,
       a.begin_date_month AS birth_month,
       a.begin_date_day AS birth_day,
       at.name AS TYPE,
       g.name AS gender
FROM artist AS a
JOIN artist_type AT ON at.id = a.type
JOIN gender g ON g.id = a.gender
WHERE a.gid = '144ef525-85e9-40c3-8335-02c32d0861f3';

Artist with 10 release groups

SELECT rg.id,
       rg.gid,
       rg.name,
       rg.artist_credit,
       a.name
FROM release_group AS rg
JOIN artist AS a ON a.id = rg.artist_credit
WHERE artist_credit = 33563
LIMIT 10;

Artist with 10 releases

SELECT r.id,
       r.gid,
       r.name,
       r.artist_credit,
       a.name
FROM release AS r
JOIN artist AS a ON a.id = r.artist_credit
WHERE artist_credit = 315753
LIMIT 10;

Artist's collaborations

SELECT a.id,
       a.name,
       r.name
FROM l_artist_release ar
JOIN artist a ON ar.entity0 = a.id
JOIN release r ON ar.entity1 = r.id
WHERE ar.entity0 = 1360060
LIMIT 20;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment