audioscrobbler 0.0.2 → 0.1.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.
- data/audioscrobbler.gemspec +1 -1
- data/lib/audioscrobbler.rb +22 -13
- data/test/test_audioscrobbler.rb +35 -0
- metadata +2 -2
data/audioscrobbler.gemspec
CHANGED
data/lib/audioscrobbler.rb
CHANGED
@@ -6,10 +6,11 @@
|
|
6
6
|
# == Description
|
7
7
|
# This file contains an implementation of the Audioscrobbler plugin
|
8
8
|
# protocol, used to submit playlist history to Last.fm. The protocol
|
9
|
-
# description is located at
|
9
|
+
# description is located at
|
10
|
+
# http://www.audioscrobbler.net/development/protocol/ .
|
10
11
|
#
|
11
12
|
# == Version
|
12
|
-
# 0.0
|
13
|
+
# 0.1.0
|
13
14
|
#
|
14
15
|
# == Author
|
15
16
|
# Daniel Erat <dan-ruby@erat.org>
|
@@ -29,6 +30,8 @@
|
|
29
30
|
# - track numbers can be submitted
|
30
31
|
# Also added a race condition that I haven't bothered fixing (I
|
31
32
|
# think I'm the only person using this library?).
|
33
|
+
# 0.1.0 Catch an exception when the server gives us a bogus now-playing
|
34
|
+
# URL, as happened to me yesterday. :-P
|
32
35
|
|
33
36
|
require "cgi"
|
34
37
|
require "md5"
|
@@ -336,21 +339,27 @@ class Audioscrobbler
|
|
336
339
|
body = args.collect {|k, v| "#{k}=" + CGI.escape(v.to_s) }.join('&')
|
337
340
|
|
338
341
|
success = false
|
339
|
-
url = URI.parse(@now_playing_url)
|
340
|
-
headers = { 'Content-Type' => 'application/x-www-form-urlencoded' }
|
341
342
|
begin
|
342
|
-
|
343
|
-
http.post(url.path, body, headers).body
|
344
|
-
end
|
343
|
+
url = URI.parse(@now_playing_url)
|
345
344
|
rescue Exception
|
346
|
-
vlog("Submission failed -- couldn't
|
345
|
+
vlog("Submission failed -- couldn't parse now-playing " +
|
346
|
+
"URL \"#@now_playing_url\"")
|
347
347
|
else
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
348
|
+
headers = { 'Content-Type' => 'application/x-www-form-urlencoded' }
|
349
|
+
begin
|
350
|
+
data = Net::HTTP.start(url.host, url.port) do |http|
|
351
|
+
http.post(url.path, body, headers).body
|
352
|
+
end
|
353
|
+
rescue Exception
|
354
|
+
vlog("Submission failed -- couldn't read #@now_playing_url: #{$!}")
|
352
355
|
else
|
353
|
-
|
356
|
+
data.chomp!
|
357
|
+
if data == "OK"
|
358
|
+
vlog("Now-playing report was successful")
|
359
|
+
success = true
|
360
|
+
else
|
361
|
+
vlog("Now-playing report failed -- got \"#{data}\"")
|
362
|
+
end
|
354
363
|
end
|
355
364
|
end
|
356
365
|
success
|
data/test/test_audioscrobbler.rb
CHANGED
@@ -359,4 +359,39 @@ class TestAudioscrobbler < Test::Unit::TestCase
|
|
359
359
|
assert_equal(tracks, @submit_status.tracks)
|
360
360
|
assert_equal(now_playing, @now_playing_status.tracks)
|
361
361
|
end # test_audioscrobbler
|
362
|
+
|
363
|
+
# Test that we don't crash when the handshake returns an unparseable
|
364
|
+
# now-playing URL.
|
365
|
+
def test_broken_url
|
366
|
+
@handshake_status = AudioscrobblerHandshakeStatus.new
|
367
|
+
@submit_status = AudioscrobblerSubmitStatus.new
|
368
|
+
@now_playing_status = AudioscrobblerSubmitStatus.new
|
369
|
+
# FIXME(derat): Quite mortifying that I'm just using a different port
|
370
|
+
# from the previous tests instead of killing off the old server.
|
371
|
+
@http_port = 16350
|
372
|
+
|
373
|
+
@server_thread = Thread.new do
|
374
|
+
s = WEBrick::HTTPServer.new(:BindAddress => "127.0.0.1",
|
375
|
+
:Port => @http_port,
|
376
|
+
:Logger => WEBrick::Log.new(
|
377
|
+
nil, WEBrick::BasicLog::WARN),
|
378
|
+
:AccessLog => [])
|
379
|
+
# Use garbage for the submit and now-playing URLs.
|
380
|
+
s.mount("/handshake", AudioscrobblerHandshakeServlet, @handshake_status,
|
381
|
+
"username", "password", "sessionid",
|
382
|
+
"hch094h09h9 htnhstn", # submit
|
383
|
+
"gcrlhc g g890") # now-playing
|
384
|
+
trap("INT") { s.shutdown }
|
385
|
+
s.start
|
386
|
+
end
|
387
|
+
|
388
|
+
a = Audioscrobbler.new("username", "password")
|
389
|
+
a.client = "tst"
|
390
|
+
a.version = "1.1"
|
391
|
+
a.handshake_url = "http://127.0.0.1:#@http_port/handshake"
|
392
|
+
a.verbose = false
|
393
|
+
a.start_submitter_thread
|
394
|
+
|
395
|
+
assert(!a.report_now_playing('artist', 'title', 100, 'album', 'mbid', 1))
|
396
|
+
end # test_broken_url
|
362
397
|
end # TestAudioscrobbler
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.3
|
|
3
3
|
specification_version: 1
|
4
4
|
name: audioscrobbler
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.0
|
7
|
-
date: 2007-
|
6
|
+
version: 0.1.0
|
7
|
+
date: 2007-10-11 00:00:00 -07:00
|
8
8
|
summary: Library to submit music playlists to Last.fm
|
9
9
|
require_paths:
|
10
10
|
- lib
|