Class: Scrobbler::Album
Overview
Add missing functions that require authentication
Integrate search functionality into this class which is already implemented in Scrobbler::Search
Instance Attribute Summary collapse
-
#artist ⇒ Object
Returns the value of attribute artist.
-
#artist_mbid ⇒ Object
Returns the value of attribute artist_mbid.
-
#chartposition ⇒ Object
needed for weekly album charts.
-
#count ⇒ Object
needed on top albums for tag.
-
#image_large ⇒ Object
Returns the value of attribute image_large.
-
#image_medium ⇒ Object
Returns the value of attribute image_medium.
-
#image_small ⇒ Object
Returns the value of attribute image_small.
-
#listeners ⇒ Object
Returns the value of attribute listeners.
-
#mbid ⇒ Object
Returns the value of attribute mbid.
-
#name ⇒ Object
Returns the value of attribute name.
-
#playcount ⇒ Object
Returns the value of attribute playcount.
-
#rank ⇒ Object
Returns the value of attribute rank.
-
#reach ⇒ Object
Returns the value of attribute reach.
-
#release_date ⇒ Object
Returns the value of attribute release_date.
-
#streamable ⇒ Object
needed on top albums for tag.
-
#top_tags ⇒ Object
Returns the value of attribute top_tags.
-
#tracks ⇒ Object
writeonly
Sets the attribute tracks.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
- #image(which = :small) ⇒ Object
-
#initialize(artist, name, o = {}) ⇒ Album
constructor
If the additional parameter :include_info is set to true, additional information is loaded.
-
#load_info ⇒ Object
Load additional information about this album.
Methods inherited from Base
api_key=, connection, fetch_and_parse, sanitize
Constructor Details
#initialize(artist, name, o = {}) ⇒ 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
91 92 93 94 95 96 97 98 |
# File 'lib/scrobbler/album.rb', line 91 def initialize(artist, name, o={}) raise ArgumentError, "Artist is required" if artist.blank? raise ArgumentError, "Name is required" if name.blank? @artist = artist @name = name = {:include_info => false}.merge(o) load_info() if [:include_info] end |
Instance Attribute Details
#artist ⇒ Object
Returns the value of attribute artist.
49 50 51 |
# File 'lib/scrobbler/album.rb', line 49 def artist @artist end |
#artist_mbid ⇒ Object
Returns the value of attribute artist_mbid.
49 50 51 |
# File 'lib/scrobbler/album.rb', line 49 def artist_mbid @artist_mbid end |
#chartposition ⇒ Object
needed for weekly album charts
58 59 60 |
# File 'lib/scrobbler/album.rb', line 58 def chartposition @chartposition end |
#count ⇒ Object
needed on top albums for tag
55 56 57 |
# File 'lib/scrobbler/album.rb', line 55 def count @count end |
#image_large ⇒ Object
Returns the value of attribute image_large.
51 52 53 |
# File 'lib/scrobbler/album.rb', line 51 def image_large @image_large end |
#image_medium ⇒ Object
Returns the value of attribute image_medium.
51 52 53 |
# File 'lib/scrobbler/album.rb', line 51 def image_medium @image_medium end |
#image_small ⇒ Object
Returns the value of attribute image_small.
51 52 53 |
# File 'lib/scrobbler/album.rb', line 51 def image_small @image_small end |
#listeners ⇒ Object
Returns the value of attribute listeners.
50 51 52 |
# File 'lib/scrobbler/album.rb', line 50 def listeners @listeners end |
#mbid ⇒ Object
Returns the value of attribute mbid.
49 50 51 |
# File 'lib/scrobbler/album.rb', line 49 def mbid @mbid end |
#name ⇒ Object
Returns the value of attribute name.
49 50 51 |
# File 'lib/scrobbler/album.rb', line 49 def name @name end |
#playcount ⇒ Object
Returns the value of attribute playcount.
49 50 51 |
# File 'lib/scrobbler/album.rb', line 49 def playcount @playcount end |
#rank ⇒ Object
Returns the value of attribute rank.
49 50 51 |
# File 'lib/scrobbler/album.rb', line 49 def rank @rank end |
#reach ⇒ Object
Returns the value of attribute reach.
50 51 52 |
# File 'lib/scrobbler/album.rb', line 50 def reach @reach end |
#release_date ⇒ Object
Returns the value of attribute release_date.
50 51 52 |
# File 'lib/scrobbler/album.rb', line 50 def release_date @release_date end |
#streamable ⇒ Object
needed on top albums for tag
55 56 57 |
# File 'lib/scrobbler/album.rb', line 55 def streamable @streamable end |
#top_tags ⇒ Object
Returns the value of attribute top_tags.
50 51 52 |
# File 'lib/scrobbler/album.rb', line 50 def @top_tags end |
#tracks=(value) ⇒ Object (writeonly)
Sets the attribute tracks
52 53 54 |
# File 'lib/scrobbler/album.rb', line 52 def tracks=(value) @tracks = value end |
#url ⇒ Object
Returns the value of attribute url.
49 50 51 |
# File 'lib/scrobbler/album.rb', line 49 def url @url end |
Class Method Details
.find(artist, name, o = {}) ⇒ Object
61 62 63 |
# File 'lib/scrobbler/album.rb', line 61 def find(artist, name, o={}) new(artist, name, o) end |
.new_from_xml(xml, doc = nil) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/scrobbler/album.rb', line 65 def new_from_xml(xml, doc=nil) name = Base::sanitize(xml.at(:name).inner_html) if xml.at(:name) name = Base::sanitize(xml['name']) if name.nil? && xml['name'] artist = Base::sanitize(xml.at('/artist/name').inner_html) if xml.at('/artist/name') a = Album.new(artist, name) a.artist_mbid = xml.at(:artist).at(:mbid).inner_html if xml.at(:artist) && xml.at(:artist).at(:mbid) a.mbid = xml.at(:mbid).inner_html if xml.at(:mbid) a.playcount = xml.at(:playcount).inner_html if xml.at(:playcount) a.chartposition = xml.at(:chartposition).inner_html if xml.at(:chartposition) a.rank = xml['rank'] if xml['rank'] a.url = xml.at('/url').inner_html if xml.at('/url') a.image_large = xml.at("/image[@size='large']").inner_html if xml.at("/image[@size='large']") a.image_medium = xml.at("/image[@size='medium']").inner_html if xml.at("/image[@size='medium']") a.image_small = xml.at("/image[@size='small']").inner_html if xml.at("/image[@size='small']") # needed on top albums for tag a.count = xml['count'] if xml['count'] a.streamable = xml['streamable'] if xml['streamable'] a end |
Instance Method Details
#image(which = :small) ⇒ Object
129 130 131 132 133 134 135 136 137 138 |
# File 'lib/scrobbler/album.rb', line 129 def image(which=:small) which = which.to_s raise ArgumentError unless ['small', 'medium', 'large', 'extralarge'].include?(which) img_url = instance_variable_get("@image_#{which}") if img_url.nil? load_info img_url = instance_variable_get("@image_#{which}") end img_url end |
#load_info ⇒ Object
Parse wiki content
Add language code for wiki translation
Load additional information about this album
Calls “album.getinfo” REST method
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/scrobbler/album.rb', line 108 def load_info xml = request('album.getinfo', {'artist' => @artist, 'name' => @name}) unless xml.at(:lfm)['status'] == 'failed' || @info_loaded xml = xml.at(:album) @url = xml.at(:url).inner_html @release_date = Time.parse(xml.at(:releasedate).inner_html.strip) @image_extralarge = xml.at("/image[@size='extralarge']").inner_html @image_large = xml.at("/image[@size='large']").inner_html @image_medium = xml.at("/image[@size='medium']").inner_html @image_small = xml.at("/image[@size='small']").inner_html @mbid = xml.at(:mbid).inner_html @listeners = xml.at(:listeners).inner_html.to_i @playcount = xml.at(:playcount).inner_html.to_i @info_loaded = true @top_tags = [] xml.at(:toptags).search(:tag).each do |elem| @top_tags << Tag.new_from_xml(elem) end end end |