protected Collection<Event> doInBackground(String... artist) { try { Caller.getInstance().setCache(null); Caller.getInstance().setUserAgent("tst"); Collection<Event> events_result = Artist.getEvents(artist[0], MainActivity.API_KEY).getPageResults(); return events_result; } catch (Exception e) { return null; } }
@Override public void onCreate() { super.onCreate(); context = (Context) this.getApplicationContext(); Util.initUserAgent(this.getApplicationContext()); Caller.getInstance().setUserAgent(Util.getUserAgent()); File dir = new File(this.getApplicationContext().getFilesDir() + File.separator + "cache"); if (!dir.exists()) dir.mkdirs(); Caller.getInstance().setCache(new FileSystemCache(dir)); Track.removeOldArtistDir(this.getApplicationContext().getFilesDir()); // Caller.getInstance().setDebugMode(true); }
public static Collection<Tag> getTopTags(String user, int limit, String apiKey) { Map<String, String> params = new HashMap<String, String>(); params.put("user", user); MapUtilities.nullSafePut(params, "limit", limit); Result result = Caller.getInstance().call("user.getTopTags", apiKey, params); return ResponseBuilder.buildCollection(result, Tag.class); }
public String searchCover(String track, String artist) { String urlResult = null; String key = "49175f0086374abc087b4774bc075343"; Caller.getInstance().setCache(null); int limit = 30; // track="Spirit Indestructible"; // artist="Nelly Furtado"; Collection<Track> chart1 = Track.search(artist, track, limit, key); if (chart1.isEmpty()) { Collection<Artist> artists = Artist.search(artist, key); for (Artist artist2 : artists) { urlResult = artist2.getImageURL(ImageSize.EXTRALARGE); if (urlResult != null) { break; } } } else { for (Track track2 : chart1) { urlResult = track2.getImageURL(ImageSize.EXTRALARGE); if (urlResult != null) { break; } } } if (urlResult == null) { urlResult = "http://www.drs3.ch/static/global/logo.gif"; } return urlResult; }
/** * Creates a Last.fm playlist. * * @param title A title for the playlist * @param description A description for the playlist * @param session A Session instance * @return the result of the operation */ public static Playlist create(String title, String description, Session session) { Result result = Caller.getInstance() .call("playlist.create", session, "title", title, "description", description); if (!result.isSuccessful()) return null; return ResponseBuilder.buildItem( result.getContentElement().getChild("playlist"), Playlist.class); }
/** * Get shouts for a user. * * @param user The username to fetch shouts for * @param page The page number to fetch * @param limit An integer used to limit the number of shouts returned per page or -1 for default * @param apiKey A Last.fm API key. * @return a page of <code>Shout</code>s */ public static PaginatedResult<Shout> getShouts(String user, int page, int limit, String apiKey) { Map<String, String> params = new HashMap<String, String>(); params.put("user", user); MapUtilities.nullSafePut(params, "limit", limit); MapUtilities.nullSafePut(params, "page", page); Result result = Caller.getInstance().call("user.getShouts", apiKey, params); return ResponseBuilder.buildPaginatedResult(result, Shout.class); }
/** * Gets a list of a user's playlists on Last.fm. Note that this method only fetches metadata * regarding the user's playlists. If you want to retrieve the list of tracks in a playlist use * {@link Playlist#fetch(String, String) Playlist.fetch()}. * * @param user The last.fm username to fetch the playlists of. * @param apiKey A Last.fm API key. * @return a list of Playlists */ public static Collection<Playlist> getPlaylists(String user, String apiKey) { Result result = Caller.getInstance().call("user.getPlaylists", apiKey, "user", user); if (!result.isSuccessful()) return Collections.emptyList(); Collection<Playlist> playlists = new ArrayList<Playlist>(); for (DomElement element : result.getContentElement().getChildren("playlist")) { playlists.add(Playlist.playlistFromElement(element)); } return playlists; }
public static PaginatedResult<Track> getRecentTracks( String user, int page, int limit, String apiKey) { Map<String, String> params = new HashMap<String, String>(); params.put("user", user); params.put("limit", String.valueOf(limit)); params.put("page", String.valueOf(page)); Result result = Caller.getInstance().call("user.getRecentTracks", apiKey, params); return ResponseBuilder.buildPaginatedResult(result, Track.class); }
public static PaginatedResult<Event> getEvents( double latitude, double longitude, int page, int limit, String apiKey) { Map<String, String> params = new HashMap<String, String>(); params.put("page", String.valueOf(page)); params.put("lat", String.valueOf(latitude)); params.put("long", String.valueOf(longitude)); MapUtilities.nullSafePut(params, "limit", limit); Result result = Caller.getInstance().call("geo.getEvents", apiKey, params); return ResponseBuilder.buildPaginatedResult(result, Event.class); }
/** * Get a list of tracks by a given artist scrobbled by this user, including scrobble time. Can be * limited to specific timeranges, defaults to all time. * * @param user The last.fm username to fetch the recent tracks of * @param artist The artist name you are interested in * @param page An integer used to fetch a specific page of tracks * @param startTimestamp An unix timestamp to start at * @param endTimestamp An unix timestamp to end at * @param apiKey A Last.fm API key * @return a list of Tracks */ public static PaginatedResult<Track> getArtistTracks( String user, String artist, int page, long startTimestamp, long endTimestamp, String apiKey) { Map<String, String> params = new HashMap<String, String>(); params.put("user", user); params.put("artist", artist); params.put("page", String.valueOf(page)); params.put("startTimestamp", String.valueOf(startTimestamp)); params.put("endTimestamp", String.valueOf(endTimestamp)); Result result = Caller.getInstance().call("user.getArtistTracks", apiKey, params); return ResponseBuilder.buildPaginatedResult(result, Track.class); }
/** * Get a list of valid countries and {@link de.umass.lastfm.Geo.Metro}s for use in the other * webservices. * * @param country Optionally restrict the results to those Metros from a particular country, as * defined by the ISO 3166-1 country names standard * @param apiKey A Last.fm API key * @return a List of {@link de.umass.lastfm.Geo.Metro}s */ public static Collection<Metro> getMetros(String country, String apiKey) { Map<String, String> params = new HashMap<String, String>(); MapUtilities.nullSafePut(params, "country", country); Result result = Caller.getInstance().call("geo.getMetros", apiKey, params); if (!result.isSuccessful()) return Collections.emptyList(); Collection<DomElement> children = result.getContentElement().getChildren("metro"); Collection<Metro> metros = new ArrayList<Metro>(children.size()); for (DomElement child : children) { metros.add(new Metro(child.getChildText("name"), child.getChildText("country"))); } return metros; }
public static PaginatedResult<Event> getRecommendedEvents(int page, Session session) { Result result = Caller.getInstance() .call( "user.getRecommendedEvents", session, "page", String.valueOf(page), "user", session.getUsername()); return ResponseBuilder.buildPaginatedResult(result, Event.class); }
/** * Add a track to a Last.fm user's playlist. * * @param playlistId The ID of the playlist - this is available in user.getPlaylists * @param artist The artist name that corresponds to the track to be added. * @param track The track name to add to the playlist. * @param session A Session instance. * @return the result of the operation */ public static Result addTrack(int playlistId, String artist, String track, Session session) { return Caller.getInstance() .call( "playlist.addTrack", session, "playlistID", String.valueOf(playlistId), "artist", artist, "track", track); }
/** * Gets a list of forthcoming releases based on a user's musical taste. * * @param user The Last.fm username * @param useRecommendations If <code>true</code>, the feed contains new releases based on * Last.fm's artist recommendations for this user. Otherwise, it is based on their library * (the default) * @param apiKey A Last.fm API key * @return a Collection of new {@link Album} releases */ public static Collection<Album> getNewReleases( String user, boolean useRecommendations, String apiKey) { Result result = Caller.getInstance() .call( "user.getNewReleases", apiKey, "user", user, "userecs", useRecommendations ? "1" : "0"); return ResponseBuilder.buildCollection(result, Album.class); }
public static PaginatedResult<User> getFriends( String user, boolean recenttracks, int page, int limit, String apiKey) { Result result = Caller.getInstance() .call( "user.getFriends", apiKey, "user", user, "recenttracks", String.valueOf(recenttracks ? 1 : 0), "limit", String.valueOf(limit), "page", String.valueOf(page)); return ResponseBuilder.buildPaginatedResult(result, User.class); }
public static Collection<Track> getTopTracks(String user, Period period, String apiKey) { Result result = Caller.getInstance() .call("user.getTopTracks", apiKey, "user", user, "period", period.getString()); return ResponseBuilder.buildCollection(result, Track.class); }
/** * Returns the tracks banned by the user. * * @param user The user name * @param page The page number to fetch * @param apiKey A Last.fm API key * @return the banned tracks */ public static PaginatedResult<Track> getBannedTracks(String user, int page, String apiKey) { Result result = Caller.getInstance() .call("user.getBannedTracks", apiKey, "user", user, "page", String.valueOf(page)); return ResponseBuilder.buildPaginatedResult(result, Track.class); }
/** * Shout on this user's shoutbox * * @param user The name of the user to shout on * @param message The message to post to the shoutbox * @param session A Session instance * @return the result of the operation */ public static Result shout(String user, String message, Session session) { return Caller.getInstance().call("user.shout", session, "user", user, "message", message); }
/** * Get Last.fm artist recommendations for a user. * * @param page The page to fetch * @param session A Session instance * @return a list of {@link Artist}s */ public static PaginatedResult<Artist> getRecommendedArtists(int page, Session session) { Result result = Caller.getInstance() .call("user.getRecommendedArtists", session, "page", String.valueOf(page)); return ResponseBuilder.buildPaginatedResult(result, Artist.class); }
/** * Retrieves profile information about the specified user. * * @param user A username * @param apiKey A Last.fm API key. * @return User info */ public static User getInfo(String user, String apiKey) { Result result = Caller.getInstance().call("user.getInfo", apiKey, "user", user); return ResponseBuilder.buildItem(result, User.class); }
/** * Fetches a playlist using a lastfm playlist url. See the class description for a list of valid * playlist urls. * * @param playlistUrl A valid playlist url. * @param apiKey A Last.fm API key. * @return a playlist */ public static Playlist fetch(String playlistUrl, String apiKey) { Result result = Caller.getInstance().call("playlist.fetch", apiKey, "playlistURL", playlistUrl); return ResponseBuilder.buildItem(result, Playlist.class); }
/** * Gets a paginated list of all events a user has attended in the past. * * @param user The username to fetch the events for. * @param page The page number to scan to. * @param apiKey A Last.fm API key. * @return a list of past {@link Event}s */ public static PaginatedResult<Event> getPastEvents(String user, int page, String apiKey) { Result result = Caller.getInstance() .call("user.getPastEvents", apiKey, "user", user, "page", String.valueOf(page)); return ResponseBuilder.buildPaginatedResult(result, Event.class); }
/** * GetS a list of upcoming events that this user is attending. * * @param user The user to fetch the events for. * @param apiKey A Last.fm API key. * @return a list of upcoming events */ public static Collection<Event> getEvents(String user, String apiKey) { Result result = Caller.getInstance().call("user.getEvents", apiKey, "user", user); return ResponseBuilder.buildCollection(result, Event.class); }
/** * Get the most popular tracks on Last.fm by country * * @param country A country name, as defined by the ISO 3166-1 country names standard * @param apiKey A Last.fm API key. * @return a list of Tracks */ public static Collection<Track> getTopTracks(String country, String apiKey) { Result result = Caller.getInstance().call("geo.getTopTracks", apiKey, "country", country); return ResponseBuilder.buildCollection(result, Track.class); }
public static Collection<User> getNeighbours(String user, int limit, String apiKey) { Result result = Caller.getInstance() .call("user.getNeighbours", apiKey, "user", user, "limit", String.valueOf(limit)); return ResponseBuilder.buildCollection(result, User.class); }