Limiting response to CD format using the Python Library?

Hi,

I use the following code to get a list of releases, is there anyway to limit what it returns to CD format only?

myQuery = ‘artist=’ + theArtistName + ’ AND release=’ + theAlbumName
myReleasesDict = musicbrainzngs.search_releases(myQuery)

All the Best
Dave

The query is not quite correct and would not do what you expect. In lucene query syntax the field names and values are separated by colons, not equal signs. Also you should put the artist name and album name in quotes, otherwise you’d search only for the first word (and the rest would be considered in a full text search, but not specific to that field). So use something like:

myQuery = 'artist:"%s" AND release:"%s"' % (theArtistName, theAlbumName)

For searching by medium format see MusicBrainz API / Search - MusicBrainz for a list of available fields for release searches. There is a field format, so maybe something like this would do:

myQuery = 'artist:"%s" AND release:"%s" AND format:CD' % (theArtistName, theAlbumName)
1 Like

Hi,

I’m confused then, the query I used seemed to work in that it returned the “correct” information, but I’ve changed to now and it seems to work.

I’m looking the formats here: Release / Format - MusicBrainz should I use “Compact Disc” there doesn’t seem to be a straight “CD” code?

Thanks a lot
Dave

It will of course also find something related, depending on the search terms it might get quite similar results. But your search did not specifically search for a specific artist or release name, just both was used for full text search over all the indexed fields. Look for example at this query:

http://musicbrainz.org/ws/2/release/?query=artist:"Paradise%20Lost"%20release:Obsidian&fmt=json

It searches for artist “Paradise Lost” and release title “Obdisian”, and indeed the very first result matches this: https://musicbrainz.org/release/be133eae-bd85-40c1-aefc-2ad3135cb5aa

If you omit the field names and just search for artist name + title as one big search term the result gets different:

http://musicbrainz.org/ws/2/release/?query=Paradise%20Lost%20Obsidian&fmt=json

Now the first three results are all albums with the title “Paradise Lost”, but by different artists. The 4th result is by the band “Paradise Lost”, but their self titled album “Paradise Lost”. That’s not surprising, for release searches matches in the title are weighted especially high. Indeed there are so many albums titled “Paradise Lost” that the Obsidian album we had been looking for does not show up for a long time (it eventually shows up at around position 90 currently).

You need to use the values as they are in the database (and as they are also shown in the web service responses). Here is a list of the current values for media:

CD
Copy Control CD
Data CD
DTS CD
Enhanced CD
HDCD
Mixed Mode CD
CD-R
8cm CD
Blu-spec CD
SHM-CD
HQCD
CD+G
8cm CD+G
Digital Media
Phonograph record
Vinyl
7" Vinyl
10" Vinyl
12" Vinyl
Flexi-disc
7" Flexi-disc
Shellac
7" Shellac
10" Shellac
12" Shellac
Cassette
Microcassette
DVD
Data DVD
DVD-Audio
Data DVD-R
DVD-R Video
DVD-Video
SACD
SACD (2 channels)
SACD (multichannel)
Hybrid SACD
Hybrid SACD (CD layer)
Hybrid SACD (SACD layer)
Hybrid SACD (SACD layer, 2 channels)
Hybrid SACD (SACD layer, multichannel)
SHM-SACD
SHM-SACD (2 channels)
SHM-SACD (multichannel)
DualDisc
DualDisc (CD side)
DualDisc (DVD-Video side)
DualDisc (DVD-Audio side)
MiniDisc
Blu-ray
Blu-ray-R
HD-DVD
CDV
VCD
SVCD
SD Card
slotMusic
Other
Betamax
Cartridge
8-Track Cartridge
HiPac
PlayTape
CED
DAT
DataPlay
DCC
Download Card
DVDplus
DVDplus (CD side)
DVDplus (DVD-Video side)
DVDplus (DVD-Audio side)
Edison Diamond Disc
Floppy Disk
3.5" Floppy Disk
5.25" Floppy Disk
Zip Disk
KiT Album
LaserDisc
8" LaserDisc
12" LaserDisc
Pathé disc
Piano Roll
Playbutton
Reel-to-reel
Tefifon
UMD
USB Flash Drive
VHD
VHS
VinylDisc
VinylDisc (CD side)
VinylDisc (DVD side)
VinylDisc (Vinyl side)
Wax Cylinder
1 Like

Hi,

Thanks for the great explanation, I added this:

myQuery = 'artist:"' + theArtistName + '" AND release:"' + theAlbumName + '" AND format:"CD"'
print('Query: ' + myQuery)
myReleasesDict = musicbrainzngs.search_releases(myQuery)

Query: artist:“Bob Dylan” AND release:“Blonde on Blonde” AND format:“CD”

And it seems to work ok, I haven’t checked but it seems a lot faster so I reckon it cut down the number of releases returned.

Thanks again for your help
All the Best
Dave

2 Likes