This article provides step-by-step instructions for incorporating XMLSpew into your jukebox. XMLSpew is a bit of PHP script created by Dave Sellers. Thanks, Dave!
XMLSpew lets you add music to your previously created music player without having to rebuild and reupload it. Instead, all you have to do is upload songs to the same folder on your server as your JukeBox files. The script reads your music directory, creates a playlist, and inserts it into your jukebox.xml file. It also prevents the caching of MP3s. Here’s how you use it:
1. Make sure the MP3 files you wish to include in your JukeBox are labeled using this format:
artist - title.mp3
Note: All your songs will automatically be arranged in alphabetical order. If you have a preferred playlist, add a number before the artist’s name, and the songs will play in numerical order.
2. Open Web Juke Box.
3. Select your desired skin.
4. Save the file with the desired filename.
5. Upload the files to your server.
6. Copy and paste the following code into your preferred text editor (Notepad, etc.)
<?php error_reporting(0);
# XmlSpew for CoffeeCup Web JukeBox
# By Dave Sellers - http://digicave.org
# Use, abuse, but leave credit intact.
# v.02 9/22/2008
/* EDIT ONLY THE VARIABLE BELOW ***********************************/
/****************************************************************/
$file_dir = "bananapants";
// this is where your mp3 files are.
// change this to a folder name deeper
// than current directory. don't worry
// the script appends the _files on the
// name
/* STOP HERE. GET IT WORKING FIRST. THEN SCREW IT UP **************/
/**************************************************************/
$omit_chars = 0;
// how many characters to cut off the
// title's front. this is in case you
// have them numbered to play in order
//
// No touchy below here
//
# Let's write the most current playlist of songs from the target dir
# into the xml file for our swf player. And, begin..
if ((isset($_GET['spew'])) AND ($_GET['spew'] == 1))
{
$dirPath = dirname($_SERVER['REQUEST_URI']);
if ($dirPath == "/")
$dirPath = str_replace("/", "", $dirPath);
$dir = opendir($file_dir."_files");
// open the directory. we're gonna grab
// the filenames now
$xml_string = array();
// create the array for the mp3's
while ($file = readdir($dir))
// now we're looping until we log all
// mp3s in the given directory
{
if(substr($file, -3) == "mp3")
{
$parts = explode(" - ", $file);
$tmp_str = '<node artist="'.$parts[0].'"
file="'.$dirPath.'/nocache.php?param='.$dirPath.'/'.$file_dir.'_files/'.$file.'"
name="'.substr($parts[1], 0, -4).'" label="'.substr($parts[0], $omit_chars)." - ".substr($parts[1], 0, -4).'"';
$tmp_str .=" />";
array_push($xml_string, $tmp_str);
}
}
sort($xml_string);
$parsed = "\n<node label=\"\">\n";
for($i=0; $i<count($xml_string); $i++)
{
$parsed .="".$xml_string[$i]."\n";
}
$parsed .= "</node>\n</tree>";
closedir($dir);
// we're done with the list, close the dir.
if (file_exists("{$file_dir}.xml.bak"))
{
unlink("{$file_dir}.xml");
rename("{$file_dir}.xml.bak", "{$file_dir}.xml");
header('Location: '.$_SERVER['REQUEST_URI'].'');
} else {
copy("{$file_dir}.xml","{$file_dir}.xml.bak");
// We're writing the .xml file below.
$str=implode("",file("{$file_dir}.xml"));
if (eregi($parsed, $str))
{
// Do nothing. We have the most current playlist.
} else {
// Write the most current playlist to the .xml file.
$fh = fopen("{$file_dir}.xml", "w") or die("Meh. I can't open the xml playlist file.");
$str = str_replace('</tree>', $parsed, $str);
fwrite($fh,$str,strlen($str));
fclose($fh);
}
echo "Bleh! I just spewed.";
echo "<br><a href=\"{$file_dir}.html\" title=\"Load your player\">Load your player</a>";
}
} else {
echo "You forgot ?spew=1<br><a href=\"".$_SERVER['REQUEST_URI']."?spew=1\" title=\"Let's spew again.\">Lemme help ya.<a/>";
}
?>
7. Now you’re going to edit the $file_dir variable. Replace “bananapants” with the name of your JukeBox HTML file. You don’t need to include the .html extension — the script appends it automatically.
8. Save this file as xmlspew.php.
9. Create a new document in your text editor.
10. Copy and paste this code into the blank document:
<php
$fileonly=$_GET['param'];
$file=$_SERVER['DOCUMENT_ROOT']."/".$fileonly;
header('Cache-Control: no-cache');
header('Cache-Control: no-store');
header('Pragma: no-cache');
header('Content-Type: audio/x-mp3');
header('Content-Length: ' . filesize($file));
$fh = fopen($file,"rb");
while (!feof($fh)) { print(fread($fh, filesize($file))); }
fclose($fh);
?>
11. Save this as nocache.php.
12. Upload xmlspew.php and nocache.php into the same directory as your JukeBox files (HTML, SWF, XML).
13. Upload the MP3s you want to include in your player into the folder containing your JukeBox files.
14. Now it’s time to run the script. To do this, type out the path to your jukebox on your server into your Web browser, replacing the name of your jukebox with “xmlspew.php?spew=1”. For example, if the path to your jukebox on your site was http://www.yourdomain.com/music/jukebox.html, you’d replace “jukebox.html” with “xmlspew.php?xpew-1”.
15. The following message will appear in your browser:
Bleh! I just spewed.
Load your player
16. Click the “Load your player” link to access your jukebox. It will now display all the songs you have uploaded to the folder containing your JukeBox files.
Rate This Article
You must be signed in to rate articles.