How do I implement last.fm api as a search engine in java eclipse?

旧城冷巷雨未停 提交于 2019-12-11 09:51:25

问题


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

来源:https://stackoverflow.com/questions/42943143/how-do-i-implement-last-fm-api-as-a-search-engine-in-java-eclipse

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