Magnatune catalog: SQL

JSONMarkdownAPI guidellms.txt

Find music any way you like: run one read-only SQLite query on the whole catalog.

  20 queries a minute, 1000 rows at most. Schema and examples

Examples

GET https://magnatune.com/api/sql?q=SELECT... (or POST the SQL as the body, as sql= form data, or as JSON {"sql": "..."}) runs one read-only SQLite SELECT on the whole catalog and returns {columns, rows, row_count, truncated, ms}. No key needed. Limits: one statement, at most 1000 rows (add LIMIT/OFFSET to page), 3 seconds per query, 20 queries and 10 seconds of query time per minute per IP. GET https://magnatune.com/api/sql with no query returns this schema as JSON.

The same database is downloadable: https://magnatune.com/info/sqlite_normalized.db (SQLite file), https://magnatune.com/info/sqlite_normalized.db.gz (gzipped), https://magnatune.com/info/sqlite_normalized.sql.gz (gzipped SQL dump: gunzip it and run it into an empty SQLite database). It is rebuilt with every new release; https://magnatune.com/info/changed.txt changes when it does.

Ready-made views (start here)

How the tables join

  pro ◄──── albums.pro              (each album: one collecting society)
             │
  artists ◄─ albums.artist_id       (artist 1 : N albums)
             │ album_id
             ├──► songs.album_id                        (album 1 : N songs, ordered by track_no)
             │       └─ song_id ──► playlist_songs ──► playlists   (N : M, ordered by sort_order)
             ├──► genres_albums      ──► genres          (N : M)
             ├──► subgenres_albums   ──► subgenres       (N : M; ids off by one: use the album_subgenres view)
             ├──► collections_albums ──► collections     (N : M)
             └──► recommendations    ──► albums          (album -> recommended album, rank 1 = best)
Foreign key (child) Points to (parent) Relationship
albums.artist_id artists.artists_id each album has one artist; an artist has many albums
albums.pro pro.pro_id the album's collecting society (0 = Unknown, 25 = NONE)
songs.album_id albums.album_id an album's tracks; songs.track_no gives their order
genres_albums.album_id, genres_albums.genre_id albums.album_id, genres.genre_id many-to-many: an album has 1+ genres
subgenres_albums.album_id, subgenres_albums.subgenre_id albums.album_id, subgenres.subgenre_id - 1 many-to-many, but the link ids are one LOW in current exports: join subgenres.subgenre_id = subgenres_albums.subgenre_id + 1, or simply use the album_subgenres view
collections_albums.album_id, collections_albums.collection_id albums.album_id, collections.collections_id many-to-many: moods, instruments, uses, composers
playlist_songs.playlist_id, playlist_songs.song_id playlists.playlist_id, songs.song_id many-to-many, ordered by playlist_songs.sort_order
recommendations.album_id, recommendations.recommended_album_id albums.album_id (both) album-to-album suggestions, rank 1 = best match

Watch the key names: the artist key is artists.artists_id (plural) but albums.artist_id; the collection key is collections.collections_id but collections_albums.collection_id. SQLite doesn't declare these foreign keys in the file (PRAGMA foreign_key_list is empty); the table above is the authority. Indexes exist on every album_id, artist_id, genre_id, subgenre_id and collection_id join column.

Ids are permanent: artists_id, album_id and song_id stay the same from one release to the next and are never reused, so they are safe to store. song_id = album_id * 100 + track_no (albums have at most 99 tracks), so song_id / 100 is the album and song_id % 100 the track. Ids from exports before October 2026 were renumbered on every release and don't match these.

Tables and columns

Table (rows) Column Type Meaning (example)
artists (723) artists_id integer, key permanent: never changes or gets reused
name text, unique display name (Paolo Pavan)
page text URL slug: https://magnatune.com/artists/{page}/ (paolo_pavan)
homepage text same as page (legacy)
description text one-line style summary (Urban funky jazz piano...)
bio text full biography
photo text site path of the photo (/artists/img/paolo_pavan.jpg)
city, state, country text where they're from; state only for the USA (Rome, empty, Italy)
albums (1,927) album_id integer, key permanent: one per sku, never changes or gets reused
artist_id integer -> artists.artists_id
name text, unique album title (French Kiss)
sku text, unique the album's id everywhere in this API (1kub-frenchkiss)
description text album notes
upc text barcode
release_date integer Unix timestamp; date(release_date, 'unixepoch') gives YYYY-MM-DD
popularity integer higher = more listened to
pro integer -> pro.pro_id
itunes_buy_url text legacy, usually empty
pro (51) pro_id, name, description integer, text, text collecting society: NONE (25) = in none, Unknown (0) = not recorded, ASCAP, BMI, PRS, SACEM, GEMA... (description adds the country)
songs (23,771) song_id integer, unique album_id * 100 + track_no, so permanent too (56406 = track 6 of album 564)
album_id integer -> albums.album_id
name text song title
track_no integer 1, 2, ...; the audio: GET /api/albums/{sku}/tracks/{track_no}/file
duration integer seconds
mp3 text the file name on the server (01-I'm Monster-1kub.mp3)
genres (10) genre_id, name integer, text Alt Rock, Ambient, Classical, Electro Rock, Electronica, Hard Rock, Hip Hop, Jazz, New Age, World
subgenres (80) subgenre_id, name integer, text finer styles: Baroque, Blues, Chamber Music...
collections (472) collections_id, name integer, text moods, instruments, uses (Background Mix) and one per classical composer
genres_albums (2,478), subgenres_albums (5,221), collections_albums (3,723) integer pairs the many-to-many links above
playlists (24) playlist_id, sort_order, owner_id, name Magnatune-curated playlists (80s Rock)
playlist_songs (5,867) playlist_id, sort_order, song_id integers the songs of each playlist, in order
recommendations (35,492) album_id, recommended_album_id, rank integers "if you like this, try..."

Join recipes

Text matching: LIKE is case-insensitive for ASCII; genres in album_details.genres are comma-separated, so match with genres LIKE '%Jazz%'. Every album row is a released, visible album.

← Magnatune