rscrobbler 0.2.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +15 -0
- data/lib/lastfm/album.rb +197 -55
- data/lib/lastfm/artist.rb +291 -48
- data/lib/lastfm/auth.rb +33 -0
- data/lib/lastfm/buylink.rb +34 -34
- data/lib/lastfm/chart.rb +61 -0
- data/lib/lastfm/event.rb +128 -62
- data/lib/lastfm/geo.rb +123 -0
- data/lib/lastfm/group.rb +67 -0
- data/lib/lastfm/library.rb +115 -0
- data/lib/lastfm/playlist.rb +38 -0
- data/lib/lastfm/radio.rb +39 -0
- data/lib/lastfm/shout.rb +20 -20
- data/lib/lastfm/struct.rb +59 -40
- data/lib/lastfm/tag.rb +144 -29
- data/lib/lastfm/tasteometer.rb +35 -0
- data/lib/lastfm/track.rb +324 -57
- data/lib/lastfm/user.rb +264 -0
- data/lib/lastfm/venue.rb +60 -25
- data/lib/lastfm/wiki.rb +20 -20
- data/lib/rscrobbler.rb +207 -214
- data/test/test_album.rb +35 -35
- metadata +20 -25
- data/lib/lastfm/api/album.rb +0 -140
- data/lib/lastfm/api/artist.rb +0 -243
- data/lib/lastfm/api/auth.rb +0 -35
- data/lib/lastfm/api/chart.rb +0 -63
- data/lib/lastfm/api/event.rb +0 -71
- data/lib/lastfm/api/geo.rb +0 -125
- data/lib/lastfm/api/group.rb +0 -69
- data/lib/lastfm/api/library.rb +0 -117
- data/lib/lastfm/api/playlist.rb +0 -40
- data/lib/lastfm/api/radio.rb +0 -41
- data/lib/lastfm/api/tag.rb +0 -120
- data/lib/lastfm/api/tasteometer.rb +0 -37
- data/lib/lastfm/api/track.rb +0 -272
- data/lib/lastfm/api/user.rb +0 -266
- data/lib/lastfm/api/venue.rb +0 -40
data/lib/lastfm/radio.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
module LastFM
|
2
|
+
class Radio
|
3
|
+
class << self
|
4
|
+
|
5
|
+
# Fetch new radio content periodically in an XSPF format.
|
6
|
+
#
|
7
|
+
# @option params [Boolean, optional] :discovery whether to request last.fm content in discovery mode
|
8
|
+
# @option params [Boolean, optional] :rtp whether the user is scrobbling or not during this session (helps content generation)
|
9
|
+
# @option params [Boolean, optional] :buylinks whether the response should contain links for purchase/download
|
10
|
+
# @option params [String, optional] :speed_multiplier the rate at which to provide the stream (supported multipliers are 1.0 and 2.0)
|
11
|
+
# @option params [String, optional] :bitrate what bitrate to stream content at, in kbps (supported bitrates are 64 and 128)
|
12
|
+
# @see http://www.last.fm/api/show?service=256
|
13
|
+
def get_playlist( params )
|
14
|
+
LastFM.requires_authentication
|
15
|
+
LastFM.get( "radio.getPlaylist", params, :secure )
|
16
|
+
end
|
17
|
+
|
18
|
+
# Resolve the name of a resource into a station depending
|
19
|
+
# on which resource it is most likely to represent.
|
20
|
+
#
|
21
|
+
# @option params [String, required] :name the tag or artist name to resolve
|
22
|
+
# @see http://www.last.fm/api/show?service=418
|
23
|
+
def search( params )
|
24
|
+
LastFM.get( "radio.search", params )
|
25
|
+
end
|
26
|
+
|
27
|
+
# Tune in to a Last.fm radio station.
|
28
|
+
#
|
29
|
+
# @option params [String, required] :station a 'lastfm://...' radio url
|
30
|
+
# @option params [String, optional] :lang the language to return the station name in, expressed as an ISO 639 alpha-2 code
|
31
|
+
# @see http://www.last.fm/api/show?service=160
|
32
|
+
def tune( params )
|
33
|
+
LastFM.requires_authentication
|
34
|
+
LastFM.post( "radio.tune", params )
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/lastfm/shout.rb
CHANGED
@@ -1,20 +1,20 @@
|
|
1
|
-
module LastFM
|
2
|
-
|
3
|
-
# @attr [String] author
|
4
|
-
# @attr [String] body
|
5
|
-
# @attr [Time] date
|
6
|
-
class Shout < Struct.new(:author, :body, :date)
|
7
|
-
|
8
|
-
def update_from_node(node)
|
9
|
-
case node.name.to_sym
|
10
|
-
when :author
|
11
|
-
self.author = node.content
|
12
|
-
when :body
|
13
|
-
self.body = node.content
|
14
|
-
when :date
|
15
|
-
self.date = Time.parse(node.content) rescue nil
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
end
|
20
|
-
end
|
1
|
+
module LastFM
|
2
|
+
|
3
|
+
# @attr [String] author
|
4
|
+
# @attr [String] body
|
5
|
+
# @attr [Time] date
|
6
|
+
class Shout < Struct.new(:author, :body, :date)
|
7
|
+
|
8
|
+
def update_from_node(node)
|
9
|
+
case node.name.to_sym
|
10
|
+
when :author
|
11
|
+
self.author = node.content
|
12
|
+
when :body
|
13
|
+
self.body = node.content
|
14
|
+
when :date
|
15
|
+
self.date = Time.parse(node.content) rescue nil
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
data/lib/lastfm/struct.rb
CHANGED
@@ -1,40 +1,59 @@
|
|
1
|
-
module LastFM
|
2
|
-
|
3
|
-
# Prodives modifications to Ruby's Struct class for use within the LastFM module space.
|
4
|
-
# Must be called 'Struct' to play nice with YARD's @attr documentation.
|
5
|
-
class Struct < Struct
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
#
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
end
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
1
|
+
module LastFM
|
2
|
+
|
3
|
+
# Prodives modifications to Ruby's Struct class for use within the LastFM module space.
|
4
|
+
# Must be called 'Struct' to play nice with YARD's @attr documentation.
|
5
|
+
class Struct < Struct
|
6
|
+
|
7
|
+
def self.inherited(child)
|
8
|
+
child.class_eval do
|
9
|
+
members.each do |mem|
|
10
|
+
# Override member= methods to filter through parse_node when given an XML::Node
|
11
|
+
define_method(:"#{mem}=") do |val|
|
12
|
+
val = parse_node(mem, val) if val.is_a?(LibXML::XML::Node)
|
13
|
+
super val
|
14
|
+
end
|
15
|
+
end if public_methods.include?(:members)
|
16
|
+
end
|
17
|
+
|
18
|
+
super
|
19
|
+
end
|
20
|
+
|
21
|
+
# Override Struct's initialize method to accept a hash of members instead.
|
22
|
+
def initialize(h={})
|
23
|
+
members.each{|m| self[m] = h[m.to_sym]}
|
24
|
+
end
|
25
|
+
|
26
|
+
# Get the Last.fm package name for a Ruby class
|
27
|
+
#
|
28
|
+
# @return [String] the Last.fm package name
|
29
|
+
def self.package
|
30
|
+
self.to_s.downcase.split('::').last
|
31
|
+
end
|
32
|
+
|
33
|
+
# Construct a LastFM::Struct object from XML, using each inheritor's attr_from_node
|
34
|
+
# method to determine how to manipulate individual attributes.
|
35
|
+
#
|
36
|
+
# @param [LibXML::XML::Document] xml XML obtained from a Last.fm API call
|
37
|
+
# @param [Hash] initial_attributes Attributes to set before parsing the XML
|
38
|
+
# @return [LastFM::Struct] object contructed from attributes contained in XML
|
39
|
+
def self.from_xml(xml, initial_attributes={})
|
40
|
+
xml = xml.find_first(self.package) if xml.is_a?(LibXML::XML::Document)
|
41
|
+
model = self.new(initial_attributes)
|
42
|
+
xml.find('*').each{|node|
|
43
|
+
if self.method_defined?(:update_from_node)
|
44
|
+
model.update_from_node(node)
|
45
|
+
else
|
46
|
+
model.send(:"#{node.name}=", node)
|
47
|
+
end
|
48
|
+
}
|
49
|
+
model
|
50
|
+
end
|
51
|
+
|
52
|
+
def to_json(*a)
|
53
|
+
members.inject({}){|map, m|
|
54
|
+
map[m] = self[m]; map
|
55
|
+
}.to_json(*a)
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
data/lib/lastfm/tag.rb
CHANGED
@@ -1,29 +1,144 @@
|
|
1
|
-
module LastFM
|
2
|
-
|
3
|
-
# @attr [String] name
|
4
|
-
# @attr [Fixnum] count
|
5
|
-
# @attr [String] url
|
6
|
-
# @attr [Fixnum] reach
|
7
|
-
# @attr [Boolean] streamable
|
8
|
-
# @attr [LastFM::Wiki] wiki
|
9
|
-
class Tag < Struct.new(:name, :count, :url, :reach, :streamable, :wiki)
|
10
|
-
|
11
|
-
def update_from_node(node)
|
12
|
-
case node.name.to_sym
|
13
|
-
when :name
|
14
|
-
self.name = node.content
|
15
|
-
when :url
|
16
|
-
self.url = node.content
|
17
|
-
when :reach
|
18
|
-
self.reach = node.content.to_i
|
19
|
-
when :count, :taggings
|
20
|
-
self.count = node.content.to_i
|
21
|
-
when :streamable
|
22
|
-
self.streamable = (node.content == '1')
|
23
|
-
when :wiki
|
24
|
-
self.wiki = LastFM::Wiki.from_xml(node)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
|
29
|
-
|
1
|
+
module LastFM
|
2
|
+
|
3
|
+
# @attr [String] name
|
4
|
+
# @attr [Fixnum] count
|
5
|
+
# @attr [String] url
|
6
|
+
# @attr [Fixnum] reach
|
7
|
+
# @attr [Boolean] streamable
|
8
|
+
# @attr [LastFM::Wiki] wiki
|
9
|
+
class Tag < Struct.new(:name, :count, :url, :reach, :streamable, :wiki)
|
10
|
+
|
11
|
+
def update_from_node(node)
|
12
|
+
case node.name.to_sym
|
13
|
+
when :name
|
14
|
+
self.name = node.content
|
15
|
+
when :url
|
16
|
+
self.url = node.content
|
17
|
+
when :reach
|
18
|
+
self.reach = node.content.to_i
|
19
|
+
when :count, :taggings
|
20
|
+
self.count = node.content.to_i
|
21
|
+
when :streamable
|
22
|
+
self.streamable = (node.content == '1')
|
23
|
+
when :wiki
|
24
|
+
self.wiki = LastFM::Wiki.from_xml(node)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# API Methods
|
29
|
+
class << self
|
30
|
+
|
31
|
+
# Get the metadata for a tag.
|
32
|
+
#
|
33
|
+
# @option params [String, required] :tag the tag name
|
34
|
+
# @option params [String, optional] :lang the language to return the summary in, expressed as an ISO 639 alpha-2 code
|
35
|
+
# @return [LastFM::Tag] tag constructed from the metadata contained in the response
|
36
|
+
# @see http://www.last.fm/api/show?service=452
|
37
|
+
def get_info( params )
|
38
|
+
xml = LastFM.get( "tag.getInfo", params )
|
39
|
+
LastFM::Tag.from_xml( xml )
|
40
|
+
end
|
41
|
+
|
42
|
+
# Search for tags similar to this one. Returns tags ranked by similarity, based on listening data.
|
43
|
+
#
|
44
|
+
# @option params [String, required] tag the tag name
|
45
|
+
# @return [Array<LastFM::Tag>] similar tags, ordered by similarity
|
46
|
+
# @see http://www.last.fm/api/show?service=311
|
47
|
+
def get_similar( params )
|
48
|
+
xml = LastFM.get( "tag.getSimilar", params )
|
49
|
+
xml.find('similartags/tag').map do |tag|
|
50
|
+
LastFM::Tag.from_xml( tag )
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# Get the top albums tagged with a tag, ordered by tag count.
|
55
|
+
#
|
56
|
+
# @option params [String, required] :tag the tag name
|
57
|
+
# @option params [Fixnum, optional] :page the page number to fetch. defaults to first page
|
58
|
+
# @option params [Fixnum, optional] :limit the number of results to fetch per page. defaults to 50
|
59
|
+
# @return [Array[LastFM::Album]] list of albums, ordered by tag count
|
60
|
+
# @see http://www.last.fm/api/show?service=283
|
61
|
+
def get_top_albums( params )
|
62
|
+
xml = LastFM.get( "tag.getTopAlbums", params )
|
63
|
+
xml.find('topalbums/album').map do |album|
|
64
|
+
LastFM::Album.from_xml( album )
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
# Get the top artists tagged with a tag, ordered by tag count.
|
69
|
+
#
|
70
|
+
# @option params [String, required] :tag the tag name
|
71
|
+
# @option params [Fixnum, optional] :page the page number to fetch. defaults to first page
|
72
|
+
# @option params [Fixnum, optional] :limit the number of results to fetch per page. defaults to 50
|
73
|
+
# @return [Array[LastFM::Artist]] list of artists, ordered by tag count
|
74
|
+
# @see http://www.last.fm/api/show?service=284
|
75
|
+
def get_top_artists( params )
|
76
|
+
xml = LastFM.get( "tag.getTopArtists", params )
|
77
|
+
xml.find('topartists/artist').map do |artist|
|
78
|
+
LastFM::Artist.from_xml( artist )
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
# Fetches the top global tags on Last.fm, sorted by popularity (number of times used).
|
83
|
+
#
|
84
|
+
# @return [Array<LastFM::Tag>] list of tags ordered by popularity
|
85
|
+
# @see http://www.last.fm/api/show?service=276
|
86
|
+
def get_top_tags
|
87
|
+
xml = LastFM.get( "tag.getTopTags" )
|
88
|
+
xml.find('toptags/tag').map do |tag|
|
89
|
+
LastFM::Tag.from_xml( tag )
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
# Get the top tracks tagged with a tag, ordered by tag count.
|
94
|
+
#
|
95
|
+
# @option params [String, required] :tag the tag name
|
96
|
+
# @option params [Fixnum, optional] :page the page number to fetch. defaults to first page
|
97
|
+
# @option params [Fixnum, optional] :limit the number of results to fetch per page. defaults to 50
|
98
|
+
# @return [Array[LastFM::Track]] list of tracks, ordered by tag count
|
99
|
+
# @see http://www.last.fm/api/show?service=285
|
100
|
+
def get_top_tracks( params )
|
101
|
+
xml = LastFM.get( "tag.getTopTracks", params )
|
102
|
+
xml.find('toptracks/track').map do |track|
|
103
|
+
LastFM::Track.from_xml( track )
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
# Get an artist chart for a tag, for a given date range. If no date range is
|
108
|
+
# supplied, it will return the most recent artist chart for this tag.
|
109
|
+
#
|
110
|
+
# @option params [String, required] :tag the tag name
|
111
|
+
# @option params [String, optional] :from date at which the chart should start from (see: Tag.get_weekly_chart_list)
|
112
|
+
# @option params [String, optional] :to date at which the chart should end on (see: Tag.get_weekly_chart_list)
|
113
|
+
# @option params [Fixnum, optional] :limit the number of results to fetch. defaults to 50
|
114
|
+
# @see http://www.last.fm/api/show?service=358
|
115
|
+
def get_weekly_artist_chart( params )
|
116
|
+
LastFM.get( "tag.getWeeklyArtistChart", params )
|
117
|
+
end
|
118
|
+
|
119
|
+
# Get a list of available charts for this tag, expressed as date
|
120
|
+
# ranges which can be sent to the chart services.
|
121
|
+
#
|
122
|
+
# @option params [String, required] :tag the tag name
|
123
|
+
# @see http://www.last.fm/api/show?service=359
|
124
|
+
def get_weekly_chart_list( params )
|
125
|
+
LastFM.get( "tag.getWeeklyChartList", params )
|
126
|
+
end
|
127
|
+
|
128
|
+
# Search for a tag by name. Returns matches sorted by relevance.
|
129
|
+
#
|
130
|
+
# @option params [String, required] :tag the tag name
|
131
|
+
# @option params [Fixnum, optional] :page the page number to fetch. defaults to first page
|
132
|
+
# @option params [Fixnum, optional] :limit the number of results to fetch per page. defaults to 50
|
133
|
+
# @return [Array<LastFM::Tag>] list of tags sorted by relevance
|
134
|
+
# @see http://www.last.fm/api/show?service=273
|
135
|
+
def search( params )
|
136
|
+
xml = LastFM.get( "tag.search", params )
|
137
|
+
xml.find('results/tagmatches/tag').map do |tag|
|
138
|
+
LastFM::Tag.from_xml( tag )
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module LastFM
|
2
|
+
class Tasteometer
|
3
|
+
class << self
|
4
|
+
|
5
|
+
# Get a Tasteometer score from two inputs, along with a list of shared
|
6
|
+
# artists. If the input is a User some additional information is returned.
|
7
|
+
#
|
8
|
+
# @option params [Array, required] :types two types are required for comparison. accepted types are 'user' and 'artists'
|
9
|
+
# @option params [Array, required] :values values for the corresponding types. accepted values are Last.fm usernames, or arrays of artist names (up to 100 artists)
|
10
|
+
# @option params [Fixnum, optional] :limit how many shared artists to display. default is 5
|
11
|
+
# @see http://www.last.fm/api/show?service=258
|
12
|
+
def compare( params )
|
13
|
+
Array(params.delete(:types)).each_with_index{|val, i| params["type[#{i}]"] = val}
|
14
|
+
Array(params.delete(:values)).each_with_index{|val, i| params["value[#{i}]"] = val}
|
15
|
+
LastFM.get( "tasteometer.compare", params )
|
16
|
+
end
|
17
|
+
|
18
|
+
# Get the scores between every user in a group of users, plus shared artists.
|
19
|
+
# Cuts off any similarities below a cutoff. Also returns a list of all users
|
20
|
+
# in the comparison and a small amount of metadata about each. Can take the
|
21
|
+
# list of users from a group, or a users friends.
|
22
|
+
#
|
23
|
+
# @option params [String, required] :source what source we're using for the comparison. accepted sources are 'user' and 'group'
|
24
|
+
# @option params [String, required] :value name of the source we're using. should be either a Last.fm username or group name
|
25
|
+
# @option params [Float, optional] :cutoff the minimum level over which comparisons should be returned. default is 0.2
|
26
|
+
# @option params [Fixnum, optional] :connection_limit the maximum number of connections each user should have. default is 6
|
27
|
+
# @see http://www.last.fm/api/show?service=500
|
28
|
+
# @deprecated This service has been deprecated and is no longer available
|
29
|
+
def compare_group(params)
|
30
|
+
LastFM.get( "tasteometer.compareGroup", params )
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|