How do i get the unique songs of a particular artist

Hi, I want to access the list of unique songs from Snoop Doggs using the python API package, and i have written the following code below.

def search_release():
    limit = 100
    offset = 0
    result = musicbrainzngs.search_releases(query='Snoop Dogg', limit=limit, offset=offset, 
    # print(result)
    release_list = result['release-list']
    for record in release_list:
        title = record['title']

the result is a mixture of songs and album titles. Please can i have some pointers to how i can access unique songs. thanks.

Welcome. Getting the unique songs can be a bit of a trouble. MusicBrainz links the tracks on a release to recordings. A recording is a specific version/mix of a song, let’s say album vs. single version.

Recordings can be linked to works, a work being the general concept. Here you find what we generally would mean when we talk about a song, see e.g. Song “Drop It Like It’s Hot” - MusicBrainz

So if you want to find all the unique songs best is to query all the works for the artist. For a famous artist like Snoop Dogg where many people edit the work list might be well maintained. Trouble is linking recordings to works is optional and often requires additional research, so many artists have incomplete work lists.

As for how to query it I need to look it up myself, with works this was a bit tricky and I’m not too familiar with the Python library.

If nobody else answers I can take a look tomorrow. But I’m currently on my mobile and also it’s too late and I should get some sleep :wink:


@outisdecontext thanks for your feedback. I have queried all the works of the artist(Snoop Dogg). not all the songs below to the artist(Snoop). there were songs title such as “Snooprah” that is not related to the artist. But thanks for your feedback, i shall check how to link recording to works.

1 Like

Hey, sorry, wanted to get back to this earlier but real life kicked in.

Things are really not that easy. Two things first: I’ll use plain web service requests here, because I’m familiar with them, but not so much with the Python library. But translating this to musicbrainzngs call should not be too difficult afterwards. Also have a look at MusicBrainz API / Search - MusicBrainz, there the different search fields and search syntax is explained.

So let’s first assume you have an artist ID. You really should do a artist search first and select one ID, otherwise it gets difficult to get good results when looking up works and recordings. In the Python library I think you can use musicbrainzngs.search_artists for this. Snoop Dogg is a good example, because one might maybe also search for the old name “Snoop Doggy Dogg” or some of the other names he used.

Now let’s assume you have the artist ID f90e8b26-9e52-4669-a5c9-e28529c47894. You could search for works by this artist with:

On a first look this seems fine. But actually it lists only songs Snoop Dogg had a role in e.g. with writing. So this misses songs he performed but did not write himself (Song “Drop It Like It’s Hot” - MusicBrainz), but it also contains songs were he is listed as a writer but not performer (Song “Bomb Ass” - MusicBrainz ). Probably not exactly what’s expected.

So other approach would be to to get all the recordings by this artist and go over them, and filter out the unique works:

Note that this is what the MB web service calls a browse request (see MusicBrainz API - MusicBrainz), not a search (a search using the query parameter).

According to the docs with musicbrainzngs this would be something like this:

result = musicbrainzngs.browse_recordings(artist="f90e8b26-9e52-4669-a5c9-e28529c47894", includes=["work-rels"], limit=limit, offset=offset)

As you can see on Song “Drop It Like It’s Hot” - MusicBrainz there are sometimes a lot of recordings for a single work (many of them probably should get merged, but often hard to say for sure), and there will be recordings not being linked to works. Not sure how to deal with them, maybe they just can be filtered out if they match the name of another recording.

Hope this helps :slight_smile:


@outsidecontext thanks for the information, I am most grateful.