Locating the mbid for various tracks with musicbrainzws2-java

477 Views Asked by At

I have imported the musicbrainzws2-java library into my project and I have been reading through the documentation that MusicBrainz has on their web service. It is very confusing though. I was wondering if someone could help me understand how to navigate through the MusicBrainz data base. I don't understand the terminology and my main goal of using the database is to gather the mbid's for various songs.

Right now this is what I have.

    public static void main(String[] args) {

    ArtistSearchFilterWs2 filter = new ArtistSearchFilterWs2();

    filter.setArtistName("Lindsey Stirling");
    filter.setLimit((long) 100);
    filter.setMinScore((long) 0);
    filter.setOffset((long) 0);

    ArtistSearchWs2 search = new ArtistSearchWs2(filter);

    List<ArtistResultWs2> result = search.getFullList();

    /*
    for(ArtistResultWs2 artist : result) {
        System.out.println(artist.getArtist().getName() + " " + i);
        i++;

        if(artist.getArtist().getName() == "Lindsey Stirling") {

            System.out.println(artist.getArtist().getName() + " " + i);
            break;
        }

    }
    */

    String artistName = result.get(0).getArtist().getName();
    System.out.println(artistName);

    List<ReleaseWs2> releases = result.get(0).getArtist().getReleaseList().getReleases();

    System.out.println(releases.size());

    for(ReleaseWs2 release : releases) {
        System.out.println(release.getTitle());

    }

For some reason it says that there are 0 releases for the artist Lindsey Stirling and on top of that I don't know how to search for a specific song based off of an artist and album

1

There are 1 best solutions below

0
On

releases does not contain any elements because the search server does not return this information for artist searches. To clarify this a bit: The "normal" web service of MusicBrainz and the search web service use the same XML model in their output, which means that the ArtistWs2 class can represent a result from either of them.

Other than the search web service, the normal one allows you to request more information about the entity you're retrieving information for (in this case, you want release information for an artist, so you have to include releases in the inc parameter).

You can view the XML that the search server returns for your search here, a request to the normal web service that includes release information is here.

The following code (minus the imports) will do what you want:

ArtistSearchFilterWs2 filter = new ArtistSearchFilterWs2();

filter.setArtistName("Lindsey Stirling");
filter.setLimit((long) 100);
filter.setMinScore((long) 0);
filter.setOffset((long) 0);

ArtistSearchWs2 search = new ArtistSearchWs2(filter);
List<ArtistResultWs2> result = search.getFullList();

String artistName = result.get(0).getArtist().getName();
System.out.println(artistName);

// This is the artist as returned by the search server.
ArtistWs2 artist = result.get(0).getArtist();

Artist controller = new Artist();
// This is where you tell the library that you want to have the artists
// releases included in the result.
controller.getIncludes().setReleases(true);

// This is the artist as returned by the MusicBrainz server, including the
// release information.
ArtistWs2 lindsey = controller.lookUp(artist);

List<ReleaseWs2> releases = lindsey.getReleaseList().getReleases();
System.out.println(releases.size());

for (ReleaseWs2 release : releases) {
    System.out.println(release.getTitle());
}

To understand how searches work, you should first read the general documentation and then find the search fields you need in the recording search documentation. If you want to search (recording in MB-speak) for a song by a specific artist on a specific album, you need the artist and releases fields. For example, to search for "Mirror Haus" by "Lindsey Stirling" on "Shatter Me", you'd want to perform the following query: "Mirror Haus" AND artist:"Lindsey Stirling" AND release:"Shatter Me".

The following code will do that:

    RecordingSearchFilterWs2 recfilter = new RecordingSearchFilterWs2();
    recfilter.setLimit((long) 100);
    recfilter.setMinScore((long) 0);
    recfilter.setOffset((long) 0);
    recfilter.setQuery("\"Mirror Haus\" AND release:\"Shatter Me\" AND artist:\"Lindsey Stirling\"");
    RecordingSearchWs2 recsearch = new RecordingSearchWs2(recfilter);
    List<RecordingResultWs2> recresult = recsearch.getFullList();
    System.out.println(recresult.size());
    System.out.println(recresult.get(0).getRecording().toString());