Now Playing: An iTunes for Mac OS X Plugin

Softpedia

Current version is 2.3.0.0 released on 2010-02-07

Other Editions: iTunes for Windows | Winamp | Windows Media Player | Yahoo! Music Engine

Contents

Overview

I seem to have some fixation on publishing the song I am currently listening to on my blog. The end result is something that could look like this on your web site!

iTunes allow you to create plugins that can do various tasks for you. The Now Playing plugin monitors the song you are listening to and publishes the data in various ways:

  1. Creates a XML file with information on that song. A file called now_playing.xml is created in your iTunes Plug-ins directory.
  2. The plugin also offers you the ability to upload that file to a server of your choosing after it is updated.
  3. Create a ping with the song information.

The idea is that you publish the XML up to your web server and then through some scripting magic, you can display your currently playing song or your recently played tracks. To make your web site more interactive, the plugin also retrieves the following information for you to use:

  1. URL of the album image cover art from Amazon.com (if found).
  2. Link to the Amazon.com product page for the CD (if found).
  3. Link to the Apple iTunes Music Store product page with the song highlighted within iTunes (if found).

Installation Instructions

  1. Run the installer.
  2. Start iTunes.
  3. The first time you start iTunes with the plugin installed, the configuration screen will come up. If you don’t see it or you miss it, you can reopen the configuration screen at any time by selecting Now Playing as the Visualizer. In the latest version of iTunes, you can do this on the View, then Visualizer menu. Then return to that menu and choose the Options item.

Configuration

About: Get version information.

Now Playing Options - About

Options: Configure a few basic options for the plugin.

  • Publish Stop: If you want the plugin to publish a message when you stop playing music.
  • Artwork: If you want the artwork to be exported locally, check this option. The files will be placed in the same directory as the XML file configured on the XML tab. This option is independent of the artwork setting on the upload tab. Only check this if you want the image files to be saved on your computer.
  • Artwork Width: Specify the the width of any exported images (both local and uploaded) if the cover art image is wider than the given value. Setting the value to 0 will cause no resizing to occur. The height is calculated based on the width-height ratio of the original image.
  • Logging: If you are not getting the results you expect from the plugin, you may want to enable logging. The log will be generated in the Mac OS X Console.app. If you contact me about an issue, I will be more likely to solve your issue if you send the log file with the event captured at the debug log level.
Now Playing Options - General

XML: Configure some options for the XML file that will be generated.

  • Output File: Specify the location of the file that is created when the song changes. This file will be uploaded to your FTP server if configured to do so.
  • Wrap XML tag values with CDATA: Some song properties have odd characters inside of them and you may need to safely encode the XML depending on your parser.
  • Playlist Length: Enter the total number of songs that you want to publish in the XML file.
  • Encoding: Select which type of encoding your want for the XML. UTF-8 is the recommended choice.
Now Playing Options - XML

Upload: Enter your server information to configure FTP or SFTP. Be sure that you have permission on your server to upload the file.

  • Protocol: Choose whether you want to upload your Now Playing files via FTP or SFTP.
  • Hostname: The name or IP address of your server.
  • Username: Your server user login.
  • Password: Your server user password.
  • Artwork: The plugin will export the album artwork for the current track and upload it along with the XML if checked. The image will be resized to be a maximum width of that specified on the Options tab. This option is independent of the artwork export setting on the Options tab.
  • Reset Export Cache: The plugin keeps track of the last time it uploaded a piece of album artwork. It will then skip uploading that same piece of artwork again. To clear the cache, you can press this button. You would do this if you are changing web servers or just want to refresh your artwork.
Now Playing Options - Upload

Ping: The plugin can send an HTTP POST request when the song changes. The request is sent after the upload of the XML file, if configured. Each of the XML tag names for the track are posted as fields.

  • URL: Enter a URL that will receive the POST request.
  • Extra Info: Enter a value that will be sent as a HTTP header called X-NowPlaying. You can use this to set a secret value that your script looks for to prevent unauthorized use.
Now Playing Options - Ping

Twitter: The plugin can post a tweet with what you are listening to.

  • Enabled: Turn the feature on or off.
  • Rate Limit: Enter the minimum number of minutes between tweets. This is used to comply with Twitter’s rate limiting. Also helps so you don’t annoy the crap out of your followers with a tweet for every track you play.
  • Message: Enter the text that you want to post for each new song that plays. You can use a combination of the tags listed below the field for the song data. The text will be substituted and should be less than 140 characters (Twitter limit).
  • Setup: You need to complete the three phase setup to add and authorize the plugin to work with Twitter. 1) Press Authorize to launch a web browser and give Now Playing access. 2) You will get a PIN from Twitter that you enter in the field. 3) Verify the PIN by pressing Verify. 4) You should see your Twitter name appear there with an option to reset if you want to start over or remove the association.
