我已经将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个专辑,最重要的是,我不知道如何根据歌手和专辑来搜索特定歌曲
最佳答案
releases
不包含任何元素,因为搜索服务器不会针对艺术家搜索返回此信息。为了澄清这一点:MusicBrainz的“普通” web service和search web service在它们的输出中使用相同的XML模型,这意味着ArtistWs2
类可以表示它们两个的结果。
除了搜索网络服务之外,普通的服务使您可以request more information关于要为其获取信息的实体(在这种情况下,您需要发布artist
的信息,因此必须在releases
中包含inc
recording
参数)。
您可以查看搜索服务器为搜索here返回的XML,对包含发行信息的普通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为单位,
artist
),则需要releases
和字段。例如,要在“粉碎我”上搜索“林赛·斯特林”的“镜屋”,您需要执行以下查询:"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());