0

我已将 musicbrainzws2-java 库导入到我的项目中,并且我一直在阅读 MusicBrainz 在其 Web 服务上的文档。但这很令人困惑。我想知道是否有人可以帮助我了解如何浏览 MusicBrainz 数据库。我不懂术语,我使用数据库的主要目标是收集各种歌曲的 mbid。

现在这就是我所拥有的。

    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());

    }

出于某种原因,它说艺术家 Lindsey Stirling 有 0 个版本,除此之外,我不知道如何根据艺术家和专辑搜索特定歌曲

4

1 回答 1

1

releases不包含任何元素,因为搜索服务器不会为艺术家搜索返回此信息。为了澄清这一点:MusicBrainz的“普通” Web 服务和搜索 Web 服务在其输出中使用相同的 XML 模型,这意味着ArtistWs2该类可以表示来自它们中的任何一个的结果。

除了搜索 Web 服务之外,普通服务还允许您请求有关您正在检索信息的实体的更多信息(在这种情况下,您需要发布信息artist,因此您必须包含releasesinc参数中)。

您可以在此处查看搜索服务器为您的搜索返回的 XML,此处是对包含发布信息的正常 Web 服务的请求

以下代码(减去导入)将执行您想要的操作:

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());
}

要了解搜索的工作原理,您应该首先阅读一般文档,然后在录音搜索文档中找到您需要的搜索字段。如果您想recording在特定专辑中搜索(以 MB 为单位)特定艺术家的歌曲,则需要artistreleases字段。例如,要在“Shatter Me”上搜索“Lindsey Stirling”的“Mirror Haus”,您需要执行以下查询:“Mirror Haus” AND artist:"Lindsey Stirling" AND release:"Shatter Me"

以下代码将执行此操作:

    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());
于 2014-11-26T09:51:00.177 回答