Class: Scrobbler::Track
Instance Attribute Summary collapse
-
#album ⇒ Object
Returns the value of attribute album.
-
#artist ⇒ Object
Returns the value of attribute artist.
-
#count ⇒ Object
Returns the value of attribute count.
-
#date ⇒ Object
Returns the value of attribute date.
-
#duration ⇒ Object
Returns the value of attribute duration.
-
#id ⇒ Object
Returns the value of attribute id.
-
#listeners ⇒ Object
Returns the value of attribute listeners.
-
#mbid ⇒ Object
Returns the value of attribute mbid.
-
#name ⇒ Object
Returns the value of attribute name.
-
#now_playing ⇒ Object
Returns the value of attribute now_playing.
-
#playcount ⇒ Object
Returns the value of attribute playcount.
-
#rank ⇒ Object
Returns the value of attribute rank.
-
#streamable ⇒ Object
Returns the value of attribute streamable.
-
#tagcount ⇒ Object
Returns the value of attribute tagcount.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
- #==(otherTrack) ⇒ Object
- #add_tags(tags) ⇒ Object
- #ban ⇒ Object
-
#initialize(input, data = {}) ⇒ Track
constructor
A new instance of Track.
- #load_info ⇒ Object
- #top_fans(force = false) ⇒ Object
- #top_tags(force = false) ⇒ Object
Methods included from ImageClassFuncs
Methods included from ImageObjectFuncs
Methods inherited from Base
api_key=, connection, get, maybe_streamable_attribute, maybe_streamable_node, post_request, request, sanitize, secret=
Constructor Details
#initialize(input, data = {}) ⇒ Track
Returns a new instance of Track.
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/scrobbler/track.rb', line 94 def initialize(input, data={}) super() #check for old style parameter arguments if data.class == String data = {:name => data} end if input.class == String && data[:mbid] && data[:mbid] == true raise ArgumentError, "MBID is required for an MBID query" if input.blank? @mbid = input load_album_info() unless !data[:include_info].nil? && data[:include_info] == false else raise ArgumentError, "Artist is required" if input.blank? raise ArgumentError, "Name is required" if data[:name].blank? @artist = Artist.new(input) @name = data[:name] load_info() if data[:include_info] end end |
Instance Attribute Details
#album ⇒ Object
Returns the value of attribute album.
43 44 45 |
# File 'lib/scrobbler/track.rb', line 43 def album @album end |
#artist ⇒ Object
Returns the value of attribute artist.
42 43 44 |
# File 'lib/scrobbler/track.rb', line 42 def artist @artist end |
#count ⇒ Object
Returns the value of attribute count.
42 43 44 |
# File 'lib/scrobbler/track.rb', line 42 def count @count end |
#date ⇒ Object
Returns the value of attribute date.
43 44 45 |
# File 'lib/scrobbler/track.rb', line 43 def date @date end |
#duration ⇒ Object
Returns the value of attribute duration.
44 45 46 |
# File 'lib/scrobbler/track.rb', line 44 def duration @duration end |
#id ⇒ Object
Returns the value of attribute id.
42 43 44 |
# File 'lib/scrobbler/track.rb', line 42 def id @id end |
#listeners ⇒ Object
Returns the value of attribute listeners.
44 45 46 |
# File 'lib/scrobbler/track.rb', line 44 def listeners @listeners end |
#mbid ⇒ Object
Returns the value of attribute mbid.
42 43 44 |
# File 'lib/scrobbler/track.rb', line 42 def mbid @mbid end |
#name ⇒ Object
Returns the value of attribute name.
42 43 44 |
# File 'lib/scrobbler/track.rb', line 42 def name @name end |
#now_playing ⇒ Object
Returns the value of attribute now_playing.
43 44 45 |
# File 'lib/scrobbler/track.rb', line 43 def @now_playing end |
#playcount ⇒ Object
Returns the value of attribute playcount.
42 43 44 |
# File 'lib/scrobbler/track.rb', line 42 def playcount @playcount end |
#rank ⇒ Object
Returns the value of attribute rank.
42 43 44 |
# File 'lib/scrobbler/track.rb', line 42 def rank @rank end |
#streamable ⇒ Object
Returns the value of attribute streamable.
43 44 45 |
# File 'lib/scrobbler/track.rb', line 43 def streamable @streamable end |
#tagcount ⇒ Object
Returns the value of attribute tagcount.
43 44 45 |
# File 'lib/scrobbler/track.rb', line 43 def tagcount @tagcount end |
#url ⇒ Object
Returns the value of attribute url.
42 43 44 |
# File 'lib/scrobbler/track.rb', line 42 def url @url end |
Class Method Details
.data_from_xml(xml, o = {}) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/scrobbler/track.rb', line 60 def data_from_xml(xml, o = {}) o = {:include_album_info => true, :include_artist_info => true}.merge(o) data = {} xml.children.each do |child| data[:name] = child.content if child.name == 'name' || child.name == 'title' data[:mbid] = child.content.to_i if child.name == 'mbid' data[:id] = child.content.to_i if child.name == 'id' data[:duration] = child.content.to_i if child.name == 'duration' data[:url] = child.content if child.name == 'url' || child.name == 'identifier' data[:date] = Time.parse(child.content) if child.name == 'date' data[:listeners] = child.content.to_i if child.name == 'listeners' data[:artist] = Artist.new_from_xml(child, o) if (child.name == 'artist' || child.name == 'creator') && o[:include_artist_info] data[:album] = Album.new_from_xml(child, o) if child.name == 'album' && o[:include_album_info] data[:playcount] = child.content.to_i if child.name == 'playcount' data[:tagcount] = child.content.to_i if child.name == 'tagcount' maybe_image_node(data, child) if child.name == 'streamable' if ['1', 'true'].include?(child.content) data[:streamable] = true else data[:streamable] = false end end end data[:rank] = xml['rank'].to_i if xml['rank'] data[:now_playing] = true if xml['nowplaying'] && xml['nowplaying'] == 'true' data[:now_playing] = false if data[:now_playing].nil? o.merge(data) end |
.new_from_xml(xml, o = {}) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/scrobbler/track.rb', line 47 def new_from_xml(xml, o = {}) data = self.data_from_xml(xml, o) return nil if data[:name].nil? if data[:artist].blank? if data[:creator].blank? data[:artist] = data[:creator]; else raise Error, "Supplied XML to track has no artist or creator" end end Track.new(data[:artist], data) end |
Instance Method Details
#==(otherTrack) ⇒ Object
145 146 147 148 149 150 |
# File 'lib/scrobbler/track.rb', line 145 def ==(otherTrack) if otherTrack.is_a?(Scrobbler::Track) return ((@name == otherTrack.name) && (@artist == otherTrack.artist)) end false end |
#add_tags(tags) ⇒ Object
114 115 116 117 |
# File 'lib/scrobbler/track.rb', line 114 def () # This function requires authentication, but SimpleAuth is not yet 2.0 raise NotImplementedError end |
#ban ⇒ Object
119 120 121 122 |
# File 'lib/scrobbler/track.rb', line 119 def ban # This function requires authentication, but SimpleAuth is not yet 2.0 raise NotImplementedError end |
#load_info ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/scrobbler/track.rb', line 125 def load_info return nil if @info_loaded doc = Base.request('track.getinfo', :artist => @artist.name, :track => @name) doc.root.children.each do |child| next unless child.name == 'track' data = self.class.data_from_xml(child) populate_data(data) @info_loaded = true break end end |
#top_fans(force = false) ⇒ Object
137 138 139 |
# File 'lib/scrobbler/track.rb', line 137 def top_fans(force=false) get_response('track.gettopfans', :fans, 'topfans', 'user', {:artist=>@artist.name, :track=>@name}, force) end |
#top_tags(force = false) ⇒ Object
141 142 143 |
# File 'lib/scrobbler/track.rb', line 141 def (force=false) get_response('track.gettoptags', :top_tags, 'toptags', 'tag', {:artist=>@artist.name.to_s, :track=>@name}, force) end |