[TUTORIAL]: iTunes (Windows) "Now Playing" script

Discussion in 'Windows Desktop Systems' started by NetRyder, Jan 14, 2004.

  1. NetRyder

    NetRyder Tech Junkie Folding Team

    Messages:
    13,256
    Location:
    New York City
    Ever since I switched to iTunes from WMP9, I've missed the ability to display my currently playing song online. The SongWriter plug-in could do this easily for WMP9 (I had a tutorial up for this before we lost our database), but there's no such direct plugin for the Windows version of iTunes yet. I've finally figured out a way to do it...
    "localhost" from the Aqua-Soft forums has recently released a plugin that enables iTunes to dump the details of the currently playing song to a text file on the local disk. This tutorial extends the ability of the plugin, so that you can use it almost like the SongWriter plugin for WMP9, and other such plugins for Winamp etc.

    Your server MUST support PHP in order for this to work

    NOTE: Other plugins that send information to the server directly are able to update the currently playing song realtime on the server. The method in this tutorial does not work the same way. The details of the currently playing song will be updated depending on how often you set XP's Task Scheduler to poll the server. Read on...

    1) Download the iTunes Multi-plugin by localhost from here:
    http://www.aqua-soft.org/board/index.php?showtopic=10678&view=findpost&p=115689
    UnRAR the MPlugin.dll file into your iTunes plugin folder (ex: C:\Program Files\iTunes\plugins)

    2) Open iTunes, right click the titlebar, and select Options. Check the "Create a file in the iTunes folder..." box.
    To test that the plugin works as intended, play any song in your library and look for the file CurrentSong.txt in your iTunes folder. It should contain the details of the song that is playing.

    3) Download RunH from here, and unzip the runh.exe file in your iTunes folder.
    http://www.scripthorizon.com/library/utilities/runh.zip
    The purpose of runh is to hide the command prompt window that pops up when the Task Scheduler runs the batch file that uploads the text file to your server.

    4) You need two more files in your iTunes folder - we'll name them upload.bat and ftp.txt
    Modify them according to the specific details for your server.

    upload.bat
    Code:
    @echo off
    ftp.exe -s:"ftp.txt"
    exit
    
    ftp.txt
    Code:
    o ftp.yourhost.com
    your_username
    your_password
    cd path_to_folder
    ascii
    put C:\"Program Files"\iTunes\CurrentSong.txt
    quit
    
    NOTE: path_to_folder is the name of the folder you want to store the text file in. In my case, for example, it is "public_html"

    5) Now we create a task using XP's Task Scheduler, so that this batch file runs every 5 minutes and uploads the text file to the server. Open Control Panel and double click Scheduled Tasks. Then select "Add Scheduled Task"
    - In the wizard, click Browse and select the runh.exe file you placed in your iTunes folder. Select "Daily" and set the Start Time to whenever you would like the task to start running. I set mine to 8:00 AM. Enter the password for your XP user account when prompted. Check the advanced properties box, and click Finish.
    - Now you should see the advanced configuration dialog box. Change the path in the "Run" box to exactly "C:\Program Files\iTunes\runh.EXE" "upload.bat" (including the quotes)
    - In the Schedule tab, click Advanced, and check "Repeat Task." For the "Every" option select the time intervals at which you want the task to run. This will be the frequency at which the file on your web server will be updated. For the "Until" option, select Time, and set it to the time you want the task to stop. Mine is set to 11:59 PM
    - Hit OK until all the dialog boxes close. This step is now complete.

    6) Create a file called nowplaying.php and add the following lines to it:
    Code:
    <?php
    
    $fname = "CurrentSong.txt";
    $songfile = fopen($fname, "r");
    $artist = fgets($songfile);
    if($artist != " ") {
     $track = fgets($songfile);
     echo "iTunes: ".$artist." - ".$track;
    }
    else
     echo "iTunes: No Song Playing";
    fclose($songfile);
    
    ?>
    
    Upload this file to the same folder on your server that contains CurrentSong.txt

    You're all set. Point your browser to nowplaying.php to see what it looks like. You can now add this to any other page using:
    Code:
    <?php include('nowplaying.php'); ?>
     
  2. NetRyder

    NetRyder Tech Junkie Folding Team

    Messages:
    13,256
    Location:
    New York City
    Feedback and comments are welcome. Also feel free to post any problems you might have in this thread. :)
     
  3. Glaanieboy

    Glaanieboy Moderator

    Messages:
    2,626
    Location:
    The Netherlands
    I am looking in ways if it's possible to let my script work with it. Shouldn't be too hard.
     
  4. NetRyder

    NetRyder Tech Junkie Folding Team

    Messages:
    13,256
    Location:
    New York City
    That would be a nice addition to it :)
     
  5. SPeedY_B

    SPeedY_B I may actually be insane.

    Messages:
    15,800
    Location:
    Midlands, England
    mmmmmmmmm, iTunes.
     
  6. Corvette

    Corvette Sauske!

    Messages:
    761
    Does anyone have a screenhot or an actual version of the finished product?
     
  7. MeFo

    MeFo el mafioso

    Messages:
    73
    Location:
    Santiago, Chile
    just to inform, samurize added winamp 5 and itunes support :)
    preety neat
     
  8. NetRyder

    NetRyder Tech Junkie Folding Team

    Messages:
    13,256
    Location:
    New York City
    Just picture a line of plain text that says "iTunes: <Name of song playing>"
    That's what the screenshot would look like.
     
  9. DngrsDrrn

    DngrsDrrn OSNN One Post Wonder

    Messages:
    1
    You could always just go over to www.listen-to.com where you could have your very own custom image to show what you're listening to at all times. It supports winamp, itunes, xmms, and other players.
     
  10. Glaanieboy

    Glaanieboy Moderator

    Messages:
    2,626
    Location:
    The Netherlands
  11. Hsn

    Hsn King

    Messages:
    1,082
    Location:
    Calgary, Canada
    They should make some other software like iMovies now or something like that. :D
     
  12. Geffy

    Geffy Moderator Folding Team

    Messages:
    7,805
    Location:
    United Kingdom
    Give it time I am sure it could soon look better ;)