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

NetRyder

Tech Junkie
Joined
Apr 19, 2002
Messages
13,256
#1
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'); ?>
 

NetRyder

Tech Junkie
Joined
Apr 19, 2002
Messages
13,256
#2
Feedback and comments are welcome. Also feel free to post any problems you might have in this thread. :)
 

NetRyder

Tech Junkie
Joined
Apr 19, 2002
Messages
13,256
#8
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.
 

DngrsDrrn

OSNN One Post Wonder
Joined
Mar 11, 2004
Messages
1
#9
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.
 

Members online

No members online now.

Latest posts

Latest profile posts

Perris Calderon wrote on Electronic Punk's profile.
Ep, glad to see you come back and tidy up...did want to ask a one day favor, I want to enhance my resume , was hoping you could make me administrator for a day, if so, take me right off since I won't be here to do anything, and don't know the slightest about the board, but it would be nice putting "served administrator osnn", if can do, THANKS

Been running around Quora lately, luv it there https://tinyurl.com/ycpxl
Electronic Punk wrote on Perris Calderon's profile.
All good still mate?
Hello, is there anybody in there? Just nod if you can hear me ...
Xie
What a long strange trip it's been. =)

Forum statistics

Threads
62,010
Messages
673,471
Members
89,032
Latest member
jamesjacob