Created
November 24, 2010 16:47
-
-
Save sharifulin/713964 to your computer and use it in GitHub Desktop.
Get images from Last.fm API
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
my $imgs = eval { $net->request( | |
method => 'artist.getImages', | |
artist => $artist, | |
)->{images} }; | |
unless ($@) { | |
if (my @imgs = | |
map { | |
my $h = { | |
map { $_->{name} => $_->{'#text'} } | |
@{ $_->{sizes}->{size} || [] } | |
}; | |
$h->{medium} ? $h : (); | |
} | |
ref $imgs->{image} eq 'ARRAY' ? @{$imgs->{image}} : $imgs->{image} | |
) { | |
$img = $imgs[0]->{largesquare}; | |
say 'image ' . $DB->query( | |
'insert ignore into artist_media (artist_id, type, url, preview, created) ' . $DB->values( | |
map { [ $a->{id}, 'image', @$_{qw(original largesquare)}, Util::time2iso ] } | |
@imgs | |
) | |
); | |
} | |
} | |
else { | |
warn("ERROR $_->{name} : $@"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment