1: # Takes raw cuecat output and looks up the barcode scanned
2: # through upcdatabase.com
3: # I DID NOT WRITE THE SECTION THAT DOES THE DECODING
4: # and at the moment the name of the person who did escapes
5: # me
6: use LWP::Simple;
7: $seq = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+-';
8:
9: sub decode
10: {
11: ($encoded) = @_;
12: @s = map { index($seq,$_); } split(//,$encoded);
13: $l = ($#s+1) % 4;
14: if ($l)
15: {
16: if ($l == 1)
17: {
18: print "Error!";
19: return;
20: }
21: $l = 4-$l;
22: $#s += $l;
23: }
24: $r = '';
25: while ($#s >= 0)
26: {
27: $n = (($s[0] << 6 | $s[1]) << 6 | $s[2]) << 6 | $s[3];
28: $r .=chr(($n >> 16) ^ 67) .
29: chr(($n >> 8 & 255) ^ 67) .
30: chr(($n & 255) ^ 67);
31: @s = @s[4..$#s];
32: }
33: $r = substr($r,0,length($r)-$l);
34: return $r;
35: }
36: chomp($s = <STDIN>);
37: @fields = split(/\./,$s);
38: @results = map(decode($_), @fields[1..$#fields]);
39:
40: $code = $results[2];
41:
42: $upcdata = get("http://www.upcdatabase.com/item.pl?upc=$code");
43:
44: $upcdata =~ s/<(?:[^>'"]*|(['"]).*?\1)*>//gs;
45:
46: $upcdata =~ /Description(.*)\n/;
47:
48: print "\n\n$1\n";
49:
50: $upcdata =~ /Manufacturer(.*)\n/;
51:
52: print "Made by: $1\n";
53:
54: $upcdata =~ /Size\/Weight(.*)\n/;
55:
56: print "Size: $1";