I hate having to use the iTunes interface directly. It’s slow. It’s annoying. It’s not macro-friendly.

So last night I decided to throw together some code to grab featured items from the iTunes Music Store and show them all together in Safari. From the command line. With working links, of course.

0604iTunesPicscaled.tiff

This way, I can see what’s there, avoid iTunes and search visually for the Singles of the Week, and any other items marked with the yellow FREE triangle. Once found, I click ‘em up right into the store.

Here it is. It only works with the US Store right now. Can anyone tell me how to directly get the feeds from other countries? Got any fixes, improvements or suggestions? What do you think of this utility? Let me know in the comments.

#! /usr/bin/perl
# US Only, Erica Sadun,  4 April 2006

@whichones = (20, 50000024, 2, 4, 5, 3, 6, 17, 7, 10, 18, 22, 11, 12, 14, 15, 24, 21, 16, 32, 23, 19);
%genrenames = (20, "Alternative", 50000024, "Audiobooks", 2, "Blues", 4, "Children's Music", 5, "Classical", 3, "Comedy", 6, "Country", 17, "Dance", 7, "Electronic", 10, "Folk", 18, "Hip-Hop/Rap", 22, "Inspirational", 11, "Jazz", 12, "Latin", 14, "Pop", 15, "R&B/Soul", 24, "Reggae", 21, "Rock", 16, "Soundtrack", 32, "TV Shows", 23, "Vocal", 19, "World");
# 31, "Music Videos", 26, "Podcasts",
@riz = ();

# For each genre, grab the tags
foreach $item (@whichones)
  {getGenre($item); push(@riz, "<br />");  print ".";}
print "done\n";

# Store into a Safari-readable file
open(XFILE, ">/tmp/itunesGenreRiz.html");
foreach $item (@riz) {print XFILE $item, "\n";}
close(XFILE);

# Open in Safari
`open /tmp/itunesGenreRiz.html`;

sub getGenre()
{
  my $genreid = shift;
  my $doit = "curl -s \"http://ax.phobos.apple.com.edgesuite.net/WebObjects/MZStore.woa/wa/com.apple.jingle.app.store.DirectAction/viewGenre?genreId=$genreid\" | gunzip | grep \"a1.phobos.apple.com\" | grep -v x53 | grep GotoURL | grep draggingURL";

  # Fetch Genre list from iTMS
  my $gn = %genrenames->{$genreid};
  push(@riz, "<h3>".$gn."</h3>");
  my $genriz = `$doit`;
  my @rizray = split("\n", $genriz);
  foreach my $item (@rizray)
  {
     $item =~ s/.*<GotoURL.*draggingURL=/<a href=/;
     $item =~ s/" url=.*http://a1/"><img src="http://a1/;
     $item =~ s/</PictureView.*/</a>/;
     push(@riz, $item);
  }
}