Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

enabling puid lookups

  • Loading branch information...
commit 9e633ce2847b5e0dd1872426f40dff4338ba16aa 1 parent 8836d5b
@tenderlove authored
View
1  lib/earworm.rb
@@ -2,6 +2,7 @@
require 'tempfile'
require 'earworm_lib'
require 'earworm/track'
+require 'earworm/puid'
require 'earworm/fingerprint'
require 'earworm/client'
require 'rexml/document'
View
8 lib/earworm/client.rb
@@ -15,6 +15,14 @@ def identify(options = {})
'enc' => '',
}.merge(Fingerprint.new(options[:file]).to_hash)
end
+ if options.key?(:puid)
+ post_opts = {
+ 'cid' => @client_id,
+ 'cvr' => "Earworm #{VERSION}",
+ 'rmd' => 1,
+ 'enc' => '',
+ }.merge(PUID.new(options[:puid]).to_hash)
+ end
xml = Net::HTTP.post_form(URI.parse(URL), post_opts).body
parser = REXML::Parsers::PullParser.new(xml)
track = Track.new
View
21 lib/earworm/puid.rb
@@ -0,0 +1,21 @@
+module Earworm
+ class PUID
+ def initialize(puid)
+ @puid = puid
+ end
+
+ def to_hash
+ {
+ 'puid' => @puid,
+ 'art' => 'unknown',
+ 'ttl' => 'unknown',
+ 'alb' => 'unknown',
+ 'tnm' => 0,
+ 'gnr' => 'unknown',
+ 'yrr' => 0,
+ }
+ end
+
+ def to_s; @puid; end
+ end
+end
View
17 test/test_earworm.rb
@@ -33,13 +33,12 @@ def test_identify_file
assert info.puid_list.length > 0
end
- #def test_idenfity_puid
- # ew = Earworm.new(@key)
- # info = ew.identify(:puid => 'f39d4c68-ab2d-5067-9a1a-c6b45a367906')
- # assert info
- # assert info.artist_name
- # assert info.title
- # assert info.puid_list.length > 0
- # p info
- #end
+ def test_idenfity_puid
+ ew = Earworm::Client.new(@key)
+ info = ew.identify(:puid => 'f39d4c68-ab2d-5067-9a1a-c6b45a367906')
+ assert info
+ assert info.artist_name
+ assert info.title
+ assert info.puid_list.length > 0
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.