2 * Copyright (c) 2012, the Last.fm Java Project and Committers All rights
3 * reserved. Redistribution and use of this software in source and binary forms,
4 * with or without modification, are permitted provided that the following
5 * conditions are met: - Redistributions of source code must retain the above
6 * copyright notice, this list of conditions and the following disclaimer. -
7 * Redistributions in binary form must reproduce the above copyright notice,
8 * this list of conditions and the following disclaimer in the documentation
9 * and/or other materials provided with the distribution. THIS SOFTWARE IS
10 * PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
11 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
13 * EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
14 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
15 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
16 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
17 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
18 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
19 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22 package com.cyngn.eleven.lastfm;
24 import android.content.Context;
26 import com.cyngn.eleven.Config;
28 import java.util.Locale;
30 import java.util.WeakHashMap;
33 * Bean that contains artist information.<br/>
34 * This class contains static methods that executes API methods relating to
36 * Method names are equivalent to the last.fm API method names.
38 * @author Janni Kovacs
40 public class Artist extends MusicEntry {
42 protected final static ItemFactory<Artist> FACTORY = new ArtistFactory();
44 protected Artist(final String name, final String url) {
49 * Retrieves detailed artist info for the given artist or mbid entry.
51 * @param artistOrMbid Name of the artist or an mbid
52 * @return detailed artist info
54 public final static Artist getInfo(final Context context, final String artistOrMbid) {
55 return getInfo(context, artistOrMbid, Locale.getDefault(), Config.LASTFM_API_KEY);
59 * Retrieves detailed artist info for the given artist or mbid entry.
61 * @param artistOrMbid Name of the artist or an mbid
62 * @param locale The language to fetch info in, or <code>null</code>
63 * @param apiKey The API key
64 * @return detailed artist info
66 public final static Artist getInfo(final Context context, final String artistOrMbid,
67 final Locale locale, final String apiKey) {
68 final Map<String, String> mParams = new WeakHashMap<String, String>();
69 mParams.put("artist", artistOrMbid);
70 if (locale != null && locale.getLanguage().length() != 0) {
71 mParams.put("lang", locale.getLanguage());
73 final Result mResult = Caller.getInstance(context).call("artist.getInfo", apiKey, mParams);
74 return ResponseBuilder.buildItem(mResult, Artist.class);
78 * Use the last.fm corrections data to check whether the supplied artist has
79 * a correction to a canonical artist. This method returns a new
80 * {@link Artist} object containing the corrected data, or <code>null</code>
81 * if the supplied Artist was not found.
83 * @param artist The artist name to correct
84 * @return a new {@link Artist}, or <code>null</code>
86 public final static Artist getCorrection(final Context context, final String artist) {
89 result = Caller.getInstance(context).call("artist.getCorrection",
90 Config.LASTFM_API_KEY, "artist", artist);
91 if (!result.isSuccessful()) {
94 final DomElement correctionElement = result.getContentElement().getChild("correction");
95 if (correctionElement == null) {
96 return new Artist(artist, null);
98 final DomElement artistElem = correctionElement.getChild("artist");
99 return FACTORY.createItemFromElement(artistElem);
100 } catch (final Exception ignored) {
105 private final static class ArtistFactory implements ItemFactory<Artist> {
111 public Artist createItemFromElement(final DomElement element) {
112 if (element == null) {
115 final Artist artist = new Artist(null, null);
116 MusicEntry.loadStandardInfo(artist, element);