Skip to content

Instantly share code, notes, and snippets.

@sharifulin
Created November 24, 2010 16:47
Show Gist options
  • Save sharifulin/713964 to your computer and use it in GitHub Desktop.
Save sharifulin/713964 to your computer and use it in GitHub Desktop.
Get images from Last.fm API
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