Class: LastFM::Track
Instance Attribute Summary collapse
-
#album ⇒ LastFM::Album
The current value of album.
-
#artist ⇒ LastFM::Artist, String
The current value of artist.
-
#duration ⇒ Fixnum
The current value of duration.
-
#id ⇒ Fixnum
The current value of id.
-
#images ⇒ Hash
The current value of images.
-
#listeners ⇒ Fixnum
The current value of listeners.
-
#mbid ⇒ String
The current value of mbid.
-
#name ⇒ String
The current value of name.
-
#playcount ⇒ Fixnum
The current value of playcount.
-
#position ⇒ Fixnum
The current value of position.
-
#streamable ⇒ Boolean
The current value of streamable.
-
#streamable_fulltrack ⇒ Boolean
The current value of streamable_fulltrack.
-
#tags ⇒ Array
The current value of tags.
-
#url ⇒ String
The current value of url.
-
#wiki ⇒ LastFM::Wii
The current value of wiki.
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.
Instance Method Summary collapse
Methods inherited from Struct
from_xml, inherited, #initialize, package, #to_json
Constructor Details
This class inherits a constructor from LastFM::Struct
Instance Attribute Details
#album ⇒ LastFM::Album
Returns the current value of album.
18 19 20 |
# File 'lib/lastfm/track.rb', line 18 def album @album end |
#artist ⇒ LastFM::Artist, String
Returns the current value of artist.
18 19 20 |
# File 'lib/lastfm/track.rb', line 18 def artist @artist end |
#duration ⇒ Fixnum
Returns the current value of duration.
18 19 20 |
# File 'lib/lastfm/track.rb', line 18 def duration @duration end |
#id ⇒ Fixnum
Returns the current value of id.
18 19 20 |
# File 'lib/lastfm/track.rb', line 18 def id @id end |
#images ⇒ Hash
Returns the current value of images.
18 19 20 |
# File 'lib/lastfm/track.rb', line 18 def images @images end |
#listeners ⇒ Fixnum
Returns the current value of listeners.
18 19 20 |
# File 'lib/lastfm/track.rb', line 18 def listeners @listeners end |
#mbid ⇒ String
Returns the current value of mbid.
18 19 20 |
# File 'lib/lastfm/track.rb', line 18 def mbid @mbid end |
#name ⇒ String
Returns the current value of name.
18 19 20 |
# File 'lib/lastfm/track.rb', line 18 def name @name end |
#playcount ⇒ Fixnum
Returns the current value of playcount.
18 19 20 |
# File 'lib/lastfm/track.rb', line 18 def playcount @playcount end |
#position ⇒ Fixnum
Returns the current value of position.
18 19 20 |
# File 'lib/lastfm/track.rb', line 18 def position @position end |
#streamable ⇒ Boolean
Returns the current value of streamable.
18 19 20 |
# File 'lib/lastfm/track.rb', line 18 def streamable @streamable end |
#streamable_fulltrack ⇒ Boolean
Returns the current value of streamable_fulltrack.
18 19 20 |
# File 'lib/lastfm/track.rb', line 18 def streamable_fulltrack @streamable_fulltrack end |
#tags ⇒ Array
Returns the current value of tags.
18 19 20 |
# File 'lib/lastfm/track.rb', line 18 def end |
#url ⇒ String
Returns the current value of url.
18 19 20 |
# File 'lib/lastfm/track.rb', line 18 def url @url end |
#wiki ⇒ LastFM::Wii
Returns the current value of wiki.
18 19 20 |
# File 'lib/lastfm/track.rb', line 18 def wiki @wiki end |
Class Method Details
.add_tags(params) ⇒ Object
Add a list of user supplied tags to a track.
65 66 67 68 |
# File 'lib/lastfm/track.rb', line 65 def ( params ) LastFM.requires_authentication LastFM.post( "track.addTags", params ) end |
.ban(params) ⇒ Object
Ban a track for the current user.
75 76 77 78 |
# File 'lib/lastfm/track.rb', line 75 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.
89 90 91 92 93 94 95 96 |
# File 'lib/lastfm/track.rb', line 89 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
103 104 105 |
# File 'lib/lastfm/track.rb', line 103 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.
115 116 117 |
# File 'lib/lastfm/track.rb', line 115 def ( params ) LastFM.get( "track.getFingerPrintMetadata", params ) end |
.get_info(params) ⇒ LastFM::Track
Get the metadata for a track.
128 129 130 131 |
# File 'lib/lastfm/track.rb', line 128 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.
143 144 145 146 147 148 |
# File 'lib/lastfm/track.rb', line 143 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.
159 160 161 162 163 164 |
# File 'lib/lastfm/track.rb', line 159 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.
174 175 176 177 178 |
# File 'lib/lastfm/track.rb', line 174 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.
187 188 189 |
# File 'lib/lastfm/track.rb', line 187 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.
199 200 201 202 203 204 |
# File 'lib/lastfm/track.rb', line 199 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.
211 212 213 214 |
# File 'lib/lastfm/track.rb', line 211 def love( params ) LastFM.requires_authentication LastFM.post( "track.love", params ) end |
.remove_tag(params) ⇒ Object
Remove a user’s tag from a track.
222 223 224 225 |
# File 'lib/lastfm/track.rb', line 222 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.
245 246 247 248 249 250 251 252 253 254 255 256 |
# File 'lib/lastfm/track.rb', line 245 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.
266 267 268 269 270 271 |
# File 'lib/lastfm/track.rb', line 266 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.
281 282 283 284 |
# File 'lib/lastfm/track.rb', line 281 def share( params ) LastFM.requires_authentication LastFM.post( "track.share", params ) end |
.unban(params) ⇒ Object
Unban a track for the current user.
291 292 293 294 |
# File 'lib/lastfm/track.rb', line 291 def unban( params ) LastFM.requires_authentication LastFM.post( "track.unban", params ) end |
.unlove(params) ⇒ Object
Unlove a track for the current user.
301 302 303 304 |
# File 'lib/lastfm/track.rb', line 301 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.
317 318 319 320 |
# File 'lib/lastfm/track.rb', line 317 def ( params ) LastFM.requires_authentication LastFM.post( "track.updateNowPlaying", params ) end |
Instance Method Details
#update_from_node(node) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/lastfm/track.rb', line 20 def update_from_node(node) case node.name.to_sym when :name self.name = node.content when :id self.id = node.content.to_i when :duration self.duration = node.content.to_i when :mbid self.mbid = node.content when :url self.url = node.content when :listeners self.listeners = node.content.to_i when :playcount self.playcount = node.content.to_i when :streamable self.streamable = (node.content == '1') self.streamable_fulltrack = (node['fulltrack'] == '1') when :image self.images ||= {} self.images.merge!({node['size'].to_sym => node.content}) when :artist self.artist = (node.find('*').count == 0) ? node.content : LastFM::Artist.from_xml(node) when :album self.position = node['position'].to_i self.album = LastFM::Album.from_xml(node) when :toptags self. = node.find('tag').map do |tag| LastFM::Tag.from_xml(tag) end when :wiki self.wiki = LastFM::Wiki.from_xml(node) end end |