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.cyanogenmod.eleven.lastfm;
24 import android.content.Context;
26 import com.cyanogenmod.eleven.Config;
28 import java.util.HashMap;
32 * Wrapper class for Album related API calls and Album Bean.
34 * @author Janni Kovacs
36 public class Album extends MusicEntry {
38 protected final static ItemFactory<Album> FACTORY = new AlbumFactory();
40 private String artist;
47 private Album(final String name, final String url, final String artist) {
53 * Get the metadata for an album on Last.fm using the album name or a
54 * musicbrainz id. See playlist.fetch on how to get the album playlist.
56 * @param artist Artist's name
57 * @param albumOrMbid Album name or MBID
58 * @return Album metadata
60 public final static Album getInfo(final Context context, final String artist,
61 final String albumOrMbid) {
62 return getInfo(context, artist, albumOrMbid, null, Config.LASTFM_API_KEY);
66 * Get the metadata for an album on Last.fm using the album name or a
67 * musicbrainz id. See playlist.fetch on how to get the album playlist.
69 * @param artist Artist's name
70 * @param albumOrMbid Album name or MBID
71 * @param username The username for the context of the request. If supplied,
72 * the user's playcount for this album is included in the
74 * @param apiKey The API key
75 * @return Album metadata
77 public final static Album getInfo(final Context context, final String artist,
78 final String albumOrMbid, final String username, final String apiKey) {
79 final Map<String, String> params = new HashMap<String, String>();
80 params.put("artist", artist);
81 params.put("album", albumOrMbid);
82 MapUtilities.nullSafePut(params, "username", username);
83 final Result result = Caller.getInstance(context).call("album.getInfo", apiKey, params);
84 return ResponseBuilder.buildItem(result, Album.class);
87 private final static class AlbumFactory implements ItemFactory<Album> {
93 public Album createItemFromElement(final DomElement element) {
94 if (element == null) {
97 final Album album = new Album(null, null, null);
98 MusicEntry.loadStandardInfo(album, element);
99 if (element.hasChild("artist")) {
100 album.artist = element.getChild("artist").getChildText("name");
101 if (album.artist == null) {
102 album.artist = element.getChildText("artist");