#!/usr/bin/perl
#------------------------------------------------------------------------------
# Copyright (C) 2001 Thomax Kaulmann
# 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later 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 for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

use CGI;
use DBI;
use lib '/opt/oma/opa/perl';
use OPA;

local %in, $query;
undef(%in);


##   ##            ##            ######         ##   ##
### ###           ####             ##           ###  ##
#######          ##  ##            ##           #### ##
#######          ##  ##            ##           ## ####
## # ##          ######            ##           ##  ###
##   ##          ##  ##            ##           ##   ##
##   ##          ##  ##          ######         ##   ##

CGI::ReadParse();

$query = new CGI();
#print $query->header('text/html');

$in{'base'} = $OPA::HOST if(!$in{'base'});

if($in{'id'} && !$in{'url'}) {
	$db=OPA::opendb();
	$st=$db->prepare("select dc__identifier,path from opa_page where id=$in{'id'} AND location='$in{'base'}'");
	$st->execute();
	@row = $st->fetchrow();
	$st->finish();

	my @s = split(/\//,$row[0]);
	$row[0] = $s[$#s];
	if(($row[0] =~ /\.mp3$/) || ($row[0] =~ /\.ogg$/)) {
		print $query->header('audio/x-mpegurl');
#		print $query->header('audio/x-mp3');
#		print "http://$in{'base'}:8000/file$row[1]$in{'id'}/$row[0]\n";
#		print "http://$in{'base'}:8000/sendungen_gen/$row[0]\r\n";
		print "http://$in{'base'}/sendungen_gen/$row[0]\r\n";
	} else {
		print $query->header('audio/x-pn-realaudio');
		print "pnm://$in{'base'}$row[1]$in{'id'}/$row[0]\n";
	}
} else {
#	print $query->header('text/html');
	print $query->header('audio/x-pn-realaudio');
	print "$in{'url'}\n";
}

