How do I implement last.fm api as a search engine

2019-07-25 12:58发布

I'm not sure how to word this correctly, but I'd like to use this code and some others to be able to search up song results and then display its info when I select it. I've also implemented the last.fm api into my eclipse, but I am not sure where to go from there. Any advice would help. Thanks!

static final ItemFactory<Track> FACTORY = new TrackFactory();

public static final String ARTIST_PAGE = "artistpage";
public static final String ALBUM_PAGE = "albumpage";
public static final String TRACK_PAGE = "trackpage";

private String artist;
private String artistMbid;

protected String album;
private String albumMbid;
private int position = -1;

private boolean fullTrackAvailable;
private boolean nowPlaying;

private Date playedWhen;
protected int duration;     
protected String location;      

protected Map<String, String> lastFmExtensionInfos = new HashMap<String, String>();


protected Track(String name, String url, String artist) {
    super(name, url);
    this.artist = artist;
}

protected Track(String name, String url, String mbid, int playcount, int listeners, boolean streamable,
                String artist, String artistMbid, boolean fullTrackAvailable, boolean nowPlaying) {
    super(name, url, mbid, playcount, listeners, streamable);
    this.artist = artist;
    this.artistMbid = artistMbid;
    this.fullTrackAvailable = fullTrackAvailable;
    this.nowPlaying = nowPlaying;
}

public int getDuration() {
    return duration;
}

public String getArtist() {
    return artist;
}

public String getArtistMbid() {
    return artistMbid;
}

public String getAlbum() {
    return album;
}

public String getAlbumMbid() {
    return albumMbid;
}

public boolean isFullTrackAvailable() {
    return fullTrackAvailable;
}

public boolean isNowPlaying() {
    return nowPlaying;
}


public String getLocation() {
    return location;
}


public String getLastFmInfo(String key) {
    return lastFmExtensionInfos.get(key);

public Date getPlayedWhen() {
    return playedWhen;
}

public static Collection<Track> search(String track, String apiKey) {
    return search(null, track, 30, apiKey);
}


public static Collection<Track> search(String artist, String track, int limit, String apiKey) {
    Map<String, String> params = new HashMap<String, String>();
    params.put("track", track);
    params.put("limit", String.valueOf(limit));
    MapUtilities.nullSafePut(params, "artist", artist);
    Result result = Caller.getInstance().call("track.search", apiKey, params);
    if(!result.isSuccessful())
        return Collections.emptyList();
    DomElement element = result.getContentElement();
    DomElement matches = element.getChild("trackmatches");
    return ResponseBuilder.buildCollection(matches, Track.class);
}

标签: java last.fm
0条回答
登录 后发表回答