hornairs-scrobbler 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +13 -0
- data/.loadpath +5 -0
- data/History.txt +5 -0
- data/MIT-LICENSE +19 -0
- data/Manifest +75 -0
- data/README.rdoc +104 -0
- data/Rakefile +10 -0
- data/VERSION.yml +5 -0
- data/examples/album.rb +20 -0
- data/examples/artist.rb +13 -0
- data/examples/playlist.rb +7 -0
- data/examples/scrobble.rb +31 -0
- data/examples/tag.rb +11 -0
- data/examples/track.rb +12 -0
- data/examples/user.rb +15 -0
- data/lib/scrobbler.rb +33 -0
- data/lib/scrobbler/album.rb +181 -0
- data/lib/scrobbler/artist.rb +165 -0
- data/lib/scrobbler/auth.rb +47 -0
- data/lib/scrobbler/base.rb +105 -0
- data/lib/scrobbler/event.rb +105 -0
- data/lib/scrobbler/geo.rb +27 -0
- data/lib/scrobbler/helper/image.rb +52 -0
- data/lib/scrobbler/helper/streamable.rb +40 -0
- data/lib/scrobbler/library.rb +112 -0
- data/lib/scrobbler/playing.rb +49 -0
- data/lib/scrobbler/playlist.rb +87 -0
- data/lib/scrobbler/radio.rb +12 -0
- data/lib/scrobbler/rest.rb +47 -0
- data/lib/scrobbler/scrobble.rb +116 -0
- data/lib/scrobbler/session.rb +9 -0
- data/lib/scrobbler/shout.rb +21 -0
- data/lib/scrobbler/simpleauth.rb +60 -0
- data/lib/scrobbler/tag.rb +113 -0
- data/lib/scrobbler/track.rb +152 -0
- data/lib/scrobbler/user.rb +222 -0
- data/lib/scrobbler/venue.rb +67 -0
- data/setup.rb +1585 -0
- data/tasks/jeweler.rake +15 -0
- data/tasks/rdoc.rake +7 -0
- data/tasks/tests.rake +13 -0
- data/tasks/yardoc.rake +8 -0
- data/test/fixtures/xml/album/info.xml +43 -0
- data/test/fixtures/xml/artist/fans.xml +52 -0
- data/test/fixtures/xml/artist/info.xml +58 -0
- data/test/fixtures/xml/artist/similar.xml +1004 -0
- data/test/fixtures/xml/artist/topalbums.xml +61 -0
- data/test/fixtures/xml/artist/toptags.xml +19 -0
- data/test/fixtures/xml/artist/toptracks.xml +62 -0
- data/test/fixtures/xml/auth/session.xml +7 -0
- data/test/fixtures/xml/auth/token.xml +3 -0
- data/test/fixtures/xml/event/attend.xml +3 -0
- data/test/fixtures/xml/event/attendees.xml +53 -0
- data/test/fixtures/xml/event/event.xml +35 -0
- data/test/fixtures/xml/event/shouts.xml +35 -0
- data/test/fixtures/xml/geo/events-distance-p1.xml +151 -0
- data/test/fixtures/xml/geo/events-lat-long.xml +167 -0
- data/test/fixtures/xml/geo/events-p1.xml +152 -0
- data/test/fixtures/xml/geo/events-p2.xml +380 -0
- data/test/fixtures/xml/geo/events-p3.xml +427 -0
- data/test/fixtures/xml/geo/top_artists-p1.xml +76 -0
- data/test/fixtures/xml/geo/top_tracks-p1.xml +77 -0
- data/test/fixtures/xml/library/albums-f30.xml +454 -0
- data/test/fixtures/xml/library/albums-p1.xml +754 -0
- data/test/fixtures/xml/library/albums-p2.xml +754 -0
- data/test/fixtures/xml/library/albums-p3.xml +754 -0
- data/test/fixtures/xml/library/albums-p4.xml +739 -0
- data/test/fixtures/xml/library/albums-p5.xml +754 -0
- data/test/fixtures/xml/library/albums-p6.xml +754 -0
- data/test/fixtures/xml/library/albums-p7.xml +739 -0
- data/test/fixtures/xml/library/albums-p8.xml +724 -0
- data/test/fixtures/xml/library/artists-f30.xml +334 -0
- data/test/fixtures/xml/library/artists-p1.xml +554 -0
- data/test/fixtures/xml/library/artists-p2.xml +554 -0
- data/test/fixtures/xml/library/artists-p3.xml +554 -0
- data/test/fixtures/xml/library/artists-p4.xml +554 -0
- data/test/fixtures/xml/library/artists-p5.xml +554 -0
- data/test/fixtures/xml/library/artists-p6.xml +554 -0
- data/test/fixtures/xml/library/artists-p7.xml +444 -0
- data/test/fixtures/xml/library/tracks-f30.xml +472 -0
- data/test/fixtures/xml/library/tracks-p1.xml +789 -0
- data/test/fixtures/xml/library/tracks-p10.xml +771 -0
- data/test/fixtures/xml/library/tracks-p11.xml +792 -0
- data/test/fixtures/xml/library/tracks-p12.xml +777 -0
- data/test/fixtures/xml/library/tracks-p13.xml +762 -0
- data/test/fixtures/xml/library/tracks-p14.xml +759 -0
- data/test/fixtures/xml/library/tracks-p15.xml +762 -0
- data/test/fixtures/xml/library/tracks-p16.xml +756 -0
- data/test/fixtures/xml/library/tracks-p17.xml +780 -0
- data/test/fixtures/xml/library/tracks-p18.xml +756 -0
- data/test/fixtures/xml/library/tracks-p19.xml +774 -0
- data/test/fixtures/xml/library/tracks-p2.xml +765 -0
- data/test/fixtures/xml/library/tracks-p20.xml +777 -0
- data/test/fixtures/xml/library/tracks-p21.xml +777 -0
- data/test/fixtures/xml/library/tracks-p22.xml +771 -0
- data/test/fixtures/xml/library/tracks-p23.xml +765 -0
- data/test/fixtures/xml/library/tracks-p24.xml +783 -0
- data/test/fixtures/xml/library/tracks-p25.xml +777 -0
- data/test/fixtures/xml/library/tracks-p26.xml +777 -0
- data/test/fixtures/xml/library/tracks-p27.xml +756 -0
- data/test/fixtures/xml/library/tracks-p28.xml +771 -0
- data/test/fixtures/xml/library/tracks-p29.xml +753 -0
- data/test/fixtures/xml/library/tracks-p3.xml +771 -0
- data/test/fixtures/xml/library/tracks-p30.xml +780 -0
- data/test/fixtures/xml/library/tracks-p31.xml +753 -0
- data/test/fixtures/xml/library/tracks-p32.xml +771 -0
- data/test/fixtures/xml/library/tracks-p33.xml +762 -0
- data/test/fixtures/xml/library/tracks-p34.xml +538 -0
- data/test/fixtures/xml/library/tracks-p4.xml +792 -0
- data/test/fixtures/xml/library/tracks-p5.xml +780 -0
- data/test/fixtures/xml/library/tracks-p6.xml +789 -0
- data/test/fixtures/xml/library/tracks-p7.xml +789 -0
- data/test/fixtures/xml/library/tracks-p8.xml +780 -0
- data/test/fixtures/xml/library/tracks-p9.xml +774 -0
- data/test/fixtures/xml/tag/similar.xml +254 -0
- data/test/fixtures/xml/tag/topalbums.xml +805 -0
- data/test/fixtures/xml/tag/topartists.xml +605 -0
- data/test/fixtures/xml/tag/toptags.xml +1254 -0
- data/test/fixtures/xml/tag/toptracks.xml +852 -0
- data/test/fixtures/xml/track/fans.xml +34 -0
- data/test/fixtures/xml/track/info.xml +53 -0
- data/test/fixtures/xml/track/toptags.xml +504 -0
- data/test/fixtures/xml/user/events.xml +401 -0
- data/test/fixtures/xml/user/friends.xml +30 -0
- data/test/fixtures/xml/user/lovedtracks.xml +678 -0
- data/test/fixtures/xml/user/neighbours.xml +23 -0
- data/test/fixtures/xml/user/playlists.xml +61 -0
- data/test/fixtures/xml/user/profile.xml +12 -0
- data/test/fixtures/xml/user/recentbannedtracks.xml +24 -0
- data/test/fixtures/xml/user/recentlovedtracks.xml +24 -0
- data/test/fixtures/xml/user/recenttracks.xml +124 -0
- data/test/fixtures/xml/user/systemrecs.xml +18 -0
- data/test/fixtures/xml/user/topalbums.xml +61 -0
- data/test/fixtures/xml/user/topartists.xml +41 -0
- data/test/fixtures/xml/user/toptags.xml +44 -0
- data/test/fixtures/xml/user/toptracks.xml +65 -0
- data/test/fixtures/xml/user/weeklyalbumchart.xml +256 -0
- data/test/fixtures/xml/user/weeklyartistchart.xml +220 -0
- data/test/fixtures/xml/user/weeklytrackchart.xml +746 -0
- data/test/fixtures/xml/venue/events.xml +151 -0
- data/test/fixtures/xml/venue/venue.xml +16 -0
- data/test/mocks/rest.rb +212 -0
- data/test/spec_helper.rb +7 -0
- data/test/test_helper.rb +20 -0
- data/test/unit/album_spec.rb +52 -0
- data/test/unit/artist_spec.rb +130 -0
- data/test/unit/auth_spec.rb +36 -0
- data/test/unit/event_spec.rb +109 -0
- data/test/unit/geo_spec.rb +148 -0
- data/test/unit/library_spec.rb +133 -0
- data/test/unit/playing_test.rb +53 -0
- data/test/unit/playlist_spec.rb +25 -0
- data/test/unit/radio_spec.rb +22 -0
- data/test/unit/scrobble_spec.rb +55 -0
- data/test/unit/scrobble_test.rb +69 -0
- data/test/unit/simpleauth_test.rb +45 -0
- data/test/unit/tag_spec.rb +101 -0
- data/test/unit/track_spec.rb +95 -0
- data/test/unit/user_spec.rb +264 -0
- data/test/unit/venue_spec.rb +104 -0
- metadata +265 -0
data/.gitignore
ADDED
data/.loadpath
ADDED
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,75 @@
|
|
1
|
+
lib/scrobbler/geo.rb
|
2
|
+
lib/scrobbler/search.rb
|
3
|
+
lib/scrobbler/rest.rb
|
4
|
+
lib/scrobbler/track.rb
|
5
|
+
lib/scrobbler/simpleauth.rb
|
6
|
+
lib/scrobbler/base.rb
|
7
|
+
lib/scrobbler/version.rb
|
8
|
+
lib/scrobbler/event.rb
|
9
|
+
lib/scrobbler/playing.rb
|
10
|
+
lib/scrobbler/artist.rb
|
11
|
+
lib/scrobbler/scrobble.rb
|
12
|
+
lib/scrobbler/user.rb
|
13
|
+
lib/scrobbler/album.rb
|
14
|
+
lib/scrobbler/tag.rb
|
15
|
+
lib/scrobbler/playlist.rb
|
16
|
+
lib/scrobbler.rb
|
17
|
+
scrobbler.gemspec
|
18
|
+
MIT-LICENSE
|
19
|
+
Rakefile
|
20
|
+
History.txt
|
21
|
+
setup.rb
|
22
|
+
README.rdoc
|
23
|
+
examples/track.rb
|
24
|
+
examples/artist.rb
|
25
|
+
examples/scrobble.rb
|
26
|
+
examples/user.rb
|
27
|
+
examples/album.rb
|
28
|
+
examples/tag.rb
|
29
|
+
examples/playlist.rb
|
30
|
+
test/unit/album_test.rb
|
31
|
+
test/unit/playing_test.rb
|
32
|
+
test/unit/scrobble_test.rb
|
33
|
+
test/unit/artist_test.rb
|
34
|
+
test/unit/chart_test.rb
|
35
|
+
test/unit/track_test.rb
|
36
|
+
test/unit/tag_test.rb
|
37
|
+
test/unit/geo_test.rb
|
38
|
+
test/unit/search_test.rb
|
39
|
+
test/unit/simpleauth_test.rb
|
40
|
+
test/unit/user_test.rb
|
41
|
+
test/test_helper.rb
|
42
|
+
test/mocks/rest.rb
|
43
|
+
test/fixtures/xml/geo/top_artists.xml
|
44
|
+
test/fixtures/xml/geo/events.xml
|
45
|
+
test/fixtures/xml/album/info.xml
|
46
|
+
test/fixtures/xml/track/toptags.xml
|
47
|
+
test/fixtures/xml/track/fans.xml
|
48
|
+
test/fixtures/xml/artist/toptags.xml
|
49
|
+
test/fixtures/xml/artist/similar.xml
|
50
|
+
test/fixtures/xml/artist/topalbums.xml
|
51
|
+
test/fixtures/xml/artist/toptracks.xml
|
52
|
+
test/fixtures/xml/artist/fans.xml
|
53
|
+
test/fixtures/xml/tag/toptags.xml
|
54
|
+
test/fixtures/xml/tag/topalbums.xml
|
55
|
+
test/fixtures/xml/tag/toptracks.xml
|
56
|
+
test/fixtures/xml/tag/topartists.xml
|
57
|
+
test/fixtures/xml/search/track.xml
|
58
|
+
test/fixtures/xml/search/artist.xml
|
59
|
+
test/fixtures/xml/search/album.xml
|
60
|
+
test/fixtures/xml/user/toptags.xml
|
61
|
+
test/fixtures/xml/user/recentbannedtracks.xml
|
62
|
+
test/fixtures/xml/user/topalbums.xml
|
63
|
+
test/fixtures/xml/user/toptracks.xml
|
64
|
+
test/fixtures/xml/user/recentlovedtracks.xml
|
65
|
+
test/fixtures/xml/user/weeklytrackchart.xml
|
66
|
+
test/fixtures/xml/user/weeklyalbumchart.xml
|
67
|
+
test/fixtures/xml/user/recenttracks.xml
|
68
|
+
test/fixtures/xml/user/friends.xml
|
69
|
+
test/fixtures/xml/user/profile.xml
|
70
|
+
test/fixtures/xml/user/weeklyartistchart.xml
|
71
|
+
test/fixtures/xml/user/topartists.xml
|
72
|
+
test/fixtures/xml/user/systemrecs.xml
|
73
|
+
test/fixtures/xml/user/neighbours.xml
|
74
|
+
test/fixtures/xml/user/lovedtracks.xml
|
75
|
+
Manifest
|
data/README.rdoc
ADDED
@@ -0,0 +1,104 @@
|
|
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('Some Hearts', :artist => 'Carrie Underwood', :include_info => true)
|
32
|
+
|
33
|
+
puts "Album: #{album.name}"
|
34
|
+
puts "Artist: #{album.artist}"
|
35
|
+
puts "Playcount: #{album.playcount}"
|
36
|
+
puts "URL: #{album.url}"
|
37
|
+
puts "Release Date: #{album.release_date.strftime('%m/%d/%Y')}"
|
38
|
+
|
39
|
+
==Artists
|
40
|
+
|
41
|
+
artist = Scrobbler::Artist.new('Carrie Underwood')
|
42
|
+
|
43
|
+
puts 'Top Tracks'
|
44
|
+
puts "=" * 10
|
45
|
+
artist.top_tracks.each { |t| puts "(#{t.playcount}) #{t.name}" }
|
46
|
+
|
47
|
+
puts
|
48
|
+
|
49
|
+
puts 'Similar Artists'
|
50
|
+
puts "=" * 15
|
51
|
+
artist.similar.each { |a| puts "(#{a.match}%) #{a.name}" }
|
52
|
+
|
53
|
+
==Geo
|
54
|
+
|
55
|
+
geo = Scrobbler::Geo.new()
|
56
|
+
|
57
|
+
puts 'Events'
|
58
|
+
puts "=" * 10
|
59
|
+
geo.events(:location => 'Manchester').each { |e| puts "(#{e.id}) #{e.title}" }
|
60
|
+
|
61
|
+
puts
|
62
|
+
|
63
|
+
puts 'Top Artists'
|
64
|
+
puts "=" * 10
|
65
|
+
geo.top_artists(:location => 'Manchester').each { |a| puts "(#{a.name}) #{a.playcount}" }
|
66
|
+
|
67
|
+
puts
|
68
|
+
|
69
|
+
puts 'Top Tracks'
|
70
|
+
puts "=" * 10
|
71
|
+
geo.top_tracks(:location => 'Manchester').each { |t| puts "(#{a.name}) #{a.playcount}" }
|
72
|
+
|
73
|
+
|
74
|
+
==Tags
|
75
|
+
|
76
|
+
tag = Scrobbler::Tag.new('country')
|
77
|
+
|
78
|
+
puts 'Top Albums'
|
79
|
+
tag.top_albums.each { |a| puts "(#{a.count}) #{a.name} by #{a.artist}" }
|
80
|
+
|
81
|
+
puts
|
82
|
+
|
83
|
+
puts 'Top Tracks'
|
84
|
+
tag.top_tracks.each { |t| puts "(#{t.count}) #{t.name} by #{t.artist}" }
|
85
|
+
|
86
|
+
==Tracks
|
87
|
+
|
88
|
+
track = Scrobbler::Track.new('Carrie Underwood', 'Before He Cheats')
|
89
|
+
puts 'Fans'
|
90
|
+
puts "=" * 4
|
91
|
+
track.top_fans.each { |u| puts "(#{u.weight}) #{u.username}" }
|
92
|
+
|
93
|
+
== Simple Authentication (for Scrobbling)
|
94
|
+
|
95
|
+
work in progress...
|
96
|
+
|
97
|
+
== Scrobbling
|
98
|
+
|
99
|
+
work in progress...
|
100
|
+
|
101
|
+
== Now Playing Submission
|
102
|
+
|
103
|
+
work in progress...
|
104
|
+
|
data/Rakefile
ADDED
data/VERSION.yml
ADDED
data/examples/album.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'scrobbler'))
|
2
|
+
|
3
|
+
Scrobbler::Base::api_key = "cc85b6d4313e40450230872430b4d631";
|
4
|
+
|
5
|
+
album = Scrobbler::Album.new('Carrie Underwood', 'Some Hearts', :include_all_info => true)
|
6
|
+
|
7
|
+
puts "Album: #{album.name}"
|
8
|
+
puts "Album ID: #{album.album_id}"
|
9
|
+
puts "Artist: #{album.artist}"
|
10
|
+
puts "Playcount: #{album.playcount}"
|
11
|
+
puts "URL: #{album.url}"
|
12
|
+
puts "Release Date: #{album.release_date.strftime('%m/%d/%Y')}"
|
13
|
+
|
14
|
+
puts
|
15
|
+
puts
|
16
|
+
|
17
|
+
# puts "Tracks"
|
18
|
+
# longest_track_name = album.tracks.collect(&:name).sort { |x, y| y.length <=> x.length }.first.length
|
19
|
+
# puts "=" * longest_track_name
|
20
|
+
# album.tracks.each { |t| puts t.name }
|
data/examples/artist.rb
ADDED
@@ -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,12 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'scrobbler'))
|
2
|
+
require 'pp'
|
3
|
+
|
4
|
+
Scrobbler::Base::api_key = "cc85b6d4313e40450230872430b4d631";
|
5
|
+
|
6
|
+
track = Scrobbler::Track.new('Carrie Underwood', :name => 'Before He Cheats', :include_info => true)
|
7
|
+
puts "Name: #{track.name}"
|
8
|
+
puts "Album: #{track.album.name}"
|
9
|
+
puts "Artist: #{track.artist.name}"
|
10
|
+
puts "Playcount: #{track.playcount}"
|
11
|
+
puts "URL: #{track.url}"
|
12
|
+
|
data/examples/user.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'scrobbler'))
|
2
|
+
require 'pp'
|
3
|
+
user = Scrobbler::User.new('hornairs')
|
4
|
+
pp user
|
5
|
+
#
|
6
|
+
# puts "#{user.username}'s Recent Tracks"
|
7
|
+
# puts "=" * (user.username.length + 16)
|
8
|
+
# user.recent_tracks.each { |t| puts t.name }
|
9
|
+
#
|
10
|
+
# puts
|
11
|
+
# puts
|
12
|
+
#
|
13
|
+
# puts "#{user.username}'s Top Tracks"
|
14
|
+
# puts "=" * (user.username.length + 13)
|
15
|
+
# user.top_tracks.each { |t| puts "(#{t.playcount}) #{t.name}" }
|
data/lib/scrobbler.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
%w{uri rubygems libxml active_support pp}.each { |x| require x }
|
2
|
+
require 'digest/md5'
|
3
|
+
|
4
|
+
$: << File.expand_path(File.dirname(__FILE__))
|
5
|
+
|
6
|
+
# Load base class
|
7
|
+
require 'scrobbler/base'
|
8
|
+
|
9
|
+
# Load helper modules
|
10
|
+
require 'scrobbler/helper/image'
|
11
|
+
require 'scrobbler/helper/streamable'
|
12
|
+
|
13
|
+
require 'scrobbler/album'
|
14
|
+
require 'scrobbler/artist'
|
15
|
+
require 'scrobbler/event'
|
16
|
+
require 'scrobbler/shout'
|
17
|
+
require 'scrobbler/venue'
|
18
|
+
require 'scrobbler/geo'
|
19
|
+
require 'scrobbler/user'
|
20
|
+
require 'scrobbler/session'
|
21
|
+
require 'scrobbler/tag'
|
22
|
+
require 'scrobbler/track'
|
23
|
+
|
24
|
+
require 'scrobbler/auth'
|
25
|
+
require 'scrobbler/library'
|
26
|
+
require 'scrobbler/playlist'
|
27
|
+
require 'scrobbler/radio'
|
28
|
+
|
29
|
+
require 'scrobbler/simpleauth'
|
30
|
+
require 'scrobbler/scrobble'
|
31
|
+
require 'scrobbler/playing'
|
32
|
+
|
33
|
+
require 'scrobbler/rest'
|
@@ -0,0 +1,181 @@
|
|
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
|
+
class Album < Base
|
48
|
+
mixins :image
|
49
|
+
|
50
|
+
attr_reader :artist, :album_id, :artist_mbid, :name, :mbid, :playcount, :rank, :url
|
51
|
+
attr_reader :reach, :release_date, :listeners, :playcount, :top_tags
|
52
|
+
attr_reader :image_large, :image_medium, :image_small, :tagcount
|
53
|
+
|
54
|
+
# needed on top albums for tag
|
55
|
+
attr_reader :count, :playlist
|
56
|
+
|
57
|
+
# needed for weekly album charts
|
58
|
+
attr_reader :chartposition, :position
|
59
|
+
|
60
|
+
class << self
|
61
|
+
|
62
|
+
def new_from_xml(xml, o = {})
|
63
|
+
data = self.data_from_xml(xml)
|
64
|
+
return nil if data[:name].empty?
|
65
|
+
Album.new(data[:artist], data[:name], data)
|
66
|
+
end
|
67
|
+
|
68
|
+
def data_from_xml(xml, o = {})
|
69
|
+
data = {}
|
70
|
+
o = {:include_artist_info => true}.merge(o)
|
71
|
+
xml.children.each do |child|
|
72
|
+
data[:name] = child.content if ['name', 'title'].include?(child.name)
|
73
|
+
data[:album_id] = child.content.to_i if child.name == 'id'
|
74
|
+
data[:playcount] = child.content.to_i if child.name == 'playcount'
|
75
|
+
data[:tagcount] = child.content.to_i if child.name == 'tagcount'
|
76
|
+
data[:release_date] = Time.parse(child.content.strip) if child.name == 'releasedate'
|
77
|
+
data[:listeners] = child.content.to_i if child.name == 'listeners'
|
78
|
+
data[:mbid] = child.content if child.name == 'mbid'
|
79
|
+
data[:url] = child.content if child.name == 'url'
|
80
|
+
data[:artist] = Artist.new_from_xml(child) if (child.name == 'artist' || child.name == 'creator') && o[:include_artist_info]
|
81
|
+
maybe_image_node(data, child)
|
82
|
+
if child.name == 'toptags'
|
83
|
+
data[:top_tags] = []
|
84
|
+
child.children.each do |grandchild|
|
85
|
+
next unless grandchild.name == 'tag'
|
86
|
+
data[:top_tags] << Tag.new_from_xml(grandchild)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
# If we have not found anything in the content of this node yet then
|
92
|
+
# this must be a simple artist node which has the name of the artist
|
93
|
+
# as its content
|
94
|
+
data[:name] = xml.content if data == {}
|
95
|
+
|
96
|
+
# Get all information from the root's attributes
|
97
|
+
data[:mbid] = xml['mbid'] if xml['mbid']
|
98
|
+
data[:rank] = xml['rank'].to_i if xml['rank']
|
99
|
+
data[:position] = xml['position'].to_i if xml['position']
|
100
|
+
|
101
|
+
# If there is no name defined, than this was an empty album tag
|
102
|
+
return nil if data[:name].empty?
|
103
|
+
data
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
# If the additional parameter :include_info is set to true, additional
|
108
|
+
# information is loaded
|
109
|
+
#
|
110
|
+
# @todo Albums should be able to be created via a MusicBrainz id too
|
111
|
+
def initialize(artist, name, data={})
|
112
|
+
super()
|
113
|
+
raise ArgumentError, "Artist or MBID is required" if artist.blank?
|
114
|
+
|
115
|
+
#check for old style parameter arguments, infer MBID if only an artist is given
|
116
|
+
if artist.class == String && name.blank? && data == {}
|
117
|
+
raise ArgumentError, "MBID is required for an MBID query" if input.blank?
|
118
|
+
@mbid = input
|
119
|
+
load_album_info() # data must be fetched since all we have is an mbid, nothing else useful
|
120
|
+
else
|
121
|
+
raise ArgumentError, "Artist is required" if artist.blank?
|
122
|
+
raise ArgumentError, "Album Name is required" if name.blank?
|
123
|
+
@artist = Artist.new(artist)
|
124
|
+
@name = name
|
125
|
+
load_album_info() if data[:include_info] || data[:include_all_info]
|
126
|
+
load_track_info() if data[:include_all_info]
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
# Indicates if the album info was already loaded
|
131
|
+
@album_info_loaded = false
|
132
|
+
|
133
|
+
# Load additional information about this album
|
134
|
+
#
|
135
|
+
# Calls "album.getinfo" REST method
|
136
|
+
#
|
137
|
+
# @todo Parse wiki content
|
138
|
+
# @todo Add language code for wiki translation
|
139
|
+
def load_album_info
|
140
|
+
return nil if @album_info_loaded
|
141
|
+
params = @mbid ? {'mbid' => @mbid} : {'artist' => @artist.name, 'album' => @name}
|
142
|
+
xml = Base.request('album.getinfo', params)
|
143
|
+
unless xml.root['status'] == 'failed'
|
144
|
+
xml.root.children.each do |child|
|
145
|
+
next unless child.name == 'album'
|
146
|
+
data = self.class.data_from_xml(child)
|
147
|
+
populate_data(data)
|
148
|
+
@album_info_loaded = true
|
149
|
+
break
|
150
|
+
end # xml.children.each do |child|
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
# Indicates if the album info was already loaded
|
155
|
+
@track_info_loaded = false
|
156
|
+
def load_track_info
|
157
|
+
return nil if @track_info_loaded
|
158
|
+
load_album_info() if !@album_info_loaded
|
159
|
+
@playlist = Playlist.new_from_album(self)
|
160
|
+
@tracks = @playlist.tracks
|
161
|
+
end
|
162
|
+
|
163
|
+
# Tag an album using a list of user supplied tags.
|
164
|
+
def add_tags(tags)
|
165
|
+
# This function require authentication, but SimpleAuth is not yet 2.0
|
166
|
+
raise NotImplementedError
|
167
|
+
end
|
168
|
+
|
169
|
+
# Get the tags applied by an individual user to an album on Last.fm.
|
170
|
+
def tags()
|
171
|
+
# This function require authentication, but SimpleAuth is not yet 2.0
|
172
|
+
raise NotImplementedError
|
173
|
+
end
|
174
|
+
|
175
|
+
# Remove a user's tag from an album.
|
176
|
+
def remove_tag()
|
177
|
+
# This function require authentication, but SimpleAuth is not yet 2.0
|
178
|
+
raise NotImplementedError
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|