【问题标题】:Locating the mbid for various tracks with musicbrainzws2-java使用 musicbrainzws2-java 定位各种曲目的 mbid
【发布时间】:2014-11-25 05:33:23
【问题描述】:

我已将 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 个版本,除此之外,我不知道如何根据艺术家和专辑搜索特定歌曲

【问题讨论】:

  • 我认为您必须先从艺术家那里获取 ReleaseGroups,然后再从组中获取 Releases。至少 WS 是这样工作的。也许这有帮助:stackoverflow.com/a/21857175/1904815

标签: java musicbrainz


【解决方案1】:

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

除了搜索网络服务之外,普通服务还允许您request more information 关于您正在检索信息的实体(在这种情况下,您想要发布信息为 artist,因此您必须包含 @987654332 inc 参数中的@)。

您可以查看搜索服务器为您的搜索返回的 XML here,对包含发布信息的普通 Web 服务的请求是 here

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

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

要了解搜索的工作原理,您应该先阅读the general documentation,然后在recording search documentation 中找到您需要的搜索字段。如果您想在特定专辑中搜索特定艺术家的歌曲(MB 中为recording),则需要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());

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-03
    • 2021-05-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多