12 my $ua = LWP::UserAgent->new;
13 push(@LWP::Protocol::http::EXTRA_SOCK_OPTS, SendTE => 0);
14 $ua->agent('Dalvik/1.2.0 (Linux; U; Android Froyo Build/MASTER)');
16 my $requestid = recognize($ua, $ARGV[0]);
17 lookup($ua, $requestid);
20 my ($ua, $filename) = @_;
24 $amr = `cat $filename`;
28 language => make_part('en_US'),
29 service => make_part('cn=CH,cn=V3,cn=SmartClub,cn=ShazamiD,cn=services'),
30 applicationIdentifier => make_encrypted_string('ShazamId_SmartPhone_Gamma__1.2'),
31 deviceId => make_encrypted_string('1234567812345678'),
32 deviceModel => make_encrypted_string('Nexus_One'),
33 userAgent => make_encrypted_string('Mozilla/5.0_(Linux;_U;_Android_1.0;_en-us;_generic)_AppleWebKit/525.10+_(KHTML,_like_Gecko)_Version/3.0.4_Mobile_Safari/523.12.2'),
34 tagDate => make_encrypted_string(POSIX::strftime("%Y-%m-%dT%H:%M:%S", localtime)),
35 cryptToken => make_encrypted_string('A220B36F'),
36 sample => make_encrypted_part($amr, 'janet.3gp.amr', 'application/octet-stream'),
40 'http://goog.shazamid.com/orbit/DoRecognition1',
42 'content-language' => 'en_US',
43 'Content_Type' => 'multipart/form-data; boundary=A3r_ISAAC_eQeY2Bh');
45 if (!$res->is_success) {
46 die $res->status_line;
49 my $parser = XML::DOM::Parser->new;
50 my $doc = $parser->parse($res->content);
51 my $ids = $doc->getElementsByTagName("requestId");
52 if ($ids->getLength == 0) {
53 print "Didn't recognize song\n";
56 return $ids->item(0)->getAttribute('id');
60 my ($ua, $requestid) = @_;
63 language => make_part('en_US'),
64 service => make_part('cn=CH,cn=V3,cn=SmartClub,cn=ShazamiD,cn=services'),
65 applicationIdentifier => make_encrypted_string('ShazamId_SmartPhone_Gamma__1.2'),
66 deviceId => make_encrypted_string('1234567812345678'),
67 deviceModel => make_encrypted_string('Nexus_One'),
68 userAgent => make_encrypted_string('Mozilla/5.0_(Linux;_U;_Android_1.0;_en-us;_generic)_AppleWebKit/525.10+_(KHTML,_like_Gecko)_Version/3.0.4_Mobile_Safari/523.12.2'),
69 requestId => make_encrypted_string($requestid),
70 coverartSize => make_encrypted_string('304'),
71 artistartX => make_encrypted_string('81'),
72 artistartY => make_encrypted_string('0'),
73 cryptToken => make_encrypted_string('A220B36F'),
77 'http://goog.shazamid.com/orbit/RequestResults1',
79 'content-language' => 'en_US',
80 'Content_Type' => 'multipart/form-data; boundary=A3r_ISAAC_eQeY2Bh');
82 if (!$res->is_success) {
83 die $res->status_line;
90 my ($content, $filename, $mime_type) = @_;
91 if (defined($mime_type)) {
92 return [ undef, $filename, 'Content' => $content, 'Content-Type' => $mime_type ];
94 return [ undef, $filename, 'Content' => $content ];
98 sub make_encrypted_string {
99 my ($content, $filename, $mime_type) = @_;
100 if (length($content) % 8 == 0) {
101 $content .= "\0\0\0\0\0\0\0\0";
103 my $enc = '#0x' . join("", map { sprintf "%02X", $_ } (unpack("W*", encrypt($content))));
104 return make_part($enc, $filename, $mime_type);
107 sub make_encrypted_part {
108 my ($content, $filename, $mime_type) = @_;
109 my $enc = encrypt($content);
110 return make_part($enc, $filename, $mime_type);
115 my $blocks = (length($content) + 7) / 8;
119 my $pid = IPC::Open2::open2(\*CHLD_OUT, \*CHLD_IN, './encrypt-ice');
120 for my $i (0..($blocks-1)) {
121 my $block = substr($content, 8*$i, 8);
122 print CHLD_IN $block;