From d890fd4beb74429626b3d49b008b645889f8bbe0 Mon Sep 17 00:00:00 2001 From: TheTroll Date: Wed, 17 Mar 2010 13:20:30 +0100 Subject: Implemented startBroacast PHP files cleanup --- bin/session.php | 118 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100755 bin/session.php (limited to 'bin/session.php') diff --git a/bin/session.php b/bin/session.php new file mode 100755 index 0000000..8b998d2 --- /dev/null +++ b/bin/session.php @@ -0,0 +1,118 @@ + $qp) + { + if ($qn == $mode) + { + $qparams = $qp; + break; + } + } + + // Create session + exec('mkdir ../ram/' .$session); + $url = str_replace("\\'", "'", $url); + switch ($type) + { + case 'tv': + $cmd = "export SHELL=\"/bin/sh\";printf \"./istream.sh \\\"" .$url ."\\\" " .$qparams ." " .$httppath ." 2 " .$ffmpegpath ." " .$segmenterpath ." " .$session ." \" | at now"; + break; + case 'rec': + $cmd = "export SHELL=\"/bin/sh\";printf \"cat \\\"" .$url ."\\\"/0* | ./istream.sh - " .$qparams ." " .$httppath ." 1260 " .$ffmpegpath ." " .$segmenterpath ." " .$session ." \" | at now"; + break; + case 'vid': + $cmd = "export SHELL=\"/bin/sh\";printf \"./istream.sh \\\"" .$url ."\\\" " .$qparams ." " .$httppath ." 1260 " .$ffmpegpath ." " .$segmenterpath ." " .$session ." \" | at now"; + break; + default: + $cmd = ""; + } + + $cmd = str_replace('%', '%%', $cmd); + exec ('echo "' .$cmd .'" > /tmp/a'); + exec ($cmd); + + // Extract $channame if needed + switch ($type) + { + case 'tv': + $urlarray = explode("/", $url); + $channum = $urlarray[count($urlarray)-1]; + $channame = vdrgetchanname($channum); + break; + case 'rec': + list($channame, $title, $desc) = vdrgetrecinfo($url); + break; + default: + $channame = ""; + break; + } + + // Write streaminfo + writeinfostream($session, $type, $mode, $url, $channame); + + // Create logo + if ($type == 'vid') + generatelogo($type, $url, '../ram/' .$session .'/logo.png'); + else + generatelogo($type, $channame, '../ram/' .$session .'/logo.png'); + + return $session; +} + +function sessiondelete($session) +{ + if ($session == 'all') + { + $dir_handle = @opendir('../ram/'); + if ($dir_handle) + { + while ($session = readdir($dir_handle)) + { + if($session == "." || $session == ".." || $session == 'lost+found') + continue; + + if (!is_dir('../ram/' .$session)) + continue; + + // Get info + list($type, $mode, $url, $channame) = readinfostream($session); + + if ($type) + sessiondeletesingle($session); + } + } + } + else + return sessiondeletesingle($session); +} + +function sessiondeletesingle($session) +{ + $ram = "../ram/" .$session ."/"; + + // Get segmenter PID if any + if (file_exists($ram ."segmenter.pid")) + $cmd = "/usr/local/bin/fw;kill `cat " .$ram ."segmenter.pid`; rm " .$ram ."segmenter.pid; "; + + $cmd .= "rm -rf " .$ram; + exec ($cmd); +} + +?> -- cgit v1.2.3