Package de.umass.lastfm
Class Track
- java.lang.Object
-
- de.umass.lastfm.ImageHolder
-
- de.umass.lastfm.MusicEntry
-
- de.umass.lastfm.Track
-
public class Track extends MusicEntry
Bean that contains information related toTrack
s and provides bindings to methods in thetrack.
namespace.- Author:
- Janni Kovacs
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.String
album
static java.lang.String
ALBUM_PAGE
protected java.lang.String
albumMbid
protected java.lang.String
artist
static java.lang.String
ARTIST_PAGE
protected java.lang.String
artistMbid
protected int
duration
protected boolean
fullTrackAvailable
protected java.util.Map<java.lang.String,java.lang.String>
lastFmExtensionInfos
protected java.lang.String
location
protected boolean
nowPlaying
protected java.util.Date
playedWhen
protected int
position
static java.lang.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
Constructors Modifier Constructor Description protected
Track(java.lang.String name, java.lang.String url, java.lang.String artist)
protected
Track(java.lang.String name, java.lang.String url, java.lang.String mbid, int playcount, int listeners, boolean streamable, java.lang.String artist, java.lang.String artistMbid, boolean fullTrackAvailable, boolean nowPlaying)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Result
addTags(java.lang.String artist, java.lang.String track, java.lang.String tags, Session session)
Tag an album using a list of user supplied tags.static Result
ban(java.lang.String artist, java.lang.String track, Session session)
Ban a track for a given user profile.java.lang.String
getAlbum()
java.lang.String
getAlbumMbid()
java.lang.String
getArtist()
java.lang.String
getArtistMbid()
static java.util.Collection<BuyLink>
getBuylinks(java.lang.String artist, java.lang.String albumOrMbid, java.lang.String country, java.lang.String apiKey)
Get a list of Buy Links for a particular Track.static Track
getCorrection(java.lang.String artist, java.lang.String track, java.lang.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(java.lang.String artist, java.lang.String trackOrMbid, java.lang.String apiKey)
Get the metadata for a track on Last.fm using the artist/track name or a musicbrainz id.static Track
getInfo(java.lang.String artist, java.lang.String trackOrMbid, java.util.Locale locale, java.lang.String username, java.lang.String apiKey)
Get the metadata for a track on Last.fm using the artist/track name or a musicbrainz id.java.lang.String
getLastFmInfo(java.lang.String key)
Returns last.fm specific information about this Track.java.lang.String
getLocation()
Returns the location (URL) of this Track.java.util.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 java.util.Collection<Track>
getSimilar(java.lang.String artist, java.lang.String trackOrMbid, java.lang.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 java.util.Collection<java.lang.String>
getTags(java.lang.String artist, java.lang.String track, Session session)
Get the tags applied by an individual user to an track on Last.fm.static java.util.Collection<User>
getTopFans(java.lang.String artist, java.lang.String trackOrMbid, java.lang.String apiKey)
Retrieves the top fans for the given track.static java.util.Collection<Tag>
getTopTags(java.lang.String artist, java.lang.String trackOrMbid, java.lang.String apiKey)
Retrieves the top tags for the given track.boolean
isFullTrackAvailable()
boolean
isNowPlaying()
static Result
love(java.lang.String artist, java.lang.String track, Session session)
Love a track for a user profile.static Result
removeTag(java.lang.String artist, java.lang.String track, java.lang.String tag, Session session)
Remove a user's tag from a track.static ScrobbleResult
scrobble(ScrobbleData scrobbleData, Session session)
static ScrobbleResult
scrobble(java.lang.String artistName, java.lang.String trackName, int timestamp, Session session)
static java.util.List<ScrobbleResult>
scrobble(java.util.List<ScrobbleData> scrobbleData, Session session)
static java.util.Collection<Track>
search(java.lang.String track, java.lang.String apiKey)
Searches for a track with the given name and returns a list of possible matches.static java.util.Collection<Track>
search(java.lang.String artist, java.lang.String track, int limit, java.lang.String apiKey)
Searches for a track with the given name and returns a list of possible matches.static Result
share(java.lang.String artist, java.lang.String track, java.lang.String message, java.lang.String recipient, Session session)
Share a track twith one or more Last.fm users or other friends.java.lang.String
toString()
static Result
unban(java.lang.String artist, java.lang.String track, Session session)
UnBan a track for a given user profile.static Result
unlove(java.lang.String artist, java.lang.String track, Session session)
UnLove a track for a user profile.static ScrobbleResult
updateNowPlaying(ScrobbleData scrobbleData, Session session)
static ScrobbleResult
updateNowPlaying(java.lang.String artistName, java.lang.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
-
-
-
-
Field Detail
-
ARTIST_PAGE
public static final java.lang.String ARTIST_PAGE
- See Also:
- Constant Field Values
-
ALBUM_PAGE
public static final java.lang.String ALBUM_PAGE
- See Also:
- Constant Field Values
-
TRACK_PAGE
public static final java.lang.String TRACK_PAGE
- See Also:
- Constant Field Values
-
artist
protected java.lang.String artist
-
artistMbid
protected java.lang.String artistMbid
-
album
protected java.lang.String album
-
albumMbid
protected java.lang.String albumMbid
-
position
protected int position
-
fullTrackAvailable
protected boolean fullTrackAvailable
-
nowPlaying
protected boolean nowPlaying
-
playedWhen
protected java.util.Date playedWhen
-
duration
protected int duration
-
location
protected java.lang.String location
-
lastFmExtensionInfos
protected java.util.Map<java.lang.String,java.lang.String> lastFmExtensionInfos
-
-
Constructor Detail
-
Track
protected Track(java.lang.String name, java.lang.String url, java.lang.String artist)
-
Track
protected Track(java.lang.String name, java.lang.String url, java.lang.String mbid, int playcount, int listeners, boolean streamable, java.lang.String artist, java.lang.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 byPlaylist.fetch
andTrack.getInfo
.- Returns:
- duration in seconds
-
getArtist
public java.lang.String getArtist()
-
getArtistMbid
public java.lang.String getArtistMbid()
-
getAlbum
public java.lang.String getAlbum()
-
getAlbumMbid
public java.lang.String getAlbumMbid()
-
isFullTrackAvailable
public boolean isFullTrackAvailable()
-
isNowPlaying
public boolean isNowPlaying()
-
getLocation
public java.lang.String getLocation()
Returns the location (URL) of this Track. This information is only available with theRadio
services.- Returns:
- the location
-
getLastFmInfo
public java.lang.String getLastFmInfo(java.lang.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:- artistpage
- albumpage
- trackpage
- buyTrackURL
- buyAlbumURL
- freeTrackURL
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 java.util.Date getPlayedWhen()
Returns the time when the track was played, if this data is available (e.g. for recent tracks) ornull
, 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 java.util.Collection<Track> search(java.lang.String track, java.lang.String apiKey)
Searches for a track with the given name and returns a list of possible matches.- Parameters:
track
- Track nameapiKey
- The API key- Returns:
- a list of possible matches
- See Also:
search(String, String, int, String)
-
search
public static java.util.Collection<Track> search(java.lang.String artist, java.lang.String track, int limit, java.lang.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. Passnull
for the artist parameter if you want to specify a limit but don't want to define an artist.- Parameters:
artist
- Artist's name ornull
track
- Track namelimit
- Number of maximum resultsapiKey
- The API key- Returns:
- a list of possible matches
-
getTopTags
public static java.util.Collection<Tag> getTopTags(java.lang.String artist, java.lang.String trackOrMbid, java.lang.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 passnull
for the first parameter.- Parameters:
artist
- Artist name ornull
if an MBID is specifiedtrackOrMbid
- Track name or MBIDapiKey
- The API key- Returns:
- list of tags
-
getTopFans
public static java.util.Collection<User> getTopFans(java.lang.String artist, java.lang.String trackOrMbid, java.lang.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 passnull
for the first parameter.- Parameters:
artist
- Artist name ornull
if an MBID is specifiedtrackOrMbid
- Track name or MBIDapiKey
- The API key- Returns:
- list of fans
-
addTags
public static Result addTags(java.lang.String artist, java.lang.String track, java.lang.String tags, Session session)
Tag an album using a list of user supplied tags.- Parameters:
artist
- The artist name in questiontrack
- The track name in questiontags
- 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(java.lang.String artist, java.lang.String track, java.lang.String tag, Session session)
Remove a user's tag from a track.- Parameters:
artist
- The artist name in questiontrack
- The track name in questiontag
- A single user tag to remove from this track.session
- A Session instance.- Returns:
- the Result of the operation
-
share
public static Result share(java.lang.String artist, java.lang.String track, java.lang.String message, java.lang.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 ornull
. 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(java.lang.String artist, java.lang.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 nametrack
- A track namesession
- A Session instance- Returns:
- the Result of the operation
-
unlove
public static Result unlove(java.lang.String artist, java.lang.String track, Session session)
UnLove a track for a user profile.- Parameters:
artist
- An artist nametrack
- A track namesession
- A Session instance- Returns:
- the Result of the operation
-
ban
public static Result ban(java.lang.String artist, java.lang.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 nametrack
- A track namesession
- A Session instance- Returns:
- the Result of the operation
-
unban
public static Result unban(java.lang.String artist, java.lang.String track, Session session)
UnBan a track for a given user profile.- Parameters:
artist
- An artist nametrack
- A track namesession
- A Session instance- Returns:
- the Result of the operation
-
getSimilar
public static java.util.Collection<Track> getSimilar(java.lang.String artist, java.lang.String trackOrMbid, java.lang.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. Passnull
for parameters you don't need.- Parameters:
artist
- The artist name in questiontrackOrMbid
- The track name in question or the track's MBIDapiKey
- A Last.fm API key.- Returns:
- a list of similar
Track
s
-
getTags
public static java.util.Collection<java.lang.String> getTags(java.lang.String artist, java.lang.String track, Session session)
Get the tags applied by an individual user to an track on Last.fm.- Parameters:
artist
- The artist name in questiontrack
- The track name in questionsession
- A Session instance- Returns:
- a list of tags
-
getInfo
public static Track getInfo(java.lang.String artist, java.lang.String trackOrMbid, java.lang.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 ornull
if an mbid is specifiedtrackOrMbid
- The track name in question or the musicbrainz id for the trackapiKey
- A Last.fm API key.- Returns:
- Track information
-
getInfo
public static Track getInfo(java.lang.String artist, java.lang.String trackOrMbid, java.util.Locale locale, java.lang.String username, java.lang.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 ornull
if an mbid is specifiedtrackOrMbid
- The track name in question or the musicbrainz id for the tracklocale
- The language to fetch info in, ornull
username
- The username for the context of the request, ornull
. If supplied, the user's playcount for this track and whether they have loved the track is included in the responseapiKey
- A Last.fm API key.- Returns:
- Track information
-
getBuylinks
public static java.util.Collection<BuyLink> getBuylinks(java.lang.String artist, java.lang.String albumOrMbid, java.lang.String country, java.lang.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 questionalbumOrMbid
- Track name or MBIDcountry
- A country name, as defined by the ISO 3166-1 country names standardapiKey
- A Last.fm API key- Returns:
- a Collection of
BuyLink
s
-
getCorrection
public static Track getCorrection(java.lang.String artist, java.lang.String track, java.lang.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 newTrack
object containing the corrected data, ornull
if the supplied Artist/Track combination was not found.- Parameters:
artist
- The artist name to correcttrack
- The track name to correctapiKey
- A Last.fm API key- Returns:
- a new
Track
, ornull
-
scrobble
public static ScrobbleResult scrobble(ScrobbleData scrobbleData, Session session)
-
scrobble
public static ScrobbleResult scrobble(java.lang.String artistName, java.lang.String trackName, int timestamp, Session session)
-
scrobble
public static java.util.List<ScrobbleResult> scrobble(java.util.List<ScrobbleData> scrobbleData, Session session)
-
updateNowPlaying
public static ScrobbleResult updateNowPlaying(ScrobbleData scrobbleData, Session session)
-
updateNowPlaying
public static ScrobbleResult updateNowPlaying(java.lang.String artistName, java.lang.String trackName, Session session)
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-