gpt4 book ai didi

java - 从 MusicBrainz Web 服务检索元数据

转载 作者:行者123 更新时间:2023-12-01 23:11:54 52 4
gpt4 key购买 nike

我正在尝试使用第 3 方 java 库从 MusicBrainz 下载元数据:musicbrainzws2-java

我正在尝试检索指定专辑中单首歌曲的元数据。我已经检索到了专辑的 MBID,但是当我尝试搜索专辑中的歌曲时却没有返回。

这是我的代码:

public static void main (String args []) throws MBWS2Exception {

String artistName = "Imagine Dragons";
String album_id = null;

Artist artist = new Artist();
artist.search(artistName);
List<ArtistResultWs2> results = artist.getFullSearchResultList();

ArtistWs2 song = results.get(0).getArtist();
artist = new Artist();

song = artist.lookUp(song);
List<ReleaseGroupWs2> rgl = artist.getFullReleaseGroupList();


for(int i =0; i<rgl.size(); i++){
System.out.println(rgl.get(i).getTitle());
if(rgl.get(i).getTitle().equals("Night Visions")){
album_id = rgl.get(i).getId();

}

}
System.out.println("Night visions ID: " + album_id);

Release release = new Release();
release.search(album_id);

List<ReleaseResultWs2> list = release.getFullSearchResultList();

for(int i =0; i<list.size(); i++)
System.out.println(list.get(i).getEntity());

有人可以给我一些指点吗?谢谢

最佳答案

成功检索信息代码如下:

public static void main (String args []) throws MBWS2Exception {

String artistName = "Imagine Dragons";
String albumName = "Night Visions";
String album_id = null;

Artist artistsearch = new Artist();
artistsearch.search(artistName);


List<ArtistResultWs2> result = artistsearch.getFullSearchResultList();
ArtistWs2 artist = new ArtistWs2();

for(ArtistResultWs2 x : result){
if(x.getArtist().toString().equals(artistName)){
artist = x.getArtist();
break;
}
}

artistsearch = new Artist();
artistsearch.lookUp(artist);

List<ReleaseGroupWs2> release_groups = artistsearch.getFullReleaseGroupList();
ReleaseGroupWs2 releasegroup = null;


for(ReleaseGroupWs2 x : release_groups)
if(x.getTitle().equals(albumName)){
releasegroup = x;
}

ReleaseGroup releasegroupsearch = new ReleaseGroup();
releasegroupsearch.lookUp(releasegroup);

List<ReleaseWs2> releases = releasegroupsearch.getFullReleaseList();

ReleaseWs2 album = releases.get(0);

Release releaselist = new Release();
releaselist.lookUp(album);

MediumListWs2 releaselist1 = releaselist.getComplete(album).getMediumList();

List<TrackWs2> tracklist = releaselist1.getCompleteTrackList();

System.out.println("artist: " + artist);
System.out.println("album: " + album);
System.out.println("title: " + tracklist.get(0).getRecording().getTitle());
System.out.println("genre: " + tracklist.get(0).getRecording().getTags().get(0).getName());
System.out.println("track: " + tracklist.get(0).getPosition());
System.out.println("year: " + album.getYear());
System.out.println("disc no.: " + releaselist1.getMedia().get(0));
System.out.println("label: " + album.getLabelInfoString());
System.out.println("artist sort : " + tracklist.get(0).getRecording().getArtistCreditString());
System.out.println("comment: " + tracklist.get(0).getRecording().getDisambiguation());


}

}

关于java - 从 MusicBrainz Web 服务检索元数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21805965/

52 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com