Class: Scrobbler::Album
Instance Attribute Summary collapse
-
#album_id ⇒ Object
readonly
Returns the value of attribute album_id.
-
#artist ⇒ Object
readonly
Returns the value of attribute artist.
-
#artist_mbid ⇒ Object
readonly
Returns the value of attribute artist_mbid.
-
#chartposition ⇒ Object
readonly
needed for weekly album charts.
-
#count ⇒ Object
readonly
needed on top albums for tag.
-
#image_large ⇒ Object
readonly
Returns the value of attribute image_large.
-
#image_medium ⇒ Object
readonly
Returns the value of attribute image_medium.
-
#image_small ⇒ Object
readonly
Returns the value of attribute image_small.
-
#listeners ⇒ Object
readonly
Returns the value of attribute listeners.
-
#mbid ⇒ Object
readonly
Returns the value of attribute mbid.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#playcount ⇒ Object
readonly
Returns the value of attribute playcount.
-
#playlist ⇒ Object
readonly
needed on top albums for tag.
-
#position ⇒ Object
readonly
needed for weekly album charts.
-
#rank ⇒ Object
readonly
Returns the value of attribute rank.
-
#reach ⇒ Object
readonly
Returns the value of attribute reach.
-
#release_date ⇒ Object
readonly
Returns the value of attribute release_date.
-
#tagcount ⇒ Object
readonly
Returns the value of attribute tagcount.
-
#top_tags ⇒ Object
readonly
Returns the value of attribute top_tags.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
-
#add_tags(tags) ⇒ Object
Tag an album using a list of user supplied tags.
-
#initialize(artist, name, data = {}) ⇒ Album
constructor
If the additional parameter :include_info is set to true, additional information is loaded.
-
#load_album_info ⇒ Object
Load additional information about this album.
- #load_track_info ⇒ Object
-
#remove_tag ⇒ Object
Remove a user’s tag from an album.
-
#tags ⇒ Object
Get the tags applied by an individual user to an album on Last.fm.
Methods inherited from Base
api_key=, connection, get, maybe_streamable_attribute, maybe_streamable_node, post_request, request, sanitize, secret=
Constructor Details
#initialize(artist, name, data = {}) ⇒ Album
Albums should be able to be created via a MusicBrainz id too
If the additional parameter :include_info is set to true, additional information is loaded
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/scrobbler/album.rb', line 111 def initialize(artist, name, data={}) super() raise ArgumentError, "Artist or MBID is required" if artist.blank? #check for old style parameter arguments, infer MBID if only an artist is given if artist.class == String && name.blank? && data == {} raise ArgumentError, "MBID is required for an MBID query" if input.blank? @mbid = input load_album_info() # data must be fetched since all we have is an mbid, nothing else useful else raise ArgumentError, "Artist is required" if artist.blank? raise ArgumentError, "Album Name is required" if name.blank? @artist = Artist.new(artist) @name = name load_album_info() if data[:include_info] || data[:include_all_info] load_track_info() if data[:include_all_info] end end |
Instance Attribute Details
#album_id ⇒ Object (readonly)
Returns the value of attribute album_id.
50 51 52 |
# File 'lib/scrobbler/album.rb', line 50 def album_id @album_id end |
#artist ⇒ Object (readonly)
Returns the value of attribute artist.
50 51 52 |
# File 'lib/scrobbler/album.rb', line 50 def artist @artist end |
#artist_mbid ⇒ Object (readonly)
Returns the value of attribute artist_mbid.
50 51 52 |
# File 'lib/scrobbler/album.rb', line 50 def artist_mbid @artist_mbid end |
#chartposition ⇒ Object (readonly)
needed for weekly album charts
58 59 60 |
# File 'lib/scrobbler/album.rb', line 58 def chartposition @chartposition end |
#count ⇒ Object (readonly)
needed on top albums for tag
55 56 57 |
# File 'lib/scrobbler/album.rb', line 55 def count @count end |
#image_large ⇒ Object (readonly)
Returns the value of attribute image_large.
52 53 54 |
# File 'lib/scrobbler/album.rb', line 52 def image_large @image_large end |
#image_medium ⇒ Object (readonly)
Returns the value of attribute image_medium.
52 53 54 |
# File 'lib/scrobbler/album.rb', line 52 def image_medium @image_medium end |
#image_small ⇒ Object (readonly)
Returns the value of attribute image_small.
52 53 54 |
# File 'lib/scrobbler/album.rb', line 52 def image_small @image_small end |
#listeners ⇒ Object (readonly)
Returns the value of attribute listeners.
51 52 53 |
# File 'lib/scrobbler/album.rb', line 51 def listeners @listeners end |
#mbid ⇒ Object (readonly)
Returns the value of attribute mbid.
50 51 52 |
# File 'lib/scrobbler/album.rb', line 50 def mbid @mbid end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
50 51 52 |
# File 'lib/scrobbler/album.rb', line 50 def name @name end |
#playcount ⇒ Object (readonly)
Returns the value of attribute playcount.
50 51 52 |
# File 'lib/scrobbler/album.rb', line 50 def playcount @playcount end |
#playlist ⇒ Object (readonly)
needed on top albums for tag
55 56 57 |
# File 'lib/scrobbler/album.rb', line 55 def playlist @playlist end |
#position ⇒ Object (readonly)
needed for weekly album charts
58 59 60 |
# File 'lib/scrobbler/album.rb', line 58 def position @position end |
#rank ⇒ Object (readonly)
Returns the value of attribute rank.
50 51 52 |
# File 'lib/scrobbler/album.rb', line 50 def rank @rank end |
#reach ⇒ Object (readonly)
Returns the value of attribute reach.
51 52 53 |
# File 'lib/scrobbler/album.rb', line 51 def reach @reach end |
#release_date ⇒ Object (readonly)
Returns the value of attribute release_date.
51 52 53 |
# File 'lib/scrobbler/album.rb', line 51 def release_date @release_date end |
#tagcount ⇒ Object (readonly)
Returns the value of attribute tagcount.
52 53 54 |
# File 'lib/scrobbler/album.rb', line 52 def tagcount @tagcount end |
#top_tags ⇒ Object (readonly)
Returns the value of attribute top_tags.
51 52 53 |
# File 'lib/scrobbler/album.rb', line 51 def @top_tags end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
50 51 52 |
# File 'lib/scrobbler/album.rb', line 50 def url @url end |
Class Method Details
.data_from_xml(xml, o = {}) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/scrobbler/album.rb', line 68 def data_from_xml(xml, o = {}) data = {} o = {:include_artist_info => true}.merge(o) xml.children.each do |child| data[:name] = child.content if ['name', 'title'].include?(child.name) data[:album_id] = child.content.to_i if child.name == 'id' data[:playcount] = child.content.to_i if child.name == 'playcount' data[:tagcount] = child.content.to_i if child.name == 'tagcount' data[:release_date] = Time.parse(child.content.strip) if child.name == 'releasedate' data[:listeners] = child.content.to_i if child.name == 'listeners' data[:mbid] = child.content if child.name == 'mbid' data[:url] = child.content if child.name == 'url' data[:artist] = Artist.new_from_xml(child) if (child.name == 'artist' || child.name == 'creator') && o[:include_artist_info] maybe_image_node(data, child) if child.name == 'toptags' data[:top_tags] = [] child.children.each do |grandchild| next unless grandchild.name == 'tag' data[:top_tags] << Tag.new_from_xml(grandchild) end end end # If we have not found anything in the content of this node yet then # this must be a simple artist node which has the name of the artist # as its content data[:name] = xml.content if data == {} # Get all information from the root's attributes data[:mbid] = xml['mbid'] if xml['mbid'] data[:rank] = xml['rank'].to_i if xml['rank'] data[:position] = xml['position'].to_i if xml['position'] # If there is no name defined, than this was an empty album tag return nil if data[:name].empty? data end |
Instance Method Details
#add_tags(tags) ⇒ Object
Tag an album using a list of user supplied tags.
164 165 166 167 |
# File 'lib/scrobbler/album.rb', line 164 def () # This function require authentication, but SimpleAuth is not yet 2.0 raise NotImplementedError end |
#load_album_info ⇒ Object
Parse wiki content
Add language code for wiki translation
Load additional information about this album
Calls “album.getinfo” REST method
139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/scrobbler/album.rb', line 139 def load_album_info return nil if @album_info_loaded params = @mbid ? {'mbid' => @mbid} : {'artist' => @artist.name, 'album' => @name} xml = Base.request('album.getinfo', params) unless xml.root['status'] == 'failed' xml.root.children.each do |child| next unless child.name == 'album' data = self.class.data_from_xml(child) populate_data(data) @album_info_loaded = true break end # xml.children.each do |child| end end |
#load_track_info ⇒ Object
156 157 158 159 160 161 |
# File 'lib/scrobbler/album.rb', line 156 def load_track_info return nil if @track_info_loaded load_album_info() if !@album_info_loaded @playlist = Playlist.new_from_album(self) @tracks = @playlist.tracks end |
#remove_tag ⇒ Object
Remove a user’s tag from an album.
176 177 178 179 |
# File 'lib/scrobbler/album.rb', line 176 def remove_tag() # This function require authentication, but SimpleAuth is not yet 2.0 raise NotImplementedError end |
#tags ⇒ Object
Get the tags applied by an individual user to an album on Last.fm.
170 171 172 173 |
# File 'lib/scrobbler/album.rb', line 170 def () # This function require authentication, but SimpleAuth is not yet 2.0 raise NotImplementedError end |