scrobbler-ng 2.0.1 → 2.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION.yml +2 -2
- data/lib/scrobbler.rb +4 -2
- data/lib/scrobbler/album.rb +2 -8
- data/lib/scrobbler/artist.rb +5 -7
- data/lib/scrobbler/base.rb +9 -34
- data/lib/scrobbler/basexml.rb +1 -0
- data/lib/scrobbler/basexmlinfo.rb +18 -0
- data/lib/scrobbler/event.rb +3 -7
- data/lib/scrobbler/helper/image.rb +1 -2
- data/lib/scrobbler/playlist.rb +2 -7
- data/lib/scrobbler/shout.rb +0 -2
- data/lib/scrobbler/tag.rb +55 -93
- data/lib/scrobbler/user.rb +12 -16
- data/lib/scrobbler/venue.rb +6 -6
- data/tasks/jeweler.rake +5 -6
- data/tasks/tests.rake +8 -6
- data/test/mocks/rest.rb +1 -1
- data/test/unit/tag_spec.rb +1 -1
- data/test/unit/venue_spec.rb +3 -2
- metadata +56 -134
- data/lib/scrobbler/scrobble.rb +0 -116
- data/test/fixtures/xml/album/info.xml +0 -43
- data/test/fixtures/xml/artist/fans.xml +0 -52
- data/test/fixtures/xml/artist/info.xml +0 -58
- data/test/fixtures/xml/artist/similar.xml +0 -1004
- data/test/fixtures/xml/artist/topalbums.xml +0 -61
- data/test/fixtures/xml/artist/toptags.xml +0 -19
- data/test/fixtures/xml/artist/toptracks.xml +0 -62
- data/test/fixtures/xml/auth/session.xml +0 -7
- data/test/fixtures/xml/auth/token.xml +0 -3
- data/test/fixtures/xml/event/attend.xml +0 -3
- data/test/fixtures/xml/event/attendees.xml +0 -53
- data/test/fixtures/xml/event/event.xml +0 -35
- data/test/fixtures/xml/event/shouts.xml +0 -35
- data/test/fixtures/xml/geo/events-distance-p1.xml +0 -151
- data/test/fixtures/xml/geo/events-lat-long.xml +0 -167
- data/test/fixtures/xml/geo/events-p1.xml +0 -152
- data/test/fixtures/xml/geo/events-p2.xml +0 -380
- data/test/fixtures/xml/geo/events-p3.xml +0 -427
- data/test/fixtures/xml/geo/top_artists-p1.xml +0 -76
- data/test/fixtures/xml/geo/top_tracks-p1.xml +0 -77
- data/test/fixtures/xml/library/albums-f30.xml +0 -454
- data/test/fixtures/xml/library/albums-p1.xml +0 -754
- data/test/fixtures/xml/library/albums-p2.xml +0 -754
- data/test/fixtures/xml/library/albums-p3.xml +0 -754
- data/test/fixtures/xml/library/albums-p4.xml +0 -739
- data/test/fixtures/xml/library/albums-p5.xml +0 -754
- data/test/fixtures/xml/library/albums-p6.xml +0 -754
- data/test/fixtures/xml/library/albums-p7.xml +0 -739
- data/test/fixtures/xml/library/albums-p8.xml +0 -724
- data/test/fixtures/xml/library/artists-f30.xml +0 -334
- data/test/fixtures/xml/library/artists-p1.xml +0 -554
- data/test/fixtures/xml/library/artists-p2.xml +0 -554
- data/test/fixtures/xml/library/artists-p3.xml +0 -554
- data/test/fixtures/xml/library/artists-p4.xml +0 -554
- data/test/fixtures/xml/library/artists-p5.xml +0 -554
- data/test/fixtures/xml/library/artists-p6.xml +0 -554
- data/test/fixtures/xml/library/artists-p7.xml +0 -444
- data/test/fixtures/xml/library/tracks-f30.xml +0 -472
- data/test/fixtures/xml/library/tracks-p1.xml +0 -789
- data/test/fixtures/xml/library/tracks-p10.xml +0 -771
- data/test/fixtures/xml/library/tracks-p11.xml +0 -792
- data/test/fixtures/xml/library/tracks-p12.xml +0 -777
- data/test/fixtures/xml/library/tracks-p13.xml +0 -762
- data/test/fixtures/xml/library/tracks-p14.xml +0 -759
- data/test/fixtures/xml/library/tracks-p15.xml +0 -762
- data/test/fixtures/xml/library/tracks-p16.xml +0 -756
- data/test/fixtures/xml/library/tracks-p17.xml +0 -780
- data/test/fixtures/xml/library/tracks-p18.xml +0 -756
- data/test/fixtures/xml/library/tracks-p19.xml +0 -774
- data/test/fixtures/xml/library/tracks-p2.xml +0 -765
- data/test/fixtures/xml/library/tracks-p20.xml +0 -777
- data/test/fixtures/xml/library/tracks-p21.xml +0 -777
- data/test/fixtures/xml/library/tracks-p22.xml +0 -771
- data/test/fixtures/xml/library/tracks-p23.xml +0 -765
- data/test/fixtures/xml/library/tracks-p24.xml +0 -783
- data/test/fixtures/xml/library/tracks-p25.xml +0 -777
- data/test/fixtures/xml/library/tracks-p26.xml +0 -777
- data/test/fixtures/xml/library/tracks-p27.xml +0 -756
- data/test/fixtures/xml/library/tracks-p28.xml +0 -771
- data/test/fixtures/xml/library/tracks-p29.xml +0 -753
- data/test/fixtures/xml/library/tracks-p3.xml +0 -771
- data/test/fixtures/xml/library/tracks-p30.xml +0 -780
- data/test/fixtures/xml/library/tracks-p31.xml +0 -753
- data/test/fixtures/xml/library/tracks-p32.xml +0 -771
- data/test/fixtures/xml/library/tracks-p33.xml +0 -762
- data/test/fixtures/xml/library/tracks-p34.xml +0 -538
- data/test/fixtures/xml/library/tracks-p4.xml +0 -792
- data/test/fixtures/xml/library/tracks-p5.xml +0 -780
- data/test/fixtures/xml/library/tracks-p6.xml +0 -789
- data/test/fixtures/xml/library/tracks-p7.xml +0 -789
- data/test/fixtures/xml/library/tracks-p8.xml +0 -780
- data/test/fixtures/xml/library/tracks-p9.xml +0 -774
- data/test/fixtures/xml/tag/similar.xml +0 -254
- data/test/fixtures/xml/tag/topalbums.xml +0 -805
- data/test/fixtures/xml/tag/topartists.xml +0 -605
- data/test/fixtures/xml/tag/toptags.xml +0 -1254
- data/test/fixtures/xml/tag/toptracks.xml +0 -852
- data/test/fixtures/xml/track/fans.xml +0 -34
- data/test/fixtures/xml/track/info.xml +0 -53
- data/test/fixtures/xml/track/toptags.xml +0 -504
- data/test/fixtures/xml/user/events.xml +0 -401
- data/test/fixtures/xml/user/friends.xml +0 -30
- data/test/fixtures/xml/user/lovedtracks.xml +0 -678
- data/test/fixtures/xml/user/neighbours.xml +0 -23
- data/test/fixtures/xml/user/playlists.xml +0 -61
- data/test/fixtures/xml/user/profile.xml +0 -12
- data/test/fixtures/xml/user/recentbannedtracks.xml +0 -24
- data/test/fixtures/xml/user/recentlovedtracks.xml +0 -24
- data/test/fixtures/xml/user/recenttracks.xml +0 -124
- data/test/fixtures/xml/user/systemrecs.xml +0 -18
- data/test/fixtures/xml/user/topalbums.xml +0 -61
- data/test/fixtures/xml/user/topartists.xml +0 -41
- data/test/fixtures/xml/user/toptags.xml +0 -44
- data/test/fixtures/xml/user/toptracks.xml +0 -65
- data/test/fixtures/xml/user/weeklyalbumchart.xml +0 -256
- data/test/fixtures/xml/user/weeklyartistchart.xml +0 -220
- data/test/fixtures/xml/user/weeklytrackchart.xml +0 -746
- data/test/fixtures/xml/venue/events.xml +0 -151
- data/test/fixtures/xml/venue/venue.xml +0 -16
- data/test/unit/scrobble_spec.rb +0 -55
- data/test/unit/scrobble_test.rb +0 -69
data/VERSION.yml
CHANGED
data/lib/scrobbler.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
|
2
|
-
|
3
|
+
require 'rubygems'
|
4
|
+
require 'uri'
|
5
|
+
require 'time'
|
3
6
|
|
4
7
|
$: << File.expand_path(File.dirname(__FILE__))
|
5
8
|
|
@@ -27,7 +30,6 @@ require 'scrobbler/playlist'
|
|
27
30
|
require 'scrobbler/radio'
|
28
31
|
|
29
32
|
require 'scrobbler/simpleauth'
|
30
|
-
require 'scrobbler/scrobble'
|
31
33
|
require 'scrobbler/playing'
|
32
34
|
|
33
35
|
require 'scrobbler/rest'
|
data/lib/scrobbler/album.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
require File.expand_path('
|
3
|
+
require File.expand_path('basexmlinfo.rb', File.dirname(__FILE__))
|
4
4
|
|
5
5
|
module Scrobbler
|
6
6
|
# @todo Add missing functions that require authentication
|
7
|
-
class Album <
|
7
|
+
class Album < BaseXmlInfo
|
8
8
|
include Scrobbler::ImageObjectFuncs
|
9
9
|
|
10
10
|
attr_reader :artist, :artist_mbid, :name, :mbid, :playcount, :rank, :url
|
@@ -28,16 +28,10 @@ module Scrobbler
|
|
28
28
|
# If the additional parameter :include_info is set to true, additional
|
29
29
|
# information is loaded
|
30
30
|
#
|
31
|
-
# @todo Albums should be able to be created via a MusicBrainz id too
|
32
|
-
#
|
33
31
|
# @param [Hash] data The options to initialize the class
|
34
32
|
def initialize(data={})
|
35
33
|
raise ArgumentError unless data.kind_of?(Hash)
|
36
34
|
super(data)
|
37
|
-
data = {:include_info => false}.merge(data)
|
38
|
-
# Load data given as method-parameter
|
39
|
-
load_info() if data.delete(:include_info)
|
40
|
-
populate_data(data)
|
41
35
|
|
42
36
|
raise ArgumentError, "Artist or mbid is required" if @artist.nil? && @mbid.nil?
|
43
37
|
raise ArgumentError, "Name is required" if @name.empty?
|
data/lib/scrobbler/artist.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
require File.expand_path('
|
3
|
+
require File.expand_path('basexmlinfo.rb', File.dirname(__FILE__))
|
4
4
|
|
5
5
|
module Scrobbler
|
6
6
|
# @todo Add missing functions that require authentication
|
7
7
|
# @todo Integrate search functionality into this class which is already implemented in Scrobbler::Search
|
8
|
-
class Artist <
|
8
|
+
class Artist < BaseXmlInfo
|
9
9
|
include Scrobbler::ImageObjectFuncs
|
10
10
|
include Scrobbler::StreamableObjectFuncs
|
11
11
|
|
@@ -25,14 +25,12 @@ module Scrobbler
|
|
25
25
|
def initialize(data = {})
|
26
26
|
raise ArgumentError unless data.kind_of?(Hash)
|
27
27
|
super(data)
|
28
|
-
# Load data given as method-parameter
|
29
|
-
populate_data(data)
|
30
28
|
raise ArgumentError, "Name is required" if @name.nil? || @name.strip.empty?
|
31
29
|
end
|
32
30
|
|
33
31
|
# Load the data for this object out of a XML-Node
|
34
32
|
#
|
35
|
-
# @param [
|
33
|
+
# @param [XML::Node] node The XML node containing the information
|
36
34
|
# @return [nil]
|
37
35
|
def load_from_xml(node)
|
38
36
|
# Get all information from the root's children nodes
|
@@ -51,7 +49,7 @@ module Scrobbler
|
|
51
49
|
when 'chartposition'
|
52
50
|
@chartposition = child.content
|
53
51
|
when 'name'
|
54
|
-
@name = child.content
|
52
|
+
@name = child.content
|
55
53
|
when 'image'
|
56
54
|
check_image_node(child)
|
57
55
|
when 'streamable'
|
@@ -77,7 +75,7 @@ module Scrobbler
|
|
77
75
|
end #^ do |child|
|
78
76
|
|
79
77
|
# Get all information from the root's attributes
|
80
|
-
@name = node['name']
|
78
|
+
@name = node['name'] unless node['name'].nil?
|
81
79
|
@rank = node['rank'].to_i unless node['rank'].nil?
|
82
80
|
maybe_streamable_attribute(node)
|
83
81
|
@mbid = node['mbid'] unless node['mbid'].nil?
|
data/lib/scrobbler/base.rb
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
require 'digest/md5'
|
2
|
+
require 'nokogiri'
|
2
3
|
|
3
4
|
$KCODE = 'u'
|
4
5
|
|
5
|
-
include LibXML
|
6
|
-
|
7
6
|
module Scrobbler
|
8
7
|
|
9
8
|
API_URL = 'http://ws.audioscrobbler.com/'
|
@@ -44,24 +43,6 @@ module Scrobbler
|
|
44
43
|
URI.escape(param.to_s, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
|
45
44
|
end
|
46
45
|
|
47
|
-
# Camelize and Constanize a string.
|
48
|
-
#
|
49
|
-
# @param [String,Symbol] word The word which should be camelized and
|
50
|
-
# constanized.
|
51
|
-
# @return [Constant]
|
52
|
-
def Base.constanize(word)
|
53
|
-
names = word.to_s.gsub(/\/(.?)/) do
|
54
|
-
"::#{$1.upcase}"
|
55
|
-
end.gsub(/(?:^|_)(.)/) { $1.upcase }.split('::')
|
56
|
-
names.shift if names.empty? || names.first.empty?
|
57
|
-
|
58
|
-
constant = Object
|
59
|
-
names.each do |name|
|
60
|
-
constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
|
61
|
-
end
|
62
|
-
constant
|
63
|
-
end
|
64
|
-
|
65
46
|
# Initiate a API and parse it.
|
66
47
|
#
|
67
48
|
# @param [String,Symbol] api_method The API method to call.
|
@@ -70,13 +51,8 @@ module Scrobbler
|
|
70
51
|
# @param [Hash<String,Symbol>] parameters The parameters for the method call.
|
71
52
|
# @return [Array<Scrobbler::Base>]
|
72
53
|
def Base.get(api_method, parent, element, parameters = {})
|
73
|
-
|
74
|
-
|
75
|
-
element = element.to_s.sub("Scrobbler::","").downcase
|
76
|
-
else
|
77
|
-
element = element.to_s
|
78
|
-
scrobbler_class = constanize("scrobbler/#{element}")
|
79
|
-
end
|
54
|
+
scrobbler_class = element
|
55
|
+
element = element.to_s.sub("Scrobbler::","").downcase
|
80
56
|
doc = request(api_method, parameters)
|
81
57
|
elements = []
|
82
58
|
doc.root.children.each do |child|
|
@@ -131,15 +107,14 @@ module Scrobbler
|
|
131
107
|
paramlist << "#{sanitize(key)}=#{sanitize(value)}"
|
132
108
|
end
|
133
109
|
end
|
134
|
-
url =
|
135
|
-
|
110
|
+
url = "/2.0/?#{paramlist.join('&')}"
|
111
|
+
xml = self.connection.send(request_method, url)
|
112
|
+
doc = Nokogiri::XML(xml) do |config|
|
113
|
+
config.noent.noblanks.nonet
|
114
|
+
end
|
115
|
+
doc
|
136
116
|
end
|
137
117
|
|
138
|
-
# @deprecated
|
139
|
-
def get_response(api_method, instance_name, parent, element, params, force=true)
|
140
|
-
Base.get(api_method, parent, element, params)
|
141
|
-
end
|
142
|
-
|
143
118
|
# Load information into instance variables.
|
144
119
|
#
|
145
120
|
# @param [Hash<String,Symbol>] data Each entry will be stored as a variable.
|
data/lib/scrobbler/basexml.rb
CHANGED
@@ -0,0 +1,18 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.expand_path('basexml.rb', File.dirname(__FILE__))
|
4
|
+
|
5
|
+
module Scrobbler
|
6
|
+
class BaseXmlInfo < BaseXml
|
7
|
+
# Load data out of a XML node, fetch addtional info if requested
|
8
|
+
#
|
9
|
+
# @param [Hash] data
|
10
|
+
def initialize(data = {})
|
11
|
+
raise ArgumentError unless data.kind_of?(Hash)
|
12
|
+
data = {:include_info => false}.merge(data)
|
13
|
+
fetch_info = data.delete(:include_info)
|
14
|
+
super(data)
|
15
|
+
load_info() if fetch_info
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/scrobbler/event.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
require File.expand_path('
|
3
|
+
require File.expand_path('basexmlinfo.rb', File.dirname(__FILE__))
|
4
4
|
|
5
5
|
module Scrobbler
|
6
|
-
class Event <
|
6
|
+
class Event < BaseXmlInfo
|
7
7
|
# Load Helper modules
|
8
8
|
include ImageObjectFuncs
|
9
9
|
|
@@ -24,11 +24,7 @@ module Scrobbler
|
|
24
24
|
def initialize(data = {})
|
25
25
|
raise ArgumentError unless data.kind_of?(Hash)
|
26
26
|
super(data)
|
27
|
-
|
28
|
-
# Load data given as method-parameter
|
29
|
-
load_info() if data.delete(:include_info)
|
30
|
-
populate_data(data)
|
31
|
-
|
27
|
+
|
32
28
|
raise ArgumentError, "ID is required" if @id.nil?
|
33
29
|
end
|
34
30
|
|
@@ -9,10 +9,9 @@ module Scrobbler
|
|
9
9
|
# of, read it into that given hash of data
|
10
10
|
#
|
11
11
|
# @param [Hash<Symbol, String>] data The data extracted from an API response
|
12
|
-
# @param [LibXML::XML::Node] node XML node, part of the API response
|
12
|
+
# @param [(LibXML::)XML::Node] node XML node, part of the API response
|
13
13
|
def maybe_image_node(data, node)
|
14
14
|
raise ArgumentError unless data.kind_of?(Hash)
|
15
|
-
raise ArgumentError unless node.kind_of?(LibXML::XML::Node)
|
16
15
|
if node.name == 'image'
|
17
16
|
case node['size'].to_s # convert to string to fix libxml-ruby bug
|
18
17
|
when 'small'
|
data/lib/scrobbler/playlist.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
require File.expand_path('
|
3
|
+
require File.expand_path('basexmlinfo.rb', File.dirname(__FILE__))
|
4
4
|
|
5
5
|
module Scrobbler
|
6
|
-
class Playlist <
|
6
|
+
class Playlist < BaseXmlInfo
|
7
7
|
# Load Helper modules
|
8
8
|
include ImageObjectFuncs
|
9
9
|
include Scrobbler::StreamableObjectFuncs
|
@@ -26,11 +26,6 @@ module Scrobbler
|
|
26
26
|
def initialize(data={})
|
27
27
|
raise ArgumentError unless data.kind_of?(Hash)
|
28
28
|
super(data)
|
29
|
-
data = {:include_info => false}.merge(data)
|
30
|
-
# Load data given as method-parameter
|
31
|
-
load_info() if data.delete(:include_info)
|
32
|
-
populate_data(data)
|
33
|
-
|
34
29
|
raise ArgumentError, "Url is required" if @url.empty?
|
35
30
|
end
|
36
31
|
|
data/lib/scrobbler/shout.rb
CHANGED
data/lib/scrobbler/tag.rb
CHANGED
@@ -1,106 +1,69 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
|
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}" }
|
12
|
-
#
|
13
|
-
# Which would output something similar to:
|
14
|
-
#
|
15
|
-
# Top Albums
|
16
|
-
# (29) American IV: The Man Comes Around by Johnny Cash
|
17
|
-
# (14) Folks Pop In at the Waterhouse by Various Artists
|
18
|
-
# (13) Hapless by Flowers From The Man Who Shot Your Cousin
|
19
|
-
# (9) Taking The Long Way by Dixie Chicks
|
20
|
-
# (8) Unchained by Johnny Cash
|
21
|
-
# (8) American III: Solitary Man by Johnny Cash
|
22
|
-
# (8) Wide Open Spaces by Dixie Chicks
|
23
|
-
# (7) It's Now or Later by Tangled Star
|
24
|
-
# (7) Greatest Hits by Hank Williams
|
25
|
-
# (7) American Recordings by Johnny Cash
|
26
|
-
# (6) Forgotten Landscape by theNoLifeKing
|
27
|
-
# (6) At Folsom Prison by Johnny Cash
|
28
|
-
# (6) Fox Confessor Brings the Flood by Neko Case
|
29
|
-
# (6) Murder by Johnny Cash
|
30
|
-
# (5) Gloom by theNoLifeKing
|
31
|
-
# (5) Set This Circus Down by Tim McGraw
|
32
|
-
# (5) Blacklisted by Neko Case
|
33
|
-
# (5) Breathe by Faith Hill
|
34
|
-
# (5) Unearthed (disc 4: My Mother's Hymn Book) by Johnny Cash
|
35
|
-
# (4) Home by Dixie Chicks
|
36
|
-
#
|
37
|
-
# Top Tracks
|
38
|
-
# (221) Hurt by Johnny Cash
|
39
|
-
# (152) I Walk the Line by Johnny Cash
|
40
|
-
# (147) Ring of Fire by Johnny Cash
|
41
|
-
# (125) Folsom Prison Blues by Johnny Cash
|
42
|
-
# (77) The Man Comes Around by Johnny Cash
|
43
|
-
# (67) Personal Jesus by Johnny Cash
|
44
|
-
# (65) Not Ready To Make Nice by Dixie Chicks
|
45
|
-
# (63) Before He Cheats by Carrie Underwood
|
46
|
-
# (62) Give My Love to Rose by Johnny Cash
|
47
|
-
# (49) Jackson by Johnny Cash
|
48
|
-
# (49) What Hurts The Most by Rascal Flatts
|
49
|
-
# (48) Big River by Johnny Cash
|
50
|
-
# (46) Man in Black by Johnny Cash
|
51
|
-
# (46) Jolene by Dolly Parton
|
52
|
-
# (46) Friends in Low Places by Garth Brooks
|
53
|
-
# (46) One by Johnny Cash
|
54
|
-
# (44) Cocaine Blues by Johnny Cash
|
55
|
-
# (41) Get Rhythm by Johnny Cash
|
56
|
-
# (41) I Still Miss Someone by Johnny Cash
|
57
|
-
# (40) The Devil Went Down to Georgia by Charlie Daniels Band
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.expand_path('basexml.rb', File.dirname(__FILE__))
|
4
|
+
|
58
5
|
module Scrobbler
|
59
|
-
class Tag <
|
60
|
-
|
6
|
+
class Tag < BaseXml
|
7
|
+
include Scrobbler::StreamableObjectFuncs
|
8
|
+
|
9
|
+
attr_reader :name, :count, :url, :streamable
|
61
10
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
data[:count] = child.content.to_i if child.name == 'count'
|
68
|
-
data[:url] = child.content if child.name == 'url'
|
69
|
-
if child.name == 'streamable'
|
70
|
-
if ['1', 'true'].include?(child.content)
|
71
|
-
data[:streamable] = true
|
72
|
-
else
|
73
|
-
data[:streamable] = false
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
Tag.new(data[:name], data)
|
79
|
-
end
|
11
|
+
# Alias for Artist.new(:xml => xml)
|
12
|
+
#
|
13
|
+
# @deprecated
|
14
|
+
def self.new_from_libxml(xml)
|
15
|
+
Tag.new(:xml => xml)
|
80
16
|
end
|
81
17
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
18
|
+
# Create a new Scrobbler::Artist instance
|
19
|
+
#
|
20
|
+
# @param [Hash] data The options to initialize the class
|
21
|
+
def initialize(data = {})
|
22
|
+
raise ArgumentError unless data.kind_of?(Hash)
|
23
|
+
super(data)
|
24
|
+
raise ArgumentError, "Name is required" if @name.nil? || @name.strip.empty?
|
88
25
|
end
|
89
26
|
|
90
|
-
|
91
|
-
|
27
|
+
# Load the data for this object out of a XML-Node
|
28
|
+
#
|
29
|
+
# @param [XML::Node] node The XML node containing the information
|
30
|
+
# @return [nil]
|
31
|
+
def load_from_xml(node)
|
32
|
+
# Get all information from the root's children nodes
|
33
|
+
node.children.each do |child|
|
34
|
+
case child.name
|
35
|
+
when 'count'
|
36
|
+
@count = child.content.to_i
|
37
|
+
when 'url'
|
38
|
+
@url = child.content
|
39
|
+
when 'name'
|
40
|
+
@name = child.content
|
41
|
+
when 'streamable'
|
42
|
+
check_streamable_node(child)
|
43
|
+
when 'text'
|
44
|
+
# ignore, these are only blanks
|
45
|
+
when '#text'
|
46
|
+
# libxml-jruby version of blanks
|
47
|
+
else
|
48
|
+
raise NotImplementedError, "Field '#{child.name}' not known (#{child.content})"
|
49
|
+
end #^ case
|
50
|
+
end #^ do |child|
|
51
|
+
end #^ load_from_xml
|
52
|
+
|
53
|
+
def top_artists
|
54
|
+
call('tag.gettopartists', :topartists, Artist, {:tag => @name})
|
92
55
|
end
|
93
56
|
|
94
|
-
def top_albums
|
95
|
-
|
57
|
+
def top_albums
|
58
|
+
call('tag.gettopalbums', :topalbums, Album, {:tag => @name})
|
96
59
|
end
|
97
60
|
|
98
|
-
def top_tracks
|
99
|
-
|
61
|
+
def top_tracks
|
62
|
+
call('tag.gettoptracks', :toptracks, Track, {:tag => @name})
|
100
63
|
end
|
101
64
|
|
102
65
|
def self.top_tags
|
103
|
-
Base.get('tag.gettoptags', :toptags,
|
66
|
+
Base.get('tag.gettoptags', :toptags, Tag)
|
104
67
|
end
|
105
68
|
|
106
69
|
def self.search
|
@@ -111,9 +74,8 @@ module Scrobbler
|
|
111
74
|
|
112
75
|
# Search for tags similar to this one. Returns tags ranked by similarity,
|
113
76
|
# based on listening data.
|
114
|
-
def similar
|
115
|
-
|
116
|
-
get_response('tag.getsimilar', :similar, 'similartags', 'tag', params, force)
|
77
|
+
def similar
|
78
|
+
call('tag.getsimilar', :similartags, Tag, {:tag => @name})
|
117
79
|
end
|
118
80
|
|
119
81
|
def weekly_artist_chart
|