de.umass.lastfm
Class Track

java.lang.Object
  extended by de.umass.lastfm.ImageHolder
      extended by de.umass.lastfm.MusicEntry
          extended by de.umass.lastfm.Track

public class Track
extends MusicEntry

Bean that contains information related to Tracks and provides bindings to methods in the track. namespace.

Author:
Janni Kovacs

Field Summary
protected  String album
           
static String ALBUM_PAGE
           
protected  String albumMbid
           
protected  String artist
           
static String ARTIST_PAGE
           
protected  String artistMbid
           
protected  int duration
           
protected  boolean fullTrackAvailable
           
protected  Map<String,String> lastFmExtensionInfos
           
protected  String location
           
protected  boolean nowPlaying
           
protected  Date playedWhen
           
protected  int position
           
static String TRACK_PAGE
           
 
Fields inherited from class de.umass.lastfm.MusicEntry
id, listeners, mbid, name, percentageChange, playcount, streamable, tags, url, userPlaycount
 
Fields inherited from class de.umass.lastfm.ImageHolder
imageUrls
 
Constructor Summary
protected Track(String name, String url, String artist)
           
protected Track(String name, String url, String mbid, int playcount, int listeners, boolean streamable, String artist, String artistMbid, boolean fullTrackAvailable, boolean nowPlaying)
           
 
Method Summary
static Result addTags(String artist, String track, String tags, Session session)
          Tag an album using a list of user supplied tags.
static Result ban(String artist, String track, Session session)
          Ban a track for a given user profile.
 String getAlbum()
           
 String getAlbumMbid()
           
 String getArtist()
           
 String getArtistMbid()
           
static Collection<BuyLink> getBuylinks(String artist, String albumOrMbid, String country, String apiKey)
          Get a list of Buy Links for a particular Track.
static Track getCorrection(String artist, String track, String apiKey)
          Use the last.fm corrections data to check whether the supplied track has a correction to a canonical track.
 int getDuration()
          Returns the duration of the song, if available, in seconds.
static Track getInfo(String artist, String trackOrMbid, Locale locale, String username, String apiKey)
          Get the metadata for a track on Last.fm using the artist/track name or a musicbrainz id.
