podcasting, ruby

finally started to play with podcasts a bit. these are essentially rss feeds containing links to audio files. pod cast clients like iPodder then automatically download these files every time there is a new RSS post.
on my search for some interesting feeds i accidentally came across chaos radio (german), a radio show about various IT topics produced by the chaos computer club - unfortunately they don’t offer a feed, so i just wrote one, which is available under langalex.org/chaosradio_podcast_ogg.php.
i started with a simple PHP script that reads the file list from their ftp server and creates an rss representation from that, linking to the ftp server. apparently, my pod casting client doesn’t speak ftp but only http. so i ended up writing an ftp to http proxy script - the final reason i needed to start playing with ruby, an OO scripting language some smart people have been talking about quite a bit in the last months.

problems not solved yet: the rss feed is generated from the ftp server file list every time causing unneccessary load on the ccc ftp server. also, the ftp-http proxy downloads the files from the ftp server before sending them to the actual client.

PHP RSS feed script:

<?
header("Content-type: application/xml");
echo '<?xml version="1.0"?>';
$ftp_server = "ftp.ccc.de";
$conn_id = ftp_connect($ftp_server);
if($conn_id == false) die("could not connect to server");
$login_result = ftp_login($conn_id, "anonymous", "");
ftp_chdir($conn_id, "chaosradio");
$dirs = ftp_nlist($conn_id, ".");
foreach($dirs as $dir) {
$files = ftp_nlist($conn_id, $dir);
foreach($files as $file) {
if(strstr($file, ".ogg") != false) {
$items[$i++]=$file;
}
}
}
?>
<rss version="2.0">
<channel>
<title>chaosradio</title>
<link>http://chaosradio.ccc.de/archiv.html</link>
<description/>
<?
foreach($items as $item) {
?>
<item>
<title><?=substr($item,0,-4)?></title>
<link></link>
<description/>
<guid isPermaLink="false"><?=$item?></guid>
<enclosure url="<?="http://langalex.org/ftp2http.rbx?file=".$item?>"/>
</item>
<?
}
?>
</channel>
</rss>

Ruby FTP to HTTP script:

require 'net/ftp'
require 'cgi'
print "HTTP/1.0 200 OK\r\n"
print "Content-type: application/octet-stream\r\n"
cgi = CGI.new
tempFileName='/tmp/'+Kernel::rand(9999999).to_s
sourceFileName=cgi.params['file'][0]
print 'Content-Disposition: attachment; filename="'+sourceFileName+'"\r\n\r\n'
ftp = Net::FTP.new('ftp.ccc.de')
ftp.login
ftp.getbinaryfile('/chaosradio/'+sourceFileName, tempFileName, 1024) {|data|
print data
}
ftp.close
File::delete(tempFileName)

one minute later…

uhm. just tried to download several files (each ~100MB) at once - i get out of memory errors and that - apparently the ruby script tries to load the whole file into ram before sending it to the client :(
ipodder also gets a timeout because the ftp download takes too long, so nothin really working yet.

5 minutes later…

replaced ftp.getbinaryfile with ftp.retrbinary which doesn’t use a local file - but it still doesn’t do real streaming, it takes forever until … i get the out of memory error

Tags:

Leave a Reply