#!/usr/bin/perl # iTunes-Playlist # Version: 0.1 # Author: Victor Ganata # Works Referenced: # - Applescript for extracting playlists by Kimbra Staken # http://www.xmldatabases.org/files/playlistToBlog.txt # - Amazon.com URI syntax by Nelson Minar # http://www.nelson.monkey.org/~nelson/blosxom-plugins/asin20030301.txt # - Google URI syntax by Beni Cherniavsky # http://catb.org/~esr/jargon/jargoogle.html # - iTMS search URI syntax by Michael Hanscom # http://www.djwudi.com/longletter/archives/2003/05/01/linking_to_the_itunes_music_store.php # This script may be distributed under the same license as Perl # Description: # Takes a specified playlist, and creates links to lyrics via Google, to a search of the iTunes Music Store, and to Amazon.com use Mac::AppleScript qw(RunAppleScript); use XML::LibXML; use LWP::Simple; use URI::Escape; #-------Configuration--------# # developer token from amazon.com $dev_token=""; # associate ID from amazon.com $assoc_id="fatoprofugusn-20"; # exact name of playlist in iTunes $playlist_name="Last 5 Songs"; # tags containing entire markup fragment $container_open=qq{}; # tags containing each individual element $wrapper_open=qq{
  • }; $wrapper_close=qq{
  • }; # any additional attributes for tag $link_attr=qq{class="inline"}; #----------------------------# $getplaylist = <new(); $playlist = RunAppleScript($getplaylist); $playlist =~ s/\"(.*)\"/$1/s; print $container_open; while($playlist =~ /^(.*)/mg) { $_ = $1; /(.*?):::(.*?):::(.*?):::(.*?)/; $songname = $1; $artist = $2; $album = $3; $playcount =$4; $songname_escaped=uri_escape($songname); $artist_escaped=uri_escape($artist); $album_escaped=uri_escape($album); print $wrapper_open; print qq{"$songname" by $artist [lyrics][iTMS]}; if ($album) { # warn "Querying Amazon.com for $album"; $query_amazon=get "http://xml.amazon.com/onca/xml?v=1.0&t=webservices-20&dev-t=$dev_token&KeywordSearch=$album_escaped&mode=music&type=lite&page=1&f=xml"; # warn "Query complete"; $amazon_search_results=$parser->parse_string($query_amazon); $product_info=$amazon_search_results->getDocumentElement; @asin_list=$product_info->findnodes('//Asin[position()=1]'); print qq{ from }; if (@asin_list) { $asin=$asin_list[0]->textContent; print qq{"$album"}; } else { print qq{"$album"}; } } print "$wrapper_close"; print "\n"; } print $container_close;