static Track getInfo(String artist, String trackOrMbid, String apiKey)
          Get the metadata for a track on Last.fm using the artist/track name or a musicbrainz id.
 String getLastFmInfo(String key)
          Returns last.fm specific information about this Track.
 String getLocation()
          Returns the location (URL) of this Track.
 Date getPlayedWhen()
          Returns the time when the track was played, if this data is available (e.g.
 int getPosition()
          Returns the position of this track in its associated album, or -1 if not available.
static Collection<Track> getSimilar(String artist, String trackOrMbid, String apiKey)
          Get the similar tracks for this track on Last.fm, based on listening data.
You have to provide either an artist and a track name or an mbid.
static Collection<String> getTags(String artist, String track, Session session)
          Get the tags applied by an individual user to an track on Last.fm.
static Collection<User> getTopFans(String artist, String trackOrMbid, String apiKey)
          Retrieves the top fans for the given track.
static Collection<Tag> getTopTags(String artist, String trackOrMbid, String apiKey)
          Retrieves the top tags for the given track.
 boolean isFullTrackAvailable()
           
 boolean isNowPlaying()
           
static Result love(String artist, String track, Session session)
          Love a track for a user profile.
static Result removeTag(String artist, String track, String tag, Session session)
          Remove a user's tag from a track.
static List<ScrobbleResult> scrobble(List<ScrobbleData> scrobbleData, Session session)
           
static ScrobbleResult scrobble(ScrobbleData scrobbleData, Session session)
           
static ScrobbleResult scrobble(String artistName, String trackName, int timestamp, Session session)
           
static Collection<Track> search(String track, String apiKey)
          Searches for a track with the given name and returns a list of possible matches.
static Collection<Track> search(String artist, String track, int limit, String apiKey)
          Searches for a track with the given name and returns a list of possible matches.
static Result share(String artist, String track, String message, String recipient, Session session)
          Share a track twith one or more Last.fm users or other friends.
 String toString()
           
static Result unban(String artist, String track, Session session)
          UnBan a track for a given user profile.
static Result unlove(String artist, String track, Session session)
          UnLove a track for a user profile.
static ScrobbleResult updateNowPlaying(ScrobbleData scrobbleData, Session session)
           
static ScrobbleResult updateNowPlaying(String artistName, String trackName, Session session)
           
 
Methods inherited from class de.umass.lastfm.MusicEntry
getId, getListeners, getMbid, getName, getPercentageChange, getPlaycount, getTags, getUrl, getUserPlaycount, getWikiLastChanged, getWikiSummary, getWikiText, isStreamable, loadStandardInfo
 
Methods inherited from class de.umass.lastfm.ImageHolder
availableSizes, getImageURL, loadImages
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ARTIST_PAGE

public static final String ARTIST_PAGE
See Also:
Constant Field Values

ALBUM_PAGE

public static final String ALBUM_PAGE
See Also:
Constant Field Values

TRACK_PAGE

public static final String TRACK_PAGE
See Also:
Constant Field Values

artist

protected String artist

artistMbid

protected String artistMbid

album

protected String album

albumMbid

protected String albumMbid

position

protected int position

fullTrackAvailable

protected boolean fullTrackAvailable

nowPlaying

protected boolean nowPlaying

playedWhen

protected Date playedWhen

duration

protected int duration

location

protected String location

lastFmExtensionInfos

protected Map<String,String> lastFmExtensionInfos
Constructor Detail

Track

protected Track(String name,
                String url,
                String artist)

Track

protected Track(String name,
                String url,
                String mbid,
                int playcount,
                int listeners,
                boolean streamable,
                String artist,
                String artistMbid,
                boolean fullTrackAvailable,
                boolean nowPlaying)
Method Detail

getDuration

public int getDuration()
Returns the duration of the song, if available, in seconds. The duration attribute is only available for tracks retrieved by Playlist.fetch and Track.getInfo.

Returns:
duration in seconds

getArtist

public String getArtist()

getArtistMbid

public String getArtistMbid()

getAlbum

public String getAlbum()

getAlbumMbid

public String getAlbumMbid()

isFullTrackAvailable

public boolean isFullTrackAvailable()

isNowPlaying

public boolean isNowPlaying()

getLocation

public String getLocation()
Returns the location (URL) of this Track. This information is only available with the Radio services.

Returns:
the location

getLastFmInfo

public String getLastFmInfo(String key)
Returns last.fm specific information about this Track. Only available in Tracks, fetched from radio-playlists. key can be one of the following: Or use the available constants in this class.
Note that the key string is case sensitive.

Parameters:
key - A key
Returns:
associated value
See Also:
ARTIST_PAGE, ALBUM_PAGE, TRACK_PAGE

getPlayedWhen

public Date getPlayedWhen()
Returns the time when the track was played, if this data is available (e.g. for recent tracks) or null, if this data is not available.

Returns:
the date when the track was played or null

getPosition

public int getPosition()
Returns the position of this track in its associated album, or -1 if not available.

Returns:
the album position

search

public static Collection<Track> search(String track,
                                       String apiKey)
Searches for a track with the given name and returns a list of possible matches.

Parameters:
track - Track name
apiKey - The API key
Returns:
a list of possible matches
See Also:
search(String, String, int, String)

search

public static Collection<Track> search(String artist,
                                       String track,
                                       int limit,
                                       String apiKey)
Searches for a track with the given name and returns a list of possible matches. Specify an artist name or a limit to narrow down search results. Pass null for the artist parameter if you want to specify a limit but don't want to define an artist.

Parameters:
artist - Artist's name or null
track - Track name
limit - Number of maximum results
apiKey - The API key
Returns:
a list of possible matches

getTopTags

public static Collection<Tag> getTopTags(String artist,
                                         String trackOrMbid,
                                         String apiKey)
Retrieves the top tags for the given track. You either have to specify a track and artist name or a mbid. If you specify an mbid you may pass null for the first parameter.

Parameters:
artist - Artist name or null if an MBID is specified
trackOrMbid - Track name or MBID
apiKey - The API key
Returns:
list of tags

getTopFans

public static Collection<User> getTopFans(String artist,
                                          String trackOrMbid,
                                          String apiKey)
Retrieves the top fans for the given track. You either have to specify a track and artist name or a mbid. If you specify an mbid you may pass null for the first parameter.

Parameters:
artist - Artist name or null if an MBID is specified
trackOrMbid - Track name or MBID
apiKey - The API key
Returns:
list of fans

addTags

public static Result addTags(String artist,
                             String track,
                             String tags,
                             Session session)
Tag an album using a list of user supplied tags.

Parameters:
artist - The artist name in question
track - The track name in question
tags - A comma delimited list of user supplied tags to apply to this track. Accepts a maximum of 10 tags.
session - A Session instance.
Returns:
the Result of the operation

removeTag

public static Result removeTag(String artist,
                               String track,
                               String tag,
                               Session session)
Remove a user's tag from a track.

Parameters:
artist - The artist name in question
track - The track name in question
tag - A single user tag to remove from this track.
session - A Session instance.
Returns:
the Result of the operation

share

public static Result share(String artist,
                           String track,
                           String message,
                           String recipient,
                           Session session)
Share a track twith one or more Last.fm users or other friends.

Parameters:
artist - An artist name.
track - A track name.
message - A message to send with the recommendation or null. If not supplied a default message will be used.
recipient - A comma delimited list of email addresses or Last.fm usernames. Maximum is 10.
session - A Session instance
Returns:
the Result of the operation

love

public static Result love(String artist,
                          String track,
                          Session session)
Love a track for a user profile. This needs to be supplemented with a scrobbling submission containing the 'love' rating (see the audioscrobbler API).

Parameters:
artist - An artist name
track - A track name
session - A Session instance
Returns:
the Result of the operation

unlove

public static Result unlove(String artist,
                            String track,
                            Session session)
UnLove a track for a user profile.

Parameters:
artist - An artist name
track - A track name
session - A Session instance
Returns:
the Result of the operation

ban

public static Result ban(String artist,
                         String track,
                         Session session)
Ban a track for a given user profile. This needs to be supplemented with a scrobbling submission containing the 'ban' rating (see the audioscrobbler API).

Parameters:
artist - An artist name
track - A track name
session - A Session instance
Returns:
the Result of the operation

unban

public static Result unban(String artist,
                           String track,
                           Session session)
UnBan a track for a given user profile.

Parameters:
artist - An artist name
track - A track name
session - A Session instance
Returns:
the Result of the operation

getSimilar

public static Collection<Track> getSimilar(String artist,
                                           String trackOrMbid,
                                           String apiKey)
Get the similar tracks for this track on Last.fm, based on listening data.
You have to provide either an artist and a track name or an mbid. Pass null for parameters you don't need.

Parameters:
artist - The artist name in question
trackOrMbid - The track name in question or the track's MBID
apiKey - A Last.fm API key.
Returns:
a list of similar Tracks

getTags

public static Collection<String> getTags(String artist,
                                         String track,
                                         Session session)
Get the tags applied by an individual user to an track on Last.fm.

Parameters:
artist - The artist name in question
track - The track name in question
session - A Session instance
Returns:
a list of tags

getInfo

public static Track getInfo(String artist,
                            String trackOrMbid,
                            String apiKey)
Get the metadata for a track on Last.fm using the artist/track name or a musicbrainz id.

Parameters:
artist - The artist name in question or null if an mbid is specified
trackOrMbid - The track name in question or the musicbrainz id for the track
apiKey - A Last.fm API key.
Returns:
Track information

getInfo

public static Track getInfo(String artist,
                            String trackOrMbid,
                            Locale locale,
                            String username,
                            String apiKey)
Get the metadata for a track on Last.fm using the artist/track name or a musicbrainz id.

Parameters:
artist - The artist name in question or null if an mbid is specified
trackOrMbid - The track name in question or the musicbrainz id for the track
locale - The language to fetch info in, or null
username - The username for the context of the request, or null. If supplied, the user's playcount for this track and whether they have loved the track is included in the response
apiKey - A Last.fm API key.
Returns:
Track information

getBuylinks

public static Collection<BuyLink> getBuylinks(String artist,
                                              String albumOrMbid,
                                              String country,
                                              String apiKey)
Get a list of Buy Links for a particular Track. It is required that you supply either the artist and track params or the mbid param.

Parameters:
artist - The artist name in question
albumOrMbid - Track name or MBID
country - A country name, as defined by the ISO 3166-1 country names standard
apiKey - A Last.fm API key
Returns:
a Collection of BuyLinks

getCorrection

public static Track getCorrection(String artist,
                                  String track,
                                  String apiKey)
Use the last.fm corrections data to check whether the supplied track has a correction to a canonical track. This method returns a new Track object containing the corrected data, or null if the supplied Artist/Track combination was not found.

Parameters:
artist - The artist name to correct
track - The track name to correct
apiKey - A Last.fm API key
Returns:
a new Track, or null

scrobble

public static ScrobbleResult scrobble(ScrobbleData scrobbleData,
                                      Session session)

scrobble

public static ScrobbleResult scrobble(String artistName,
                                      String trackName,
                                      int timestamp,
                                      Session session)

scrobble

public static List<ScrobbleResult> scrobble(List<ScrobbleData> scrobbleData,
                                            Session session)

updateNowPlaying

public static ScrobbleResult updateNowPlaying(ScrobbleData scrobbleData,
                                              Session session)

updateNowPlaying

public static ScrobbleResult updateNowPlaying(String artistName,
                                              String trackName,
                                              Session session)

toString

public String toString()
Overrides:
toString in class Object