Retrieving Metadata from MusicBrainz Web Service

…衆ロ難τιáo~ 提交于 2019-12-13 07:19:46

问题


I'm trying to download metadata from MusicBrainz using a 3rd party java library: musicbrainzws2-java

I'm trying to retrieve the metadata of individual songs in a specified album. I've retrieved the MBID of the album, but when I try to search for the songs in the album I get no return.

Here is my code:

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

Can someone give me some pointers. Thanks


回答1:


Managed to retrieve information code is below:

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


}

}



来源:https://stackoverflow.com/questions/21805965/retrieving-metadata-from-musicbrainz-web-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!