xhochy-scrobbler 0.2.14

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. data/History.txt +5 -0
  2. data/MIT-LICENSE +19 -0
  3. data/Manifest +65 -0
  4. data/README.rdoc +114 -0
  5. data/Rakefile +36 -0
  6. data/examples/album.rb +17 -0
  7. data/examples/artist.rb +13 -0
  8. data/examples/scrobble.rb +31 -0
  9. data/examples/tag.rb +11 -0
  10. data/examples/track.rb +6 -0
  11. data/examples/user.rb +14 -0
  12. data/lib/scrobbler.rb +22 -0
  13. data/lib/scrobbler/album.rb +140 -0
  14. data/lib/scrobbler/artist.rb +134 -0
  15. data/lib/scrobbler/base.rb +82 -0
  16. data/lib/scrobbler/chart.rb +31 -0
  17. data/lib/scrobbler/playing.rb +49 -0
  18. data/lib/scrobbler/rest.rb +47 -0
  19. data/lib/scrobbler/scrobble.rb +66 -0
  20. data/lib/scrobbler/search.rb +60 -0
  21. data/lib/scrobbler/simpleauth.rb +59 -0
  22. data/lib/scrobbler/tag.rb +93 -0
  23. data/lib/scrobbler/track.rb +89 -0
  24. data/lib/scrobbler/user.rb +173 -0
  25. data/lib/scrobbler/version.rb +3 -0
  26. data/scrobbler.gemspec +41 -0
  27. data/setup.rb +1585 -0
  28. data/test/fixtures/xml/album/info.xml +43 -0
  29. data/test/fixtures/xml/artist/fans.xml +52 -0
  30. data/test/fixtures/xml/artist/similar.xml +1004 -0
  31. data/test/fixtures/xml/artist/topalbums.xml +61 -0
  32. data/test/fixtures/xml/artist/toptags.xml +19 -0
  33. data/test/fixtures/xml/artist/toptracks.xml +62 -0
  34. data/test/fixtures/xml/search/album.xml +241 -0
  35. data/test/fixtures/xml/search/artist.xml +215 -0
  36. data/test/fixtures/xml/search/track.xml +209 -0
  37. data/test/fixtures/xml/tag/topalbums.xml +805 -0
  38. data/test/fixtures/xml/tag/topartists.xml +605 -0
  39. data/test/fixtures/xml/tag/toptags.xml +1254 -0
  40. data/test/fixtures/xml/tag/toptracks.xml +852 -0
  41. data/test/fixtures/xml/track/fans.xml +34 -0
  42. data/test/fixtures/xml/track/toptags.xml +33 -0
  43. data/test/fixtures/xml/user/friends.xml +30 -0
  44. data/test/fixtures/xml/user/neighbours.xml +23 -0
  45. data/test/fixtures/xml/user/profile.xml +12 -0
  46. data/test/fixtures/xml/user/recentbannedtracks.xml +24 -0
  47. data/test/fixtures/xml/user/recentlovedtracks.xml +24 -0
  48. data/test/fixtures/xml/user/recenttracks.xml +47 -0
  49. data/test/fixtures/xml/user/systemrecs.xml +18 -0
  50. data/test/fixtures/xml/user/topalbums.xml +61 -0
  51. data/test/fixtures/xml/user/topartists.xml +41 -0
  52. data/test/fixtures/xml/user/toptags.xml +44 -0
  53. data/test/fixtures/xml/user/toptracks.xml +65 -0
  54. data/test/mocks/rest.rb +102 -0
  55. data/test/test_helper.rb +20 -0
  56. data/test/unit/album_test.rb +73 -0
  57. data/test/unit/artist_test.rb +106 -0
  58. data/test/unit/chart_test.rb +34 -0
  59. data/test/unit/playing_test.rb +53 -0
  60. data/test/unit/scrobble_test.rb +69 -0
  61. data/test/unit/search_test.rb +55 -0
  62. data/test/unit/simpleauth_test.rb +45 -0
  63. data/test/unit/tag_test.rb +58 -0
  64. data/test/unit/track_test.rb +37 -0
  65. data/test/unit/user_test.rb +201 -0
  66. metadata +175 -0
