Skip to content

Instantly share code, notes, and snippets.

@dmdeller
Created January 16, 2019 00:07
Show Gist options
  • Save dmdeller/2189bdf4b0fbf13f02dff8015e8b5cda to your computer and use it in GitHub Desktop.
Save dmdeller/2189bdf4b0fbf13f02dff8015e8b5cda to your computer and use it in GitHub Desktop.
RADICCIO: The PSP stream-your-music-collection thingy
by D.M.Deller
VERSION: 1.0.1
DESCRIPTION
This PHP script will stream files to your PSP using version 2.60's 'RSS Channel' feature. Because this feature is somewhat limited (it's annoying to scroll through the thousands of mp3s you have), the script can dynamically create a separate feed for each subdirectory in your main music directory.
It's recommended for use primarily on your home LAN (that is, the computer with the music is on the same LAN as your PSP). You should be able to access it remotely, but due to the constraints of your broadband connection's upload speed and the inherent latency in 802.11b, I highly recommend using bitrates of 128kbps or lower if you use it in this way. The lower the bitrate, the less your PSP will pause to buffer. CBR files (rather than VBR) also seem to work best.
LICENSE
This script is Copyright 2005 D.M.Deller. It is licensed under the GNU General Public License, which can be found in the accompanying file license.txt.
REQUIREMENTS
- A PSP with firmware version 2.60 or later. You can update your PSP through System Update or at www.playstation.com. Note that this will probably disable 'homebrew' programs you may use. Do some research first if that bothers you.
- A wireless network that works with your PSP.
- Music :) specifically, MP3 or M4A (aka AAC).
- (optional) If you have a file named 'folder.jpg' in a particular folder, it will be used as the image for that feed.
- A webserver (any will do, so long as it supports PHP) running on the same computer as your music collection. Many are available for free, but you might have to learn how to use them.
- PHP 5.x (no, an earlier version will not work). Also available for free. <www.php.net>
SET UP PART 1 - the webserver
You need to install a webserver, and PHP, on the computer where your music collection is located. I will not go into detail explaining this, as it can vary wildly depending on what your setup is. I personally use Apache 1.x <httpd.apache.org>, but it's not very easy for the newbie to set up. Please look elsewhere for instructions. Use your nerd skills (Google?).
You should install the webserver first, then PHP. The Windows PHP installer can automatically configure itself for many webservers (not, unfortunately, Apache... last I knew).
If you're on a Mac, you already have a webserver installed (Personal Internet Sharing or something). You just need to click one button to turn it on. It's nice being a Mac user, isn't it? You still need to install PHP though.
Familiarise yourself a little with how the server works, then place the Radiccio script files in a subdirectory that is shared by the webserver (referred to by Apache as 'htdocs').
SET UP PART 2 - the script
Look at config.php. Modify it to suit your needs. It's commented.
SET UP PART 3 - the PSP
Simply browse (via the PSP) to the site you set up. Wherever you see [RSS], 'click' that to subscribe to a folder. Then exit the web browser, go to RSS Channel, and listen. Enjoy!
COMMENTS? BUG REPORTS?
I don't mean to sound cold, but I'm a college student and I have other things going on. Therefore this script comes with NO SUPPORT from me. If you e-mail me asking how to set up a webserver or how to upgrade your firmware, or something along those lines, I will likely just delete your e-mail.
That said, I would appreciate legitimate bug reports. Please send them to david@horizon-nigh.org.
KNOWN BUGS
* The timestamp on each file is falsified in order to force the PSP to display the files in alphabetical order. It actually should display the current time when you access the feed, but there seems to be a bug in the way the PSP itself displays the time, so you get very weird results. Just try not to think about it.
SHOUT OUTS
* psp-vault.com - interesting, up-to-date PSP news and information you just won't get anywhere else, with a great community
VERSION HISTORY
1.0.1 (4 December 2005)
- bugfix: RSS feeds generated invalid URLs for m4a files
1.0 (3 December 2005)
- Initial release
WHY RADICCIO?
Why are you still reading? :)
Well, I couldn't think of a name that would describe what this thing does (PSP PHP RSS MP3 Streamer sounded rather awkward), so I just kind of picked it randomly. 'Radiccio' sounds kind of like 'little radio' in my mind (hey, I'm not Italian). It's also an EP by the excellent former UK techno group Orbital, which contains the rare original version of their dreamy 'Halcyon' song. I'm told it's also a nice veggie for use in salads. So there you go.
<?php
//VER:1.0.1
/*
Radiccio: The PSP stream-your-music-collection thingy
Copyright 2005 D.M.Deller
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as
published by the Free Software Foundation (no other version).
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License (license.txt) for more details.
*/
/*
This is the folder where your music is stored. This is a local path, not a web (http://) path.
Do not use backslashes. Use forward slashes. Yes, even if you're on Windows.
Please include a trailing slash.
*/
$config_musicfolder = 'c:/Documents and Settings/Owner/My Documents/My Music/';
/*
This is the web path to get to the local path above. Must start with http:// and end with a trailing slash.
Please, I beg you, find some way of disabling directory listing of this path for your webserver, or you'll be the #1 hit on Google for 'mp3' before long.
*/
$config_webpath = 'http://192.168.1.100/mymusic/';
/*
HINT:
If you're using Apache, add a line like this to your httpd.conf:
Alias /mymusic/ "C:/Documents and Settings/Owner/My Documents/My Music"
That will redirect requests for http://yourserver/mymusic/ to your music folder.
On my install, it also denies directory listings by default, which is good.
*/
/*
IP addresses to which to limit access. You can use a partial address (i.e., 192.168.) to match a whole range. Separate IPs by commas (i.e. 192.168.1.10,10.10.)
Leave this blank or comment it out to allow the whole world access.
*/
$config_allowedips = '';
/*
BIG FAT SECURITY WARNING:
Although this script will prevent people outside of the allowed IP variable from viewing the script files, they will sill be able to access your music files path, and anything else you web server makes available, unless you take steps to prevent it.
YOU are solely responsible for YOUR security.
*/
?>
<?php
//VER:1.0.1
/*
Radiccio: The PSP stream-your-music-collection thingy
Copyright 2005 D.M.Deller
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as
published by the Free Software Foundation (no other version).
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License (license.txt) for more details.
*/
require_once('config.php');
if (strstr(stripslashes($_GET['p']),'..'))
die('Error: invalid path');
/* check if the IP is allowed access */
if ($config_allowedips != '')
{
$ips = explode(',',$config_allowedips);
$found = false;
foreach($ips as $ip)
if (strstr($_SERVER['REMOTE_ADDR'],$ip))
$found = true;
if (!$found)
{
header('HTTP/1.1 403 Forbidden');
die('<h1>403 Forbidden</h1>');
}
}
echo '<html><head><title>Radiccio</title></head><body link="blue" vlink="blue">'."\r\n";
if ($_GET['p'] == null)
{
echo '- Radiccio -<br />';
echo '<hr />';
$searchdir = $config_musicfolder;
}
else
{
if (strstr($_GET['p'],'/'))
{
$levels = explode('/',$_GET['p']);
$current = $levels[sizeof($levels)-1];
$parent = str_replace('/'.$current,'',$_GET['p']);
}
else
$parent = '';
echo '<a href="index.php">Home</a> | <a href="index.php?p='.$parent.'">Parent</a><br />';
echo '<hr />';
$searchdir = $config_musicfolder.stripslashes($_GET['p']);
}
$mp3s = 0;
foreach(scandir($searchdir) as $item)
{
if (preg_match("/.(mp3|m4a)$/i",$item))
$mp3s++;
}
echo 'This folder: '.$searchdir.'<br />';
echo $mp3s.' audio files found. <a href="rss.php?p='.stripslashes($_GET['p']).'">[RSS]</a><br />';
echo '<hr />';
echo '<table><tr><td>Subfolder</td><td>#files&nbsp;&nbsp;</td><td align="center">Feed</td></tr>';
foreach(scandir($searchdir) as $item)
{
if ($_GET['p'] == null)
{
$fullpath = $searchdir.$item;
$partpath = $item;
}
else
{
$fullpath = $searchdir.'/'.$item;
$partpath = $_GET['p'].'/'.$item;
}
if ((is_dir($fullpath)) && ($item != '.') && ($item != '..'))
{
echo '<tr><td>';
if (strlen($item) > 50)
$item = substr($item,0,50).'...';
echo '<a href="index.php?p='.$partpath.'">'.$item.'</a>';
echo '</td>';
$mp3s = 0;
foreach(scandir($fullpath) as $subitem)
{
if (preg_match("/.(mp3|m4a)$/i",$subitem))
$mp3s++;
}
echo '<td align="center">'.$mp3s.'</td>';
echo '<td align="center"><a href="rss.php?p='.$partpath.'">[RSS]</a></td></tr>';
}
}
echo '</table>'."\r\n";
echo '</body></html>'."\r\n";
?>
User-agent: *
Disallow: /
<?php
//VER:1.0.1
/*
Radiccio: The PSP stream-your-music-collection thingy
Copyright 2005 D.M.Deller
This program is free software; you can redistribute it and/or modify
it under the terms of version 2 of the GNU General Public License as
published by the Free Software Foundation (no other version).
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License (license.txt) for more details.
*/
require_once('config.php');
if (strstr(stripslashes($_GET['p']),'..'))
die('Error: invalid path');
/* check if the IP is allowed access */
if ($config_allowedips != '')
{
$ips = explode(',',$config_allowedips);
$found = false;
foreach($ips as $ip)
if (strstr($_SERVER['REMOTE_ADDR'],$ip))
$found = true;
if (!$found)
{
header('HTTP/1.1 403 Forbidden');
die('<h1>403 Forbidden</h1>');
}
}
if ($_GET['p'] == '')
{
$searchdir = $config_musicfolder;
}
else
{
$searchdir = $config_musicfolder.stripslashes($_GET['p']);
}
header('Content-type: application/xml');
echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\r\n";
echo '<rss version="2.0">'."\r\n";
echo ' <channel>'."\r\n";
if ($_GET['p'] == '')
echo ' <title>My Music</title>'."\r\n";
else
echo ' <title>'.str_replace('_',' ',htmlentities(stripslashes($_GET['p']))).'</title>'."\r\n";
//echo ' <link>http://www.playstation.com/manual/psp/rss/</link>'."\r\n";
echo ' <description>Radiccio feed for PSP</description>'."\r\n";
echo ' <language>en</language>'."\r\n";
echo ' <pubDate>'.date('r',filemtime($searchdir)).'</pubDate>'."\r\n";
if (file_exists($searchdir.'/folder.jpg'))
{
$folderjpg = 'folder.jpg';
/* checking to see if the case of the filename is different */
foreach(scandir($searchdir) as $searchjpg)
if (preg_match('/folder\.jpg/i',$searchjpg))
$folderjpg = $searchjpg;
echo ' <image>'."\r\n";
echo ' <url>'.$config_webpath.rawurlencode($_GET['p']).'/'.$folderjpg.'</url>'."\r\n";
if ($_GET['p'] == '')
echo ' <title>My Music</title>'."\r\n";
else
echo ' <title>'.htmlentities(stripslashes($_GET['p'])).'</title>'."\r\n";
echo ' </image>'."\r\n";
}
$ctime = time();
foreach(scandir($searchdir) as $item)
{
if (preg_match("/.(mp3|m4a)$/i",$item))
{
if ($_GET['p'] == '')
{
$fullpath = $searchdir.$item;
$partpath = $item;
}
else
{
$fullpath = $searchdir.'/'.$item;
$partpath = stripslashes($_GET['p']).'/'.$item;
}
echo ' <item>'."\r\n";
echo ' <title>'.str_replace('_',' ',htmlentities(stripslashes(substr($item,0,strlen($item)-4)))).'</title>'."\r\n";
echo ' <link>'.$config_webpath.str_replace('%2F','/',rawurlencode($partpath)).'</link>'."\r\n";
// echo ' <description>JAZZ FUSION SAMPLE 1 / PSP Mix</description>'."\r\n";
// echo ' <author>Noburo Masuda</author>'."\r\n";
/* screws up file sort order on PSP */
//echo ' <pubDate>'.date('r',filemtime($fullpath)).'</pubDate>'."\r\n";
/* now this is more like it - since PSP sorts by date, most recent is first file
alphabetically, then each next file is one more second old... */
echo ' <pubDate>'.date('r',$ctime--).'</pubDate>'."\r\n";
if (substr($item,strlen($item)-3,strlen($item)) == 'mp3')
echo ' <enclosure url="'.$config_webpath.str_replace('%2F','/',rawurlencode($partpath)).'" type="audio/mp3" /> '."\r\n";
else if (substr($item,strlen($item)-3,strlen($item)) == 'm4a')
echo ' <enclosure url="'.$config_webpath.str_replace('%2F','/',rawurlencode($partpath)).'" type="audio/m4a" /> '."\r\n";
echo ' </item>'."\r\n";
}
}
echo ' </channel>'."\r\n";
echo '</rss>'."\r\n";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment