我已将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个版本,除此之外我不知道如何根据艺术家和专辑搜索特定的歌曲
答案 0 :(得分:1)
releases
不包含任何元素,因为搜索服务器不会为艺术家搜索返回此信息。为了澄清这一点:MusicBrainz的“普通”web service和search web service在其输出中使用相同的XML模型,这意味着ArtistWs2
类可以表示来自任何一个的结果它们。
除了搜索网络服务之外,正常情况允许您request more information关于您正在检索信息的实体(在这种情况下,您需要artist
的发布信息,因此您有在releases
参数中包含inc
。
您可以查看搜索服务器为您的搜索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中找到所需的搜索字段。如果您想在特定相册中搜索某位特定艺术家的歌曲(recording
以MB为单位),则需要artist
和releases
字段。例如,要在“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());