Beginner Question: Query Disc catalog nbr in python

With Python I try to query:

import musicbrainzngs
import discid

user_agent = "musicplayer"
api_key = "my auth key"
musicbrainzngs.set_useragent(user_agent, api_key)    

def get_catalog_number(device_path):
    d = discid.read(device_path)
    musicbrainz_disc_id = d.submission_url

    try:
        result = musicbrainzngs.get_release_by_id(d, includes=["labels"])
        catalog_number = result['release']['label-info-list'][0]['catalog-number']

    except musicbrainzngs.musicbrainz.ResponseError as e:
        
        print(f"Error: {e}")

get_catalog_number('/dev/cdrom')

But I get a HTTP Error 400

Can someone help to solve my issue?

I haven’t used either of those libraries, but perhaps you should be calling get_releases_by_discid instead of get_release_by_id (which I suspect expects an MBID, not a disc ID). I think the object you’re passing to it may not be right, either (per the discid docs). I’d guess it should be something like:

result = musicbrainzngs.get_releases_by_discid(d.id, includes=['labels'])

Per the musicbrainzngs docs, you might then need to update the next line to something like result['disc']['release-list'][0]['catalog-number'], or maybe result['release-list'][0]['catalog-number']:

The result is a dict with either a ‘disc’ , a ‘cdstub’ key or a ‘release-list’ (fuzzy match with TOC). A ‘disc’ has an ‘offset-count’, an ‘offset-list’ and a ‘release-list’. A ‘cdstub’ key has direct ‘artist’ and ‘title’ keys.

2 Likes