#!/usr/bin/perl # albumart.pl use XML::Amazon; use MP3::Info; use Data::Dumper; # DEBUG use strict; # no strict 'refs'; # put your own amazon API details below my $amazon = XML::Amazon->new(token => 'GETYOUROWN', associate => 'webprogramminboo', locale => 'uk'); # get an mp3 file from current dir opendir(CHDIR,'.'); my @mp3files = grep { /\.mp3$/ } readdir(CHDIR); closedir(CHDIR); my $mp3 = new MP3::Info $mp3files[0]; #die Dumper($mp3); my $keywords = $mp3->{ARTIST} . ' ' . $mp3->{ALBUM}; #die $keywords; my $items; $items = $amazon->search(keywords => $keywords, type => 'Music'); if (!defined($items) || !exists($items->{collection})) { die "No search results found"; } #die Dumper($items); my $count = 0; foreach my $item ($items->collection) { # skip no image results next unless ($item->image('m') =~ /\w/); $count++; # get artist(s) string my $artists = ($#{$item->{artists}} > 0) ? join ', ', @{$item->{artists}} : $item->{artists}->[0]; print sprintf("%3d ", $count); print $artists . " : " . $item->title . "\n"; } print "\nPlease choose an item (1..$count): "; my $chosen = ; chomp($chosen); die "Invalid selection" unless ($chosen > 0 && $chosen <= $count); #print "---" . Dumper($items->{collection}->[1]); #print "REF: " . ref($items->collection) . "\n"; print $items->{collection}->[$chosen-1]->image('m') . "\n";