• For those of you who have a license for Brandon Fuller’s NowPlaying hack for iTunes, here’s a small snippet of code which you can integrate directly into your sidebar, header or the like. The function itself would ideally be placed in your functions.php file, that way you can call upon the get_itunes() function from any page.

    NowPlaying automatically exports an XML file containing things such as a URI for album artwork, the album name, date, song title etc. and is capable of uploading the XML file automatically to your webserver if you run WordPress on a separate server.

    I don’t know about you guys, but I have a small obsession with letting people know what I am listening to. The license for the plugin is about ten bux, so IMO, it’s worth it.

    This Snippet aught to go into functions.php :

    function get_itunes($tag)
    {
    $np_xml = 'Enter Your XML URI Here!';
    $xml_parser = xml_parser_create();
    
    if ( is_file( $np_xml ) )
    {
       xml_parse_into_struct( $xml_parser, file_get_contents($np_xml), $vals, $index );
       xml_parser_free( $xml_parser );
    
       if ( $vals[ $index["NOW_PLAYING"][0] ]["attributes"]["PLAYING"] == 1 )
       {
    		parse_str($vals[$index["URLAPPLE"][0]]["value"],$tmp);
    		$vals[$index["URLAPPLE"][0]]["value"]=rawurldecode($tmp["amp;RD_PARM1"]);
    		return htmlentities($vals[ $index[$tag][0] ]["value"],ENT_QUOTES,'UTF-8');
       }
       else
       {
          return false;
       }
    }
    }

    You can call the function with the following tags, one at a time:

    TITLE
    ARTIST
    ALBUM
    GENRE
    KIND
    TRACK
    NUMTRACKS
    YEAR
    COMMENTS
    TIME
    BITRATE
    RATING
    DISC
    NUMDISCS
    PLAYCOUNT
    COMPILATION
    URLAMAZON
    URLAPPLE
    IMAGESMALL
    IMAGE
    IMAGELARGE
    COMPOSER
    GROUPING
    FILE
    ARTWORKID

    For an example, take a look at my sidebar at http://www.joshblake.net. And for the link to NowPlaying, take a look here: http://brandon.fuller.name/archives/hacks/nowplaying/

    Josh

Viewing 1 replies (of 1 total)
  • That does seem cool, Josh, but I wonder why you and Brandon don’t just use LastFM? Brandon kvetched that he has to write a new plugin to display his now-playing when he changed from Windows Media to iTunes. If you use LastFM, it scrobbles from both your WMP, iTunes, and WinAmp — so even if you switch around, it’s all noted.

    Perhaps LastFM’s sidebar display options are less flexible in some ways, but they give you a rotating flash “quilt” showing your favorite artists, or recent listens, several options — and so easy to pop their code into your WP template / sidebar.

    Just curious the difference of the plugin?

Viewing 1 replies (of 1 total)

The topic ‘NowPlaying iTunes Integration’ is closed to new replies.