Now Playing Options - Twitter

Facebook: The plugin can update your Facebook status or news feed with what you are listening to.

  • Enabled: Turn the feature on or off.
  • Rate Limit: Enter the minimum number of minutes between posts. This is used to comply with Facebook’s rate limiting. Also helps so you don’t annoy the crap out of your friends with a post for every track you play.
  • Post To: Choose to post a status message or a news feed item. News feed items will display album artwork from Amazon, if available.
  • Message: Enter the text that you want to post for each new song that plays. You can use a combination of the tags listed below the field for the song data.
  • Setup: You need to complete the three phase setup to add and authorize the plugin to work with Facebook. Press each of the buttons in sequence and follow the instructions. You should see your Facebook name appear there with an option to reset if you want to start over or remove the association when you have completed the steps.
Now Playing Options - Facebook

Amazon: The plugin will query Amazon.com for additional information about your song, such as a link and the album image cover.

  • Enabled: Turn the lookup on or off.
  • Locale: Choose “us” for Amazon in the US, “ca” for Amazon in Canada, “uk” for Amazon in the United Kingdom, “de” for Amazon in Germany, “fr” for Amazon in France, or “jp” for Amazon in Japan.
  • Associate ID: Amazon allows you to collect referral fees on items sold when users click-through from your site. Enter your associate ID here.
  • ASIN Hint: Check this box if you want the plug-in to assume the value of the track’s grouping field is an Amazon ASIN. Since Amazon’s search is quirky for some albums, you can use this feature to specify the exact album you want to match.
Now Playing Options - Amazon

Apple: The plugin will query Apple’s iTunes Music Store for additional information about your song, such as a link.

  • Enabled: Turn the lookup on or off.
  • Affiliate ID: Want to receive a commission when users click-through and buy songs from your site at the iTunes Music Store? Join the Apple iTunes Affiliate program. Once you join, find out what your ID is by using the LinkShare link generator for any song and extract the ID parameter from the URL generated.
Now Playing Options - Apple

License: If and when you purchase a license, you will enter your registration information on the license tab. Enter the e-mail address you used for the PayPal transaction and the license key I sent you after the purchase.

Now Playing Options - License

Schema

The XML has the following format for a single song playlist. If you configure the playlist for more than 1 entry, there will be multiple song tags.

<?xml version="1.0" encoding="UTF-8"?>

<now_playing playing="1" timestamp="2007-09-08T23:12:46Z">
   <song>
      <title>Faint</title>
      <artist>Linkin Park</artist>
      <album>Meteora</album>
      <genre>Rock</genre>
      <kind>MPEG audio file</kind>
      <track>7</track>
      <numTracks>14</numTracks>
      <year>2003</year>
      <comments>I like it.</comments>
      <time>162</time>
      <bitrate>128</bitrate>
      <rating>4</rating>
      <disc>1</disc>
      <numDiscs>1</numDiscs>
      <playCount>6</playCount>
      <composer></composer>
      <grouping></grouping>
      <file>faint.mp3</file>
      <urlAmazon>http://www.amazon.com/...</url>
      <imageSmall>http://images.amazon.com/...jpg</imageSmall>
      <image>http://images.amazon.com/...jpg</image>
      <imageLarge>http://images.amazon.com/...jpg</imageLarge>
      <file>faint.mp3</file>
      <artworkID>41b25792e5231986d48be16437f0edeb</artworkID>
   </song>
</now_playing>

