<?xml version="1.0" encoding="UTF-8"?>
<essay xml:lang="en" version="5.0" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:gal="http://norman.walsh.name/rdf/gallery#" xmlns:foaf="http://xmlns.com/foaf/0.1/">
<info>
    
    
    
    
    
    
    
    
    
    
    
    
    
<title>Cover art</title><biblioid class="uri">http://norman.walsh.name/2008/04/15/coverArt</biblioid>
<volumenum>11</volumenum>
<issuenum>38</issuenum>
<pubdate>2008-04-15T15:32:40-04:00</pubdate>
<author>
      <personname>
<firstname>Norman</firstname>
	<surname>Walsh</surname>
</personname>
    </author>
<copyright>
      <year>2008</year>
      <holder>Norman Walsh</holder>
    </copyright>
<abstract>
<para>Using the Amazon search API as a quick-and-dirty way to find
album covers.</para>
</abstract>
<dc:subject rdf:resource="http://norman.walsh.name/knows/taxonomy#Music"/>
<dc:subject rdf:resource="http://norman.walsh.name/knows/taxonomy#Programming"/>
<dc:subject rdf:resource="http://norman.walsh.name/knows/taxonomy#SelfReference"/>
</info>

<para xml:id="p1">I recently discovered that album cover art can be
embedded in MP3 files (using the <wikipedia page="ID3">ID3v2</wikipedia>
<literal>APIC</literal> tag). I wouldn't much care
except that I've also got an iTunes extension
(<link xlink:href="http://coversutra.com/">CoverSutra</link>) that will
display that art when a song is playing.</para>

<para xml:id="p2">That's kind of cool, but I've got several hundred ripped albums
with no cover art. I'm not scanning it all myself!</para>

<para xml:id="p3">A few web searches for cover art were enough to convince me that
Amazon is a good place to get it. And they have a search API, don't
they?</para>

<para xml:id="p4">After a quick trip to <wikipedia>CPAN</wikipedia>, I had a shell
script that would grab covers. One of my <wikipedia>Twitter</wikipedia>
followers
<link xlink:href="http://twitter.com/jurjanpaul/statuses/787247647">asked</link>
to
see it, so here
<link xlink:href="examples/getcover.pl">it</link> is:</para>

<programlisting>
    <inlinemediaobject>
<textobject>
<textdata fileref="/2008/04/15/examples/getcover.pl"/>
</textobject>
</inlinemediaobject>
  </programlisting>

<para xml:id="p5">So, for example:</para>

<screen>perl getcover.pl -a "flogging molly" -k "within mile home"</screen>

<para xml:id="p6">returns the cover for the Flogging Molly album
<citetitle>Within a Mile of Home</citetitle>.</para>

<para xml:id="p7">It blindly assumes that the first match is the right one, it
unceremoniously writes the cover to
<filename>/tmp/cover.jpg</filename>, and it assumes that
<command>open</command> will display it. Oh, and it won't work until
you replace “<literal>YOUR-AMAZON-KEY</literal>” with, well, your
Amazon key, naturally.</para>

<para xml:id="p8">Still it seems to have done a reasonable job on 350 or so albums.</para>

<para xml:id="p9">Now my “rip for iTunes” script embeds cover art when it's available.
And I get pretty pictures on my desktop. Sweet.</para>

</essay>

