2 # get_coverart downloads coverart, and is released
3 # under the terms of the GPL version 2, or any later version, at your
4 # option. See the file README and COPYING for more information.
5 # Copyright 2011 by Don Armstrong <don@donarmstrong.com>.
16 get_coverart -- download coverart
20 get_coverart --asin B000NIIUX8 --cover cover.jpg [options]
23 --asin Amazon image ID
24 --cover file name to save cover to
25 --debug, -d debugging level (Default 0)
26 --help, -h display this help
27 --man, -m display manual
35 Debug verbosity. (Default 0)
39 Display brief usage information.
49 get_coverart --asin B000NIIUX8 --cover cover.jpg
50 get_coverart --asin B000NIIUX8 > cover.jpg
62 my %options = (debug => 0,
70 'debug|d+','help|h|?','man|m');
72 pod2usage() if $options{help};
73 pod2usage({verbose=>2}) if $options{man};
75 $DEBUG = $options{debug};
78 if (not exists $options{asin}) {
79 push @USAGE_ERRORS,"You must give an ASIN.";
82 pod2usage(join("\n",@USAGE_ERRORS)) if @USAGE_ERRORS;
86 if (exists $options{cover}) {
87 $wfh = IO::File->new($options{cover},O_WRONLY|O_CREAT|O_EXCL) or die "Unable to create file: $options{cover}: $!";
90 my $m = WWW::Mechanize->new();
92 mm_get($m,"http://www.amazon.com/gp/product/$options{asin}");
93 if ($m->status() != 200) {
94 print STDERR "Unable to get product for asin $options{asin}";
97 my $content = $m->content();
98 my $parser = HTML::TokeParser->new(\$content);
100 while (my $token = $parser->get_tag('img')) {
101 if (exists $token->[1]{id} and $token->[1]{id} eq 'prodImage') {
102 $image = $token->[1]{src};
106 print {$wfh} $m->content;
115 $return = $m->get($url);
118 ($rerun-- > 0) and sleep 5);