data/History.txt ADDED
@@ -0,0 +1,5 @@
1
+ * v 0.2.13: Nearly all API calls are now done via version 2.0 of the API
2
+ * v 0.2.10: Upgraded to using the 2.0 API for parts of the code and added in the ability to search
3
+ * v 0.2.2: a bunch of changes from titanous, mostly refactoring
4
+ * v 0.2.0: added support for scrobbling tracks and now playing submission (Titanous)
5
+ * v 0.1.0: initial release
data/MIT-LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2007-2009 John Nunemaker, Kurt Schrader, Uwe L. Korn
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/Manifest ADDED
@@ -0,0 +1,65 @@
1
+ lib/scrobbler/search.rb
2
+ lib/scrobbler/rest.rb
3
+ lib/scrobbler/track.rb
4
+ lib/scrobbler/simpleauth.rb
5
+ lib/scrobbler/base.rb
6
+ lib/scrobbler/version.rb
7
+ lib/scrobbler/chart.rb
8
+ lib/scrobbler/playing.rb
9
+ lib/scrobbler/artist.rb
10
+ lib/scrobbler/scrobble.rb
11
+ lib/scrobbler/user.rb
12
+ lib/scrobbler/album.rb
13
+ lib/scrobbler/tag.rb
14
+ lib/scrobbler.rb
15
+ scrobbler.gemspec
16
+ MIT-LICENSE
17
+ Rakefile
18
+ History.txt
19
+ setup.rb
20
+ README.rdoc
21
+ examples/track.rb
22
+ examples/artist.rb
23
+ examples/scrobble.rb
24
+ examples/user.rb
25
+ examples/album.rb
26
+ examples/tag.rb
27
+ test/unit/album_test.rb
28
+ test/unit/playing_test.rb
29
+ test/unit/scrobble_test.rb
30
+ test/unit/artist_test.rb
31
+ test/unit/chart_test.rb
32
+ test/unit/track_test.rb
33
+ test/unit/tag_test.rb
34
+ test/unit/search_test.rb
35
+ test/unit/simpleauth_test.rb
36
+ test/unit/user_test.rb
37
+ test/test_helper.rb
38
+ test/mocks/rest.rb
39
+ test/fixtures/xml/album/info.xml
40
+ test/fixtures/xml/track/toptags.xml
41
+ test/fixtures/xml/track/fans.xml
42
+ test/fixtures/xml/artist/toptags.xml
43
+ test/fixtures/xml/artist/similar.xml
44
+ test/fixtures/xml/artist/topalbums.xml
45
+ test/fixtures/xml/artist/toptracks.xml
46
+ test/fixtures/xml/artist/fans.xml
47
+ test/fixtures/xml/tag/toptags.xml
48
+ test/fixtures/xml/tag/topalbums.xml
49
+ test/fixtures/xml/tag/toptracks.xml
50
+ test/fixtures/xml/tag/topartists.xml
51
+ test/fixtures/xml/search/track.xml
52
+ test/fixtures/xml/search/artist.xml
53
+ test/fixtures/xml/search/album.xml
54
+ test/fixtures/xml/user/toptags.xml
55
+ test/fixtures/xml/user/recentbannedtracks.xml
56
+ test/fixtures/xml/user/topalbums.xml
57
+ test/fixtures/xml/user/toptracks.xml
58
+ test/fixtures/xml/user/recentlovedtracks.xml
59
+ test/fixtures/xml/user/recenttracks.xml
60
+ test/fixtures/xml/user/friends.xml
61
+ test/fixtures/xml/user/profile.xml
62
+ test/fixtures/xml/user/topartists.xml
63
+ test/fixtures/xml/user/systemrecs.xml
64
+ test/fixtures/xml/user/neighbours.xml
65
+ Manifest
data/README.rdoc ADDED
@@ -0,0 +1,114 @@
1
+ =Scrobbler
2
+
3
+ Scrobbler is a wrapper for the audioscrobbler web services (http://www.audioscrobbler.net/data/webservices/).
4
+
5
+ Currently updating to use the 2.0 API. It is very much a work in progress.
6
+
7
+ Below is just a sampling of how easy this lib is to use, full documentation of
8
+ all functions is available at http://rdoc.info/projects/xhochy/scrobbler
9
+
10
+ == Initialization
11
+
12
+ Scrobbler::Base.api_key = 'foo123'
13
+
14
+ == Users
15
+
16
+ user = Scrobbler::User.new('jnunemaker')
17
+
18
+ puts "#{user.username}'s Recent Tracks"
19
+ puts "=" * (user.username.length + 16)
20
+ user.recent_tracks.each { |t| puts t.name }
21
+
22
+ puts
23
+ puts
24
+
25
+ puts "#{user.username}'s Top Tracks"
26
+ puts "=" * (user.username.length + 13)
27
+ user.top_tracks.each { |t| puts "(#{t.playcount}) #{t.name}" }
28
+
29
+ == Albums
30
+
31
+ album = Scrobbler::Album.new('Carrie Underwood', 'Some Hearts', :include_info => true)
32
+
33
+ puts "Album: #{album.name}"
34
+ puts "Artist: #{album.artist}"
35
+ puts "Reach: #{album.reach}"
36
+ puts "URL: #{album.url}"
37
+ puts "Release Date: #{album.release_date.strftime('%m/%d/%Y')}"
38
+
39
+ puts
40
+ puts
41
+
42
+ puts "Tracks"
43
+ longest_track_name = album.tracks.collect(&:name).sort { |x, y| y.length <=> x.length }.first.length
44
+ puts "=" * longest_track_name
45
+ album.tracks.each { |t| puts t.name }
46
+
47
+ ==Artists
48
+
49
+ artist = Scrobbler::Artist.new('Carrie Underwood')
50
+
51
+ puts 'Top Tracks'
52
+ puts "=" * 10
53
+ artist.top_tracks.each { |t| puts "(#{t.reach}) #{t.name}" }
54
+
55
+ puts
56
+
57
+ puts 'Similar Artists'
58
+ puts "=" * 15
59
+ artist.similar.each { |a| puts "(#{a.match}%) #{a.name}" }
60
+
61
+ ==Tags
62
+
63
+ tag = Scrobbler::Tag.new('country')
64
+
65
+ puts 'Top Albums'
66
+ tag.top_albums.each { |a| puts "(#{a.count}) #{a.name} by #{a.artist}" }
67
+
68
+ puts
69
+
70
+ puts 'Top Tracks'
71
+ tag.top_tracks.each { |t| puts "(#{t.count}) #{t.name} by #{t.artist}" }
72
+
73
+ ==Tracks
74
+
75
+ track = Scrobbler::Track.new('Carrie Underwood', 'Before He Cheats')
76
+ puts 'Fans'
77
+ puts "=" * 4
78
+ track.fans.each { |u| puts "(#{u.weight}) #{u.username}" }
79
+
80
+ == Simple Authentication (for Scrobbling)
81
+
82
+ auth = Scrobbler::SimpleAuth.new(:user => 'chunky', :password => 'bacon')
83
+ auth.handshake!
84
+
85
+ puts "Auth Status: #{auth.status}"
86
+ puts "Session ID: #{auth.session_id}"
87
+ puts "Now Playing URL: #{auth.now_playing_url}"
88
+ puts "Submission URL: #{auth.submission_url}"
89
+
90
+ == Scrobbling
91
+
92
+ scrobble = Scrobbler::Scrobble.new(:session_id => auth.session_id,
93
+ :submission_url => auth.submission_url,
94
+ :artist => 'Coldplay',
95
+ :track => 'Viva La Vida',
96
+ :album => "Viva La Vida",
97
+ :time => Time.new,
98
+ :length => 244,
99
+ :track_number => 7)
100
+ scrobble.submit!
101
+ puts "Scrobbler Submission Status: #{scrobble.status}"
102
+
103
+ == Now Playing Submission
104
+
105
+ playing = Scrobbler::Playing.new(:session_id => auth.session_id,
106
+ :now_playing_url => auth.now_playing_url,
107
+ :artist => 'Anberlin',
108
+ :track => 'Readyfuels',
109
+ :album => 'Blueprints For the Black Market',
110
+ :length => 218,
111
+ :track_number => 1)
112
+
113
+ playing.submit!
114
+ puts "Playing Submission Status: #{playing.status}"
data/Rakefile ADDED
@@ -0,0 +1,36 @@
1
+ # Rakefile
2
+ require 'rubygems'
3
+ require 'rake'
4
+ require 'echoe'
5
+ require 'lib/scrobbler/version'
6
+
7
+ WEBSITE_PATH = 'jnunemaker@rubyforge.org:/var/www/gforge-projects/scrobbler'
8
+
9
+ Echoe.new('scrobbler', Scrobbler::Version) do |p|
10
+ p.description = "wrapper for audioscrobbler (last.fm) web services"
11
+ p.url = "http://scrobbler.rubyforge.org"
12
+ p.author = ['John Nunemaker', 'Jonathan Rudenberg', 'Uwe L. Korn']
13
+ p.email = "nunemaker@gmail.com"
14
+ p.extra_deps = [['hpricot', '>=0.4.86'], ['activesupport', '>=1.4.2'], ['htmlentities', '>=4.0.0']]
15
+ p.need_tar_gz = false
16
+ p.docs_host = WEBSITE_PATH
17
+ p.ignore_pattern = /website/
18
+ end
19
+
20
+ desc 'Upload website files to rubyforge'
21
+ task :website do
22
+ sh %{rsync -av website/ #{WEBSITE_PATH}}
23
+ Rake::Task['website_docs'].invoke
24
+ end
25
+
26
+ task :website_docs do
27
+ Rake::Task['redocs'].invoke
28
+ sh %{rsync -av doc/ #{WEBSITE_PATH}/docs}
29
+ end
30
+
31
+ desc 'Preps the gem for a new release'
32
+ task :prepare do
33
+ %w[manifest build_gemspec].each do |task|
34
+ Rake::Task[task].invoke
35
+ end
36
+ end
data/examples/album.rb ADDED
@@ -0,0 +1,17 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'scrobbler'))
2
+
3
+ album = Scrobbler::Album.new('Carrie Underwood', 'Some Hearts', :include_info => true)
4
+
5
+ puts "Album: #{album.name}"
6
+ puts "Artist: #{album.artist}"
7
+ puts "Reach: #{album.reach}"
8
+ puts "URL: #{album.url}"
9
+ puts "Release Date: #{album.release_date.strftime('%m/%d/%Y')}"
10
+
11
+ puts
12
+ puts
13
+
14
+ puts "Tracks"
15
+ longest_track_name = album.tracks.collect(&:name).sort { |x, y| y.length <=> x.length }.first.length
16
+ puts "=" * longest_track_name
17
+ album.tracks.each { |t| puts t.name }
@@ -0,0 +1,13 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'scrobbler'))
2
+
3
+ artist = Scrobbler::Artist.new('Carrie Underwood')
4
+
5
+ puts 'Top Tracks'
6
+ puts "=" * 10
7
+ artist.top_tracks.each { |t| puts "(#{t.reach}) #{t.name}" }
8
+
9
+ puts
10
+
11
+ puts 'Similar Artists'
12
+ puts "=" * 15
13
+ artist.similar.each { |a| puts "(#{a.match}%) #{a.name}" }
@@ -0,0 +1,31 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'scrobbler'))
2
+
3
+ auth = Scrobbler::SimpleAuth.new(:user => 'chunky', :password => 'bacon')
4
+ auth.handshake!
5
+
6
+ puts "Auth Status: #{auth.status}"
7
+ puts "Session ID: #{auth.session_id}"
8
+ puts "Now Playing URL: #{auth.now_playing_url}"
9
+ puts "Submission URL: #{auth.submission_url}"
10
+
11
+ scrobble = Scrobbler::Scrobble.new(:session_id => auth.session_id,
12
+ :submission_url => auth.submission_url,
13
+ :artist => 'Coldplay',
14
+ :track => 'Viva La Vida',
15
+ :album => 'Viva La Vida',
16
+ :time => Time.new,
17
+ :length => 244,
18
+ :track_number => 7)
19
+ scrobble.submit!
20
+ puts "Scrobbler Submission Status: #{scrobble.status}"
21
+
22
+ playing = Scrobbler::Playing.new(:session_id => auth.session_id,
23
+ :now_playing_url => auth.now_playing_url,
24
+ :artist => 'Anberlin',
25
+ :track => 'A Day Late',
26
+ :album => 'Never Take Friendship Personal',
27
+ :length => 214,
28
+ :track_number => 5)
29
+
30
+ playing.submit!
31
+ puts "Playing Submission Status: #{playing.status}"
data/examples/tag.rb ADDED
@@ -0,0 +1,11 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'scrobbler'))
2
+
3
+ tag = Scrobbler::Tag.new('country')
4
+
5
+ puts 'Top Albums'
6
+ tag.top_albums.each { |a| puts "(#{a.count}) #{a.name} by #{a.artist}" }
7
+
8
+ puts
9
+
10
+ puts 'Top Tracks'
11
+ tag.top_tracks.each { |t| puts "(#{t.count}) #{t.name} by #{t.artist}" }
data/examples/track.rb ADDED
@@ -0,0 +1,6 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'scrobbler'))
2
+
3
+ track = Scrobbler::Track.new('Carrie Underwood', 'Before He Cheats')
4
+ puts 'Fans'
5
+ puts "=" * 4
6
+ track.fans.each { |u| puts "(#{u.weight}) #{u.username}" }
data/examples/user.rb ADDED
@@ -0,0 +1,14 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'scrobbler'))
2
+
3
+ user = Scrobbler::User.new('jnunemaker')
4
+
5
+ puts "#{user.username}'s Recent Tracks"
6
+ puts "=" * (user.username.length + 16)
7
+ user.recent_tracks.each { |t| puts t.name }
8
+
9
+ puts
10
+ puts
11
+
12
+ puts "#{user.username}'s Top Tracks"
13
+ puts "=" * (user.username.length + 13)
14
+ user.top_tracks.each { |t| puts "(#{t.playcount}) #{t.name}" }
data/lib/scrobbler.rb ADDED
@@ -0,0 +1,22 @@
1
+ %w{cgi rubygems hpricot active_support}.each { |x| require x }
2
+
3
+ $: << File.expand_path(File.dirname(__FILE__))
4
+
5
+ require 'scrobbler/base'
6
+ require 'scrobbler/version'
7
+
8
+
9
+ require 'scrobbler/album'
10
+ require 'scrobbler/artist'
11
+ require 'scrobbler/chart'
12
+ require 'scrobbler/user'
13
+ require 'scrobbler/tag'
14
+ require 'scrobbler/track'
15
+
16
+ require 'scrobbler/simpleauth'
17
+ require 'scrobbler/scrobble'
18
+ require 'scrobbler/playing'
19
+
20
+ require 'scrobbler/rest'
21
+
22
+ require 'scrobbler/search'
@@ -0,0 +1,140 @@
1
+ # Getting information about an album such as release date and the tracks on it is very easy.
2
+ #
3
+ # album = Scrobbler::Album.new('Carrie Underwood', 'Some Hearts', :include_info => true)
4
+ #
5
+ # puts "Album: #{album.name}"
6
+ # puts "Artist: #{album.artist}"
7
+ # puts "Reach: #{album.reach}"
8
+ # puts "URL: #{album.url}"
9
+ # puts "Release Date: #{album.release_date.strftime('%m/%d/%Y')}"
10
+ #
11
+ # puts
12
+ # puts
13
+ #
14
+ # puts "Tracks"
15
+ # longest_track_name = album.tracks.collect(&:name).sort { |x, y| y.length <=> x.length }.first.length
16
+ # puts "=" * longest_track_name
17
+ # album.tracks.each { |t| puts t.name }
18
+ #
19
+ # Would output:
20
+ #
21
+ # Album: Some Hearts
22
+ # Artist: Carrie Underwood
23
+ # Reach: 18729
24
+ # URL: http://www.last.fm/music/Carrie+Underwood/Some+Hearts
25
+ # Release Date: 11/15/2005
26
+ #
27
+ #
28
+ # Tracks
29
+ # ===============================
30
+ # Wasted
31
+ # Don't Forget to Remember Me
32
+ # Some Hearts
33
+ # Jesus, Take the Wheel
34
+ # The Night Before (Life Goes On)
35
+ # Lessons Learned
36
+ # Before He Cheats
37
+ # Starts With Goodbye
38
+ # I Just Can't Live a Lie
39
+ # We're Young and Beautiful
40
+ # That's Where It Is
41
+ # Whenever You Remember
42
+ # I Ain't in Checotah Anymore
43
+ # Inside Your Heaven
44
+ #
45
+ module Scrobbler
46
+ # @todo Add missing functions that require authentication
47
+ # @todo Integrate search functionality into this class which is already implemented in Scrobbler::Search
48
+ class Album < Base
49
+ attr_accessor :artist, :artist_mbid, :name, :mbid, :playcount, :rank, :url
50
+ attr_accessor :reach, :release_date, :listeners, :playcount, :top_tags
51
+ attr_accessor :image_large, :image_medium, :image_small
52
+ attr_writer :tracks
53
+
54
+ # needed on top albums for tag
55
+ attr_accessor :count, :streamable
56
+
57
+ # needed for weekly album charts
58
+ attr_accessor :chartposition
59
+
60
+ class << self
61
+ def find(artist, name, o={})
62
+ new(artist, name, o)
63
+ end
64
+
65
+ def new_from_xml(xml, doc=nil)
66
+ name = Base::sanitize(xml.at(:name).inner_html) if xml.at(:name)
67
+ name = Base::sanitize(xml['name']) if name.nil? && xml['name']
68
+ artist = Base::sanitize(xml.at('/artist/name').inner_html) if xml.at('/artist/name')
69
+ a = Album.new(artist, name)
70
+ a.artist_mbid = xml.at(:artist).at(:mbid).inner_html if xml.at(:artist) && xml.at(:artist).at(:mbid)
71
+ a.mbid = xml.at(:mbid).inner_html if xml.at(:mbid)
72
+ a.playcount = xml.at(:playcount).inner_html if xml.at(:playcount)
73
+ a.chartposition = xml.at(:chartposition).inner_html if xml.at(:chartposition)
74
+ a.rank = xml['rank'] if xml['rank']
75
+ a.url = xml.at('/url').inner_html if xml.at('/url')
76
+ a.image_large = xml.at("/image[@size='large']").inner_html if xml.at("/image[@size='large']")
77
+ a.image_medium = xml.at("/image[@size='medium']").inner_html if xml.at("/image[@size='medium']")
78
+ a.image_small = xml.at("/image[@size='small']").inner_html if xml.at("/image[@size='small']")
79
+
80
+ # needed on top albums for tag
81
+ a.count = xml['count'] if xml['count']
82
+ a.streamable = xml['streamable'] if xml['streamable']
83
+ a
84
+ end
85
+ end
86
+
87
+ # If the additional parameter :include_info is set to true, additional
88
+ # information is loaded
89
+ #
90
+ # @todo Albums should be able to be created via a MusicBrainz id too
91
+ def initialize(artist, name, o={})
92
+ raise ArgumentError, "Artist is required" if artist.blank?
93
+ raise ArgumentError, "Name is required" if name.blank?
94
+ @artist = artist
95
+ @name = name
96
+ options = {:include_info => false}.merge(o)
97
+ load_info() if options[:include_info]
98
+ end
99
+
100
+ @info_loaded = false # Indicates if the info was already loaded
101
+
102
+ # Load additional information about this album
103
+ #
104
+ # Calls "album.getinfo" REST method
105
+ #
106
+ # @todo Parse wiki content
107
+ # @todo Add language code for wiki translation
108
+ def load_info
109
+ xml = request('album.getinfo', {'artist' => @artist, 'name' => @name})
110
+ unless xml.at(:lfm)['status'] == 'failed' || @info_loaded
111
+ xml = xml.at(:album)
112
+ @url = xml.at(:url).inner_html
113
+ @release_date = Time.parse(xml.at(:releasedate).inner_html.strip)
114
+ @image_extralarge = xml.at("/image[@size='extralarge']").inner_html
115
+ @image_large = xml.at("/image[@size='large']").inner_html
116
+ @image_medium = xml.at("/image[@size='medium']").inner_html
117
+ @image_small = xml.at("/image[@size='small']").inner_html
118
+ @mbid = xml.at(:mbid).inner_html
119
+ @listeners = xml.at(:listeners).inner_html.to_i
120
+ @playcount = xml.at(:playcount).inner_html.to_i
121
+ @info_loaded = true
122
+ @top_tags = []
123
+ xml.at(:toptags).search(:tag).each do |elem|
124
+ @top_tags << Tag.new_from_xml(elem)
125
+ end
126
+ end
127
+ end
128
+
129
+ def image(which=:small)
130
+ which = which.to_s
131
+ raise ArgumentError unless ['small', 'medium', 'large', 'extralarge'].include?(which)
132
+ img_url = instance_variable_get("@image_#{which}")
133
+ if img_url.nil?
134
+ load_info
135
+ img_url = instance_variable_get("@image_#{which}")
136
+ end
137
+ img_url
138
+ end
139
+ end
140
+ end