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

NetRyder

Tech Junkie
Joined
19 Apr 2002
Messages
13,256
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'); ?>
 
Feedback and comments are welcome. Also feel free to post any problems you might have in this thread. :)
 
I am looking in ways if it's possible to let my script work with it. Shouldn't be too hard.
 
Does anyone have a screenhot or an actual version of the finished product?
 
just to inform, samurize added winamp 5 and itunes support :)
preety neat
 
ViperSnake said:
Does anyone have a screenhot or an actual version of the finished product?

Just picture a line of plain text that says "iTunes: <Name of song playing>"
That's what the screenshot would look like.
 
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.
 
They should make some other software like iMovies now or something like that. :D
 

Members online

No members online now.

Latest profile posts

Also Hi EP and people. I found this place again while looking through a oooollllllldddd backup. I have filled over 10TB and was looking at my collection of antiques. Any bids on the 500Mhz Win 95 fix?
Any of the SP crew still out there?
Xie wrote on Electronic Punk's profile.
Impressed you have kept this alive this long EP! So many sites have come and gone. :(

Just did some crude math and I apparently joined almost 18yrs ago, how is that possible???
hello peeps... is been some time since i last came here.
Electronic Punk wrote on Sazar's profile.
Rest in peace my friend, been trying to find you and finally did in the worst way imaginable.

Forum statistics

Threads
62,015
Messages
673,494
Members
5,621
Latest member
naeemsafi
Back