Created
June 19, 2010 08:17
-
-
Save xaicron/444702 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use LWP::Simple qw/is_success getstore/; | |
use Getopt::Long qw/GetOptions/; | |
GetOptions( | |
'a|asin=s' => \my $asin, | |
'o|output=s' => \my $out, | |
's|seq=i' => \my $seq, | |
'h|help' => \my $help, | |
) or help(); | |
help() if $help or not ($asin || $ARGV[0]); | |
main: { | |
$asin = find_asin($asin || $ARGV[0]); | |
$seq ||= 1; | |
my $file_name = sprintf '%s.%02d._SCRMZZZZZZ_.jpg', $asin, $seq; | |
my $image_url = 'http://z2-ec2.images-amazon.com/images/P/' . $file_name; | |
$out ||= $file_name; | |
print "--> $image_url getting...\n"; | |
is_success getstore $image_url, $out or die $LWP::Simple::ua->status_line; | |
print "done.\n"; | |
} | |
sub find_asin { | |
my $asin = shift; | |
$asin =~ s{http://(?:www\.)?amazon\.(?:co\.jp|com)/gp/product/images/([^/]+)/.*}{$1}; | |
return $asin; | |
} | |
sub help { | |
print <<END_OF_HELP; | |
amazon_jacket.pl - Save amazon jacket image. | |
Usage: amazon_jacket.pl [options] [--asin] ASIN | |
Options: | |
-a, --asin ASIN | |
-o, --output Output filename | |
-s, --seq Zoom image sequence. default 1. | |
Example: | |
amazon_jacket.pl -a B003EVW708 -o nori.jpg | |
END_OF_HELP | |
exit 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment