Today’s iTunes Music Store Hack: downloading the text that accompanies an iTunes Music Store album. The text will generally include the album description and user reviews from the main album page. If you’re a Unix weenie, you can think of this script as “strings” for the iTMS.

As always, this is a US music store hack only. If someone can help me figure out how to request listings from another storefront, please let me know.

I’ve taken some of Andy Lester’s superb coding examples to heart here, but as always please feel free to suggest improvements. Enjoy.

#! /usr/bin/perl
# US Only, Erica Sadun,  14 April 2006
# Return the text for an album
# e.g. ./getAlbumText.pl 140812843
# or   ./getAlbumText.pl 145852049

use warnings;
use strict;

if ($#ARGV < 0) {die "Usage: $0 AlbumID (StoreID)\n";}

my $albumid = $ARGV[0];
my $url = "http://ax.phobos.apple.com.edgesuite.net/WebObjects/MZStore.woa/wa/com.apple.jingle.app.store.DirectAction/viewAlbum?id=$albumid";

my $doit = qq{curl -s "$url" | gunzip};
my $riz = `$doit`;
my @riz = split("\n", $riz);

foreach my $item (grep(/TextView/ , @riz))
{
  $item =~ s/<[^>]*>//g;
  $item =~ s/^ *//;
  if ($item ne "") {print $item, "\n";}
}

Download a copy of the code here.