Frequently Asked Questions

  • Q: I lost my registration key. Can you resend it?
    A: You can retrieve it yourself here.

  • Q: FTP isn’t working. How can I turn on passive mode?
    A: Passive FTP is configured through the Mac’s System Preferences applet. Go there, then pick the Network icon. Choose the connection you are using and then go to the Proxies tab. Near the bottom you will see a checkbox that indicates whether you want passive FTP or not.

  • Q: How do I uninstall the plugin?
    A: Browse to /Library/iTunes/iTunes Plug-ins and delete Now Playing.bundle. A lot of people mistakenly look in their own personal user Library folder. It is not in there! It is in the system Library folder which can be found at the root of your hard drive.

  • Q: How can I get back to the configuration screen?
    A: To configure any plugin, you must select it as the Visualizer. In the latest version of iTunes, you can do this on the View, then Visualizer menu. Then return to that menu and choose the Options item.

  • Q: If I turn the visualizer off, will the plugin still run?
    A: Yes.

  • Q: Why does part of my album cover get cut off in the Visualizer?
    A: This happens because you have “Small” mode selected. Change to “Large” on the Visualizer menu.

  • Q: Why aren’t my Amazon or Apple links populated in the XML?
    A: It is because the Amazon or Apple search engine cannot find the album. These engines can be picky at times.

  • Q: Can you show me how to parse the XML file on my server?
    A: Sure. This sample will work for a single song or multiple songs.
    <?php
    
    $file = "now_playing.xml";
    $xml_parser = xml_parser_create();
    
    if ( is_file( $file ) )
    {
       $fp = fopen( $file, "r" );
       $data = fread( $fp, filesize( $file ) );
       fclose( $fp );
       xml_parse_into_struct( $xml_parser, $data, $vals, $index );
       xml_parser_free( $xml_parser );
    
       if ( $debug )
       {
          echo "<pre>";
          echo "Index array\n";
          print_r($index);
          echo "\nVals array\n";
          print_r($vals);
          echo "</pre>\n\n";
       }
    
       if ( $vals[ $index["NOW_PLAYING"][0] ]["attributes"]["PLAYING"] == 1 )
       {
          foreach ( $index["TITLE"] as $i => $j )
          {
             $title = $vals[ $index["TITLE"][$i] ]["value"];
    
             if ( strlen( $title ) > 0 )
             {
                $artist = $vals[ $index["ARTIST"][$i] ]["value"];
                $album = $vals[ $index["ALBUM"][$i] ]["value"];
                $genre = $vals[ $index["GENRE"][$i] ]["value"];
                $kind = $vals[ $index["KIND"][$i] ]["value"];
                $track = $vals[ $index["TRACK"][$i] ]["value"];
                $numtracks = $vals[ $index["NUMTRACKS"][$i] ]["value"];
                $year = $vals[$index["YEAR"][$i] ]["value"];
                $comments = $vals[ $index["COMMENTS"][$i] ]["value"];
                $time = $vals[ $index["TIME"][$i] ]["value"];
                $bitrate = $vals[ $index["BITRATE"][$i] ]["value"];
                $urlamazon = $vals[ $index["URLAMAZON"][$i] ]["value"];
                $imagesmallurl = $vals[ $index["IMAGESMALL"][$i] ]["value"];
                $imageurl = $vals[ $index["IMAGE"][$i] ]["value"];
                $imagelargeurl = $vals[ $index["IMAGELARGE"][$i] ]["value"];
                $file = $vals[ $index["FILE"][$i] ]["value"];
                $artworkID = $vals[ $index["ARTWORKID"][$i] ]["value"];
    
                echo "Now Playing is " . $title . " by " . $artist;
             }
          }
       }
       else
       {
          echo "Now Playing is stopped.";
       }
    }
    
    ?>
    
  • Q: I don’t understand all of this PHP stuff but I still want to do all these cool things. Can you help?
    A: Ok, I have zipped up the actual code I use on my own web site. You can download it and use it for your site or as a starter. Please don’t mail me to customize it for you. I don’t have time. So to use this: 1) Take the zip file and extract and place the files on your PHP-enabled web server. 2) Put the images into /images on your server. 3) Insert the following code in the web page that you want to display the music.
    <script type="text/javascript" src="http://yourserver.com/now_playing.php"></script>
    
  • Q: How about a WordPress widget to display the output?
    A: Josh Blake wrote one. Check it out.

Purchase

I have done my fair share of free plugins lately. This one took a little more work so I decided to release it as shareware. So download the plugin and test it out. Make sure it does what you want. Once you are happy, order the licensed version for $15. You will receive a registration key via e-mail once I receive your purchase confirmation from PayPal. Oh yeah — be cool and keep your registration to yourself.

Also, if you would, you can put the Now Playing badge on your web site with a link back to this page. The more people that donate, the more I will be asked to develop new and interesting features that you will be able to take advantage of!

Now Playing

Here is the code for your site:

<div>
   <a href="http://brandon.fuller.name/archives/hacks/nowplaying/">
      <img src="http://brandon.fuller.name/images/now_playing.png" alt="Now Playing" />
   </a>
</div>

Download

Download the current version from the link below. Past versions are not archived.

Download Now Playing for iTunes Installer (125 KB - Universal Binary)
MD5:

Version History

v2.3.0.0 — 2010-02-07
  • Changed Facebook option to publish to status or news feed. You must perform the 1, 2, 3 setup on the configuration page again.
v2.2.0.0 — 2010-02-04
  • Added Twitter support.
v2.1.0.4 — 2010-01-26
  • Overhauled shutdown sequence to prevent reported crashes.
  • Moved comments to DISQUS for better interaction.
v2.1.0.3 — 2009-11-09
  • Apple changed iTunes links again.
v2.1.0.2 — 2009-08-18
  • Amazon began requiring requests to be signed so signatures added.
v2.1.0.1 — 2009-03-31
  • Added SFTP support for stop publish.
  • Added ping support for stop publish.
v2.1.0.0 — 2009-01-26
  • Added SFTP support.
  • Added a check during install if iTunes is running.
v2.0.0.1 — 2009-01-06
  • Fixed artworkID. I broke it in 2.0 with the internationalization.
  • Removed duplicate file tag in XML.
  • Ordered new XML tags in 2.0 to match Windows edition.
v2.0.0.0 — 2008-12-28
  • Upgraded to later version of iTunes API which allows access to additional fields such as grouping, composer, rating, and more. Provides support for international characters in strings!
  • Added ability to use grouping field to hold ASIN value for Amazon lookups.
  • Added a caching mechanism for the upload of artwork to prevent redundant exports.
  • Added a hasAmazon tag for Facebook support so conditional logic can be used in display.
  • Updated the default Facebook message to include the new conditional tag.
  • Fixed Apple search to new URL.
  • Changed install builders because PackageMaker blows.
v1.2.0.0 — 2008-12-25
  • Added Facebook support!
v1.1.2.1 — 2008-02-13
  • Fixed bug that caused plugin to crash iTunes when opening plugin preferences.
v1.1.2.0 — 2007-11-04
  • Fixed bug that caused plugin preferences to go unsaved in Leopard.
v1.1.1.0 — 2007-09-08
  • Added timestamp attribute to XML. Forgot to add this before. Now its the same as Windows editions of the plugin.
v1.1.0.4 — 2007-07-13
  • Now Playing menu item in Visualizer menu was showing strange charactgers in iTunes 7.3 and higher.
v1.1.0.3 — 2007-04-04
  • Reverted AppleScript changes; didn’t help; caused other issues
v1.1.0.2 — 2007-04-01
  • Log level is now saved between runs of iTunes.
  • More logging added for various log levels.
  • Programmatic changes to export artwork script to try and avoid crashes. Crashes seem to be triggered by other plugins, such as OmniGrowl, that all rush to export artwork at the same time.
v1.1.0.1 — 2007-01-14
  • Print empty XML nodes for Amazon and Apple when no data exists. PHP XML processing doesn’t do well with differing number of elements per block.
  • Fixed artwork ID value in XML to use UTF-8 characters before MD5 hashing.
v1.1.0.0 — 2006-12-19
  • Added choice of character encoding for XML.
  • Added UTF-8 character encoding for ping data.
v1.0.0.2 — 2006-09-15
  • Some user interface updates to make options window more dialog-like.
v1.0.0.1 — 2006-09-14
  • Fixed iTunes 7 issue where tracks would not update.
  • Fixed iTunes Music Store links because Apple changed them — again.
  • Updated installer to close iTunes if running on install.
v1.0.0.0 — 2006-08-03
  • Added a weekly software update check for new versions.
v0.2.0.1 — 2006-07-04
  • Fixed crash issue in new ping functionality when Apple or Amazon lookup isn’t enabled.
v0.2.0.0 — 2006-07-01
  • Added Apple lookup.
v0.1.0.0 — 2006-06-28
  • Added ability to set variable length of songs to be stored in XML.
  • Added ability to set custom HTTP header value for ping.
v0.0.2.3 — 2006-03-29
  • Fixed issue where artwork would not export properly with apostrophe in album or artist.
  • Fixed issue where artwork would only export locally into /tmp directory.
v0.0.2.2 — 2006-03-27
  • Fixed issue where iTunes crashes when FTP settings are empty.
v0.0.2.1 — 2006-03-27
  • Fixed issue where local XML file would not be written unless upload is configured.
v0.0.2.0 — 2006-03-25
  • Added locale selection and associate ID to Amazon lookup.
  • Added abilty to export artwork locally.
  • Moved artwork width option to general option.
v0.0.1.0 — 2006-03-09
  • Fixed the publish stop message. Broke it a while back.
  • Confirmed that Intel-based Macs are working!
v0.0.0.9 — 2006-03-07
  • Upgraded project targets to support Intel-based Macs.
v0.0.0.8 — 2006-03-06
  • Added Amazon lookup.
v0.0.0.7 — 2006-02-10
  • Ping added.
v0.0.0.6 — 2006-01-16
  • Publish stop added.
v0.0.0.5 — 2005-12-13
  • Artwork upload added.
v0.0.0.4 — 2005-12-09
  • Fixed crash when FTP settings are empty.
v0.0.0.3 — 2005-12-07
  • Fixed license issue..
v0.0.0.2 — 2005-12-08
  • Fixed crash when computer is offline and FTP is attempted.
v0.0.0.1 — 2005-12-05
  • First relase. More to come.

Contact

For questions, suggestions, bug reports, and anything else, please e-mail brandon@fuller.name or leave a comment. Please be sure to review the FAQ above before asking a question. Requests from those who have donated receive higher priority.

iTunes is a registered trademark of Apple Computer, Inc.

Updated: 2010-02-07 at 10:25 MST in Hacks
Tags: apple facebook itunes nowplaying twitter