Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright (c) 2012, the Last.fm Java Project and Committers
* All rights reserved.
*
* Redistribution and use of this software in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above
* copyright notice, this list of conditions and the
* following disclaimer.
*
* - Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package de.umass.lastfm;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import de.umass.util.MapUtilities;
import de.umass.util.StringUtilities;
import de.umass.xml.DomElement;
/**
* Bean that contains artist information. This class contains static methods that executes API methods relating to artists. Method
* names are equivalent to the last.fm API method names.
*
* @author Janni Kovacs
*/
public class Artist extends MusicEntry {
static final ItemFactory FACTORY = new ArtistFactory();
private Collection similar = new ArrayList();
protected Artist(String name, String url) {
super(name, url);
}
protected Artist(String name, String url, String mbid, int playcount, int listeners, boolean streamable) {
super(name, url, mbid, playcount, listeners, streamable);
}
/**
* Returns a list of similar Artists. Note that this method does not retrieve this list from the server but instead returns
* the result of an artist.getInfo call. If you need to retrieve similar artists to a specified artist use the {@link
* #getSimilar(String, String)} method.
*
* @return list of similar artists
* @see #getSimilar(String, String)
* @see #getSimilar(String, int, String)
*/
public Collection getSimilar() {
return similar;
}
/**
* Retrieves detailed artist info for the given artist or mbid entry.
*
* @param artistOrMbid Name of the artist or an mbid
* @param apiKey The API key
* @return detailed artist info
*/
public static Artist getInfo(String artistOrMbid, String apiKey) {
return getInfo(artistOrMbid, null, null, apiKey);
}
/**
* Retrieves detailed artist info for the given artist or mbid entry.
*
* @param artistOrMbid Name of the artist or an mbid
* @param username The username for the context of the request, or null. If supplied, the user's playcount for this artist is
* included in the response
* @param apiKey The API key
* @return detailed artist info
*/
public static Artist getInfo(String artistOrMbid, String username, String apiKey) {
return getInfo(artistOrMbid, null, username, apiKey);
}
/**
* Retrieves detailed artist info for the given artist or mbid entry.
*
* @param artistOrMbid Name of the artist or an mbid
* @param locale The language to fetch info in, or null
* @param username The username for the context of the request, or null. If supplied, the user's playcount for this artist is
* included in the response
* @param apiKey The API key
* @return detailed artist info
*/
public static Artist getInfo(String artistOrMbid, Locale locale, String username, String apiKey) {
Map params = new HashMap();
if (StringUtilities.isMbid(artistOrMbid)) {
params.put("mbid", artistOrMbid);
} else {
params.put("artist", artistOrMbid);
}
if (locale != null && locale.getLanguage().length() != 0) {
params.put("lang", locale.getLanguage());
}
MapUtilities.nullSafePut(params, "username", username);
Result result = Caller.getInstance().call("artist.getInfo", apiKey, params);
return ResponseBuilder.buildItem(result, Artist.class);
}
/**
* Calls {@link #getSimilar(String, int, String)} with the default limit of 100.
*
* @param artist Artist's name
* @param apiKey The API key
* @return similar artists
* @see #getSimilar(String, int, String)
*/
public static Collection getSimilar(String artist, String apiKey) {
return getSimilar(artist, 100, apiKey);
}
/**
* Returns limit similar artists to the given one.
*
* @param artist Artist's name
* @param limit Number of maximum results
* @param apiKey The API key
* @return similar artists
*/
public static Collection getSimilar(String artist, int limit, String apiKey) {
Result result = Caller.getInstance().call("artist.getSimilar", apiKey, "artist", artist, "limit", String.valueOf(limit));
return ResponseBuilder.buildCollection(result, Artist.class);
}
/**
* Searches for an artist and returns a Collection of possible matches.
*
* @param name The artist name to look up
* @param apiKey The API key
* @return a list of possible matches
*/
public static Collection search(String name, String apiKey) {
Result result = Caller.getInstance().call("artist.search", apiKey, "artist", name);
Collection children = result.getContentElement().getChild("artistmatches").getChildren("artist");
List list = new ArrayList(children.size());
for (DomElement c : children) {
list.add(FACTORY.createItemFromElement(c));
}
return list;
}
/**
* Returns a list of the given artist's top albums.
*
* @param artist Artist's name
* @param apiKey The API key
* @return list of top albums
*/
public static Collection getTopAlbums(String artist, String apiKey) {
Result result = Caller.getInstance().call("artist.getTopAlbums", apiKey, "artist", artist);
return ResponseBuilder.buildCollection(result, Album.class);
}
/**
* Retrieves a list of the top fans of the given artist.
*
* @param artist Artist's name
* @param apiKey The API key
* @return list of top fans
*/
public static Collection getTopFans(String artist, String apiKey) {
Result result = Caller.getInstance().call("artist.getTopFans", apiKey, "artist", artist);
return ResponseBuilder.buildCollection(result, User.class);
}
/**
* Retrieves the top tags for the given artist.
*
* @param artist Artist's name
* @param apiKey The API key
* @return list of top tags
*/
public static Collection getTopTags(String artist, String apiKey) {
Result result = Caller.getInstance().call("artist.getTopTags", apiKey, "artist", artist);
return ResponseBuilder.buildCollection(result, Tag.class);
}
/**
* Get the top tracks by an artist on Last.fm, ordered by popularity
*
* @param artist The artist name in question
* @param apiKey A Last.fm API key.
* @return list of top tracks
*/
public static Collection