Class: LastFM::Api::Track
- Inherits:
-
Object
- Object
- LastFM::Api::Track
- Defined in:
- lib/lastfm/api/track.rb
Class Method Summary collapse
-
.add_tags(params) ⇒ Object
Add a list of user supplied tags to a track.
-
.ban(params) ⇒ Object
Ban a track for the current user.
-
.get_buylinks(params) ⇒ Array<LastFM::Buylink>
Get a list of buy Links for a track.
-
.get_correction(params) ⇒ Object
Use the last.fm corrections data to check whether the supplied track has a correction to a canonical track.
-
.get_fingerprint_metadata(params) ⇒ Object
Retrieve track metadata associated with a fingerprint id generated by the Last.fm Fingerprinter.
-
.get_info(params) ⇒ LastFM::Track
Get the metadata for a track.
-
.get_shouts(params) ⇒ Array<LastFM::Shout>
Get shouts for a track.
-
.get_similar(params) ⇒ Array<LastFM::Track>
Get similar tracks for a track on Last.fm, based on listening data.
-
.get_tags(params) ⇒ Object
Get the tags on a track.
-
.get_top_fans(params) ⇒ Object
Get the top fans for a track, based on listening data.
-
.get_top_tags(params) ⇒ Array<LastFM::Tag>
Get the top fans for a track, ordered by tag count.
-
.love(params) ⇒ Object
Love a track for the current user.
-
.remove_tag(params) ⇒ Object
Remove a user’s tag from a track.
-
.scrobble(params) ⇒ Object
Used to add a track-play to a user’s profile.
-
.search(params) ⇒ Array<LastFM::Track>
Search for a track by track name.
-
.share(params) ⇒ Object
Share a track twith one or more Last.fm users or other friends.
-
.unban(params) ⇒ Object
Unban a track for the current user.
-
.unlove(params) ⇒ Object
Unlove a track for the current user.
-
.update_now_playing(params) ⇒ Object
Used to notify Last.fm that a user has started listening to a track.
Class Method Details
.add_tags(params) ⇒ Object
Add a list of user supplied tags to a track.
12 13 14 15 |
# File 'lib/lastfm/api/track.rb', line 12 def ( params ) LastFM.requires_authentication LastFM.post( "track.addTags", params ) end |
.ban(params) ⇒ Object
Ban a track for the current user.
22 23 24 25 |
# File 'lib/lastfm/api/track.rb', line 22 def ban( params ) LastFM.requires_authentication LastFM.post( "track.ban", params ) end |
.get_buylinks(params) ⇒ Array<LastFM::Buylink>
Get a list of buy Links for a track.
36 37 38 39 40 41 42 43 |
# File 'lib/lastfm/api/track.rb', line 36 def get_buylinks( params ) xml = LastFM.get( "track.getBuylinks", params ) [:physical, :download].each_with_object([]) do |type, buylinks| xml.find("affiliations/#{type}s/affiliation").each do |buylink| buylinks << LastFM::Buylink.from_xml( buylink, :type => type ) end end end |
.get_correction(params) ⇒ Object
Use the last.fm corrections data to check whether the supplied track has a correction to a canonical track
50 51 52 |
# File 'lib/lastfm/api/track.rb', line 50 def get_correction( params ) LastFM.get( "track.getCorrection", params ) end |
.get_fingerprint_metadata(params) ⇒ Object
Retrieve track metadata associated with a fingerprint id generated by the Last.fm Fingerprinter. Returns track elements, along with a ‘rank’ value between 0 and 1 reflecting the confidence for each match.
62 63 64 |
# File 'lib/lastfm/api/track.rb', line 62 def ( params ) LastFM.get( "track.getFingerPrintMetadata", params ) end |
.get_info(params) ⇒ LastFM::Track
Get the metadata for a track.
75 76 77 78 |
# File 'lib/lastfm/api/track.rb', line 75 def get_info( params ) xml = LastFM.get( "track.getInfo", params ) LastFM::Track.from_xml( xml ) end |
.get_shouts(params) ⇒ Array<LastFM::Shout>
Get shouts for a track.
90 91 92 93 94 95 |
# File 'lib/lastfm/api/track.rb', line 90 def get_shouts( params ) xml = LastFM.get( "track.getShouts", params ) xml.find('shouts/shout').map do |shout| LastFM::Shout.from_xml( shout ) end end |
.get_similar(params) ⇒ Array<LastFM::Track>
Get similar tracks for a track on Last.fm, based on listening data.
106 107 108 109 110 111 |
# File 'lib/lastfm/api/track.rb', line 106 def get_similar( params ) xml = LastFM.get( "track.getSimilar", params ) xml.find('similartracks/track').map do |track| LastFM::Track.from_xml( track ) end end |
.get_tags(params) ⇒ Object
Get the tags on a track.
121 122 123 124 125 |
# File 'lib/lastfm/api/track.rb', line 121 def ( params ) secure = !params.include?(:user) LastFM.requires_authentication if secure LastFM.post( "track.getTags", params, secure ) end |
.get_top_fans(params) ⇒ Object
Get the top fans for a track, based on listening data.
134 135 136 |
# File 'lib/lastfm/api/track.rb', line 134 def get_top_fans( params ) LastFM.get( "track.getTopFans", params ) end |
.get_top_tags(params) ⇒ Array<LastFM::Tag>
Get the top fans for a track, ordered by tag count.
146 147 148 149 150 151 |
# File 'lib/lastfm/api/track.rb', line 146 def ( params ) xml = LastFM.get( "track.getTopTags", params ) xml.find('toptags/tag').map do |tag| LastFM::Tag.from_xml( tag ) end end |
.love(params) ⇒ Object
Love a track for the current user.
158 159 160 161 |
# File 'lib/lastfm/api/track.rb', line 158 def love( params ) LastFM.requires_authentication LastFM.post( "track.love", params ) end |
.remove_tag(params) ⇒ Object
Remove a user’s tag from a track.
169 170 171 172 |
# File 'lib/lastfm/api/track.rb', line 169 def remove_tag( params ) LastFM.requires_authentication LastFM.post( "track.removeTag", params ) end |
.scrobble(params) ⇒ Object
Used to add a track-play to a user’s profile. Scrobble a track, or a batch of tracks. Single tracks may be passed using the Object types listed, batches of tracks must be passed in as Arrays of each Object type. Allows up to a maximum of 50 scrobbles per batch. For batch scrobbles, Array indices of optional parameters must line up with the indicies of their corresponding tracks.
192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/lastfm/api/track.rb', line 192 def scrobble( params ) LastFM.requires_authentication # Tracks are passed to the service using array notation for each of the above params array_params = {} params.each do |hkey, hval| hval = hval.to_i if hval.is_a?(Time) Array(hval).each_with_index do |aval, index| array_params["#{hkey}[#{index}]"] = aval end end LastFM.post( "track.scrobble", array_params ) end |
.search(params) ⇒ Array<LastFM::Track>
Search for a track by track name. Returns track matches sorted by relevance.
213 214 215 216 217 218 |
# File 'lib/lastfm/api/track.rb', line 213 def search( params ) xml = LastFM.get( "track.search", params ) xml.find('results/trackmatches/track').map do |track| LastFM::Track.from_xml( track ) end end |
.share(params) ⇒ Object
Share a track twith one or more Last.fm users or other friends.
228 229 230 231 |
# File 'lib/lastfm/api/track.rb', line 228 def share( params ) LastFM.requires_authentication LastFM.post( "track.share", params ) end |
.unban(params) ⇒ Object
Unban a track for the current user.
238 239 240 241 |
# File 'lib/lastfm/api/track.rb', line 238 def unban( params ) LastFM.requires_authentication LastFM.post( "track.unban", params ) end |
.unlove(params) ⇒ Object
Unlove a track for the current user.
248 249 250 251 |
# File 'lib/lastfm/api/track.rb', line 248 def unlove( params ) LastFM.requires_authentication LastFM.post( "track.unlove", params ) end |
.update_now_playing(params) ⇒ Object
Used to notify Last.fm that a user has started listening to a track.
264 265 266 267 |
# File 'lib/lastfm/api/track.rb', line 264 def ( params ) LastFM.requires_authentication LastFM.post( "track.updateNowPlaying", params ) end |