From f27608f2695d51f563adb6ebc8c475c6a8df53ba Mon Sep 17 00:00:00 2001 From: root Date: Wed, 17 Feb 2010 23:14:37 +0100 Subject: 0.3.5-dev --- includes/inc_auth.php | 32 ++++ includes/inc_cat.php | 17 ++ includes/inc_chan.php | 24 +++ includes/inc_home.php | 20 ++ includes/inc_media.php | 16 ++ includes/inc_rec.php | 62 ++++++ includes/inc_stream.php | 177 ++++++++++++++++++ includes/inc_streaminfo.php | 61 ++++++ includes/inc_svdrp.php | 446 ++++++++++++++++++++++++++++++++++++++++++++ includes/inc_vdr.php | 204 ++++++++++++++++++++ includes/include.php | 112 +++++++++++ 11 files changed, 1171 insertions(+) create mode 100755 includes/inc_auth.php create mode 100755 includes/inc_cat.php create mode 100755 includes/inc_chan.php create mode 100755 includes/inc_home.php create mode 100755 includes/inc_media.php create mode 100755 includes/inc_rec.php create mode 100755 includes/inc_stream.php create mode 100755 includes/inc_streaminfo.php create mode 100755 includes/inc_svdrp.php create mode 100755 includes/inc_vdr.php create mode 100755 includes/include.php (limited to 'includes') diff --git a/includes/inc_auth.php b/includes/inc_auth.php new file mode 100755 index 0000000..92f0fc8 --- /dev/null +++ b/includes/inc_auth.php @@ -0,0 +1,32 @@ + diff --git a/includes/inc_cat.php b/includes/inc_cat.php new file mode 100755 index 0000000..0b107d3 --- /dev/null +++ b/includes/inc_cat.php @@ -0,0 +1,17 @@ +\r\n"; +print "
\r\n"; +print "
\r\n"; +print "\"home\"
\r\n"; +print "
iStreamdev
\r\n"; +print "
\r\n"; +print "
\r\n"; +print " Category\r\n"; +print " "; +print "
\r\n"; +?> diff --git a/includes/inc_chan.php b/includes/inc_chan.php new file mode 100755 index 0000000..02cb80e --- /dev/null +++ b/includes/inc_chan.php @@ -0,0 +1,24 @@ +\r\n"; +print "
\r\n"; + +print "
\r\n"; +print "Back
\r\n"; +print "
\r\n"; +print "\"home\"
\r\n"; +print "
iStreamdev
\r\n"; +print "
\r\n"; +print "
\r\n"; +print " "; +print "
\r\n"; +print "
\r\n"; +?> diff --git a/includes/inc_home.php b/includes/inc_home.php new file mode 100755 index 0000000..8fcf513 --- /dev/null +++ b/includes/inc_home.php @@ -0,0 +1,20 @@ +\r\n"; +print "
\r\n"; +print "
iStreamdev
\r\n"; +print "
\r\n"; +print "
\r\n"; +print " Home\r\n"; +print " "; +print "
"; +?> diff --git a/includes/inc_media.php b/includes/inc_media.php new file mode 100755 index 0000000..b946e09 --- /dev/null +++ b/includes/inc_media.php @@ -0,0 +1,16 @@ +\r\n"; +print "
\r\n"; +print "
\r\n"; +print "\"home\"
\r\n"; +print "
iStreamdev
\r\n"; +print "
\r\n"; +print "
\r\n"; +print " Media\r\n"; +print "
\r\n"; + +?> diff --git a/includes/inc_rec.php b/includes/inc_rec.php new file mode 100755 index 0000000..42ab455 --- /dev/null +++ b/includes/inc_rec.php @@ -0,0 +1,62 @@ +\r\n"; +print "
\r\n"; +print "
\r\n"; +if ($dir == $vdrrecpath) + print "\"home\"
\r\n"; +else + print "Back
\r\n"; + +print "
iStreamdev
\r\n"; +print "\r\n"; +print "
\r\n"; +print " Recordings\r\n"; +print "
"; +print " {$subdir}\r\n"; +print "
\r\n"; +?> diff --git a/includes/inc_stream.php b/includes/inc_stream.php new file mode 100755 index 0000000..84d621f --- /dev/null +++ b/includes/inc_stream.php @@ -0,0 +1,177 @@ +\r\n"; + + print "
\r\n"; + print "
\r\n"; + print "Stop Stream
\r\n"; + print "
iStreamdev
\r\n"; + print "
\r\n"; + + print "
\r\n"; + print " Now streaming\r\n"; + + // Print the right logo + print " \r\n"; + + print " \r\n"; + + print " \r\n"; + + print "
\r\n"; + + print "
"; + print " "; + switch ($type) + { + case 1: + print " "; + print " "; + break; + default: + case 2: + $dir = dirname($url); + print " "; + print " "; + break; + } + print "
\r\n"; +} +else +{ + $category = $_SESSION['currentcat']; + + $type = $_REQUEST['type']; + $name = $_REQUEST['name']; + + switch ($type) + { + // Live TV + case 1: + list($title, $desc, $realname) = vdrgetinfostream($name, 1); + $channum = vdrgetchannum($realname); + break; + // Recording + case 2: + list($title, $desc, $realname) = vdrgetinfostream($name, 0); + break; + case 3: + default: + $realname = ""; + $title = ""; + $desc = ""; + $channame = $name; + } + + print "\r\n"; + + print "
\r\n"; + print "
\r\n"; + + print "Back
\r\n"; + print "
\r\n"; + print "\"home\"
\r\n"; + + print "
iStreamdev
\r\n"; + print "
\r\n"; + + print "
\r\n"; + + print " Select stream mode\r\n"; + + print " \r\n"; + + // Check if running to display the start buttons + print "
\r\n"; + print "
\r\n"; + + foreach ($quality as $qname => $qparams) + print "{$qname}"; + print "\r\n"; + + print "
\r\n"; + + print " \r\n"; + + print "
\r\n"; + + foreach ($quality as $qname => $qparams) + { + print "
\r\n"; + print " \r\n"; + print " \r\n"; + print " \r\n"; + print " \r\n"; + print " \r\n"; + print " \r\n"; + print " \r\n"; + print " \r\n"; + switch ($type) + { + case 1: + print " \r\n"; + break; + case 2: + default: + print " \r\n"; + break; + } + print "
"; + } + + print "
"; + switch ($type) + { + case 1: + print " "; + print " "; + break; + default: + case 2: + $dir = dirname($vdrrecpath .$name); + print " "; + print " "; + break; + } + print "
\r\n"; + +} + +?> diff --git a/includes/inc_streaminfo.php b/includes/inc_streaminfo.php new file mode 100755 index 0000000..a45920c --- /dev/null +++ b/includes/inc_streaminfo.php @@ -0,0 +1,61 @@ + diff --git a/includes/inc_svdrp.php b/includes/inc_svdrp.php new file mode 100755 index 0000000..da83b49 --- /dev/null +++ b/includes/inc_svdrp.php @@ -0,0 +1,446 @@ +cfgServer = $server; + $this->cfgPort = $port; + $this->cfgTimeOut = $timeout; + $this->debug = $debug; + $this->handle = 0; + } + + function DebugMessage($msg) + { + if($this->debug) echo ($msg); + } + + function Connect() + { + if($this->handle) Disconnect(); + $errno = 0; + $errstr = ""; + $this->handle = fsockopen($this->cfgServer, $this->cfgPort, &$errno, &$errstr, $this->cfgTimeOut); + + if(!$this->handle) + { + $this->DebugMessage("error $errno: $errstr"); + return false; + } + + $this->DebugMessage("handle: $this->handle
\n"); + + + $input = fgets($this->handle,128); + + if(!preg_match("/^220 /", $input) || $input == "") + { + $this->DebugMessage("wrong welcome message: '$input'
\n"); + $this->Disconnect(); + return false; + } + + + $this->DebugMessage("Welcome message: $input

\n"); + + return true; + } + + function Command($cmd) + { + if(!$this->handle) return false; + + $ret = array(); + + $this->DebugMessage("Kommando $cmd
"); + fputs($this->handle, $cmd . "\n"); + $s = ""; + $nline = 0; + while($s .= fgets($this->handle,4096)) + { + $nline++; + + $this->DebugMessage($s); + if(!preg_match("/^(\\d{3})([ -])(.*)$/", $s, $data)) + { + continue; + } + + + + + $number = $data[1]; + // TODO: Fehlernummer bearbeiten + $ret[] = $data[3]; + if($data[2] != "-" && $nline == 1) $ret = $data[3] ; + if($data[2] != "-") break; + $s = ""; + + } + + $this->DebugMessage(""); + return $ret; + } + + function ListChannels($numberorname="") + { + if(!$this->handle) return false; + $channels = array(); + $lines = $this->Command("LSTC$numberorname"); + if(!$lines) return false; + foreach($lines as $a => $l) + { + $a = split(":", $l); + $name = $a[0]; + $freq = $a[1]; + $b = split(";", $name); + $name = $b[0]; + if(!isset($b[1])) $b[1] = $name; + $group = $b[1]; + + + $c["name"] = $name; + $c["group"] = $group; + $c["frequency"] = $freq; + + $channels[] = $c; + + + } + return $channels; + } + + function Help() + { + return $this->Command("HELP"); + } + function Disconnect() + { + if(!$this->handle) return; + $this->Command("QUIT"); + + fclose($this->handle); + $this->handle = 0; + $this->DebugMessage("disconnected"); + } + function ClearEpg() + { + if(!$this->handle) return false; + $this->Command("CLRE"); + return true; + } + function SwitchUp() + { + if(!$this->handle) return false; + $this->Command("CHAN +"); + return true; + } + function SwitchDown() + { + if(!$this->handle) return false; + $this->Command("CHAN -"); + return true; + } + function SwitchChannel($channel) + { + if(!$this->handle) return false; + $this->Command("CHAN $channel"); + return true; + } + function DeleteChannel($id) + { + if(!$this->handle) return false; + $this->Command("DELC $id"); + return true; + } + function DeleteRecord($id) + { + if(!$this->handle) return false; + $this->Command("DELR $id"); + return true; + } + + function GrabImage($filename, $type="jpeg", $quality="", $width="", $height) + { + if(!$this->handle) return false; + $this->Command("GRAB $filename $type $quality $width $height"); + return true; + } + function HitKey($key) + { + if(!$this->handle) return false; + $this->Command("HITK $key"); + return true; + } + function PowerOff() + { + if(!$this->handle) return false; + $this->Command("HITK Power"); + return true; + + } + function GetKeys() + { + if(!$this->handle) return false; + + $lines = $this->Command("HITK"); + $keys = array(); + foreach($lines as $l) + { + if(!preg_match("/^ {4}(.*)$/", $l, $m)) continue; + $keys[] = $m[1]; + } + + return $keys; + } + function ListEPG($pStrChannel="", $pStrTime="") + { + if(!$this->handle) return false; + $lines = $this->Command("LSTE"); + + $epg = array (); + $channel = array(); + $event = array(); + + $channelname = ""; + foreach($lines as $l) + { + preg_match("/^(.)\\s*(.*)$/", $l, $m); + $type = $m[1]; + $text = $m[2]; + switch($type) + { + case 'C': // Channel + list( $channeldata, $channelname ) = explode( ' ', $text, 2 ); + + break; + case 'E': // new Event + sscanf($text, "%u %ld %d %X", $event["EventID"], $event["StartTime"], $event["Duration"], $event["TableID"]); + + break; + case 'T': // Title + $event["Title"] = $text; + break; + case 'S': // Short text + $event["Shottext"] = $text; + break; + case 'D': // Description + $event["Desc"] = $text; + break; + case 'V': // VPS + $event["VPS"] = $text; + break; + case 'e': // Event end + if ((trim($pStrTime) != '') && (( $event['StartTime'] > $pStrTime ) || ($event['StartTime'] + $event["Duration"] < $pStrTime))) + continue; + + $channel[] = $event; + $event = array(); + + break; + case 'c': // Channel end + if ((trim($pStrChannel) != '') && ($channelname != $pStrChannel)) + continue; + + $epg[$channelname] = $channel; + $channel = array(); + + break; + } + + } + if ((trim($pStrTime) == '') || (( $event['StartTime'] < $pStrTime ) && ($event['StartTime'] + $event["Duration"] > $pStrTime))) + $channel[] = $event; + + if ((trim($pStrChannel) != '') || ($channelname == $pStrChannel)) + $epg[$channelname] = $channel; + + return $epg; + } + + function Message($msg) + { + if(!$this->handle) return false; + $this->Command("MESG $msg"); + return true; + } + + + // Volume commands + function ToggleMute() + { + if(!$this->handle) return false; + $this->Command("VOLU mute"); + return true; + } + function VolumeUp() + { + if(!$this->handle) return false; + $this->Command("VOLU +"); + return true; + } + function VolumeDown() + { + if(!$this->handle) return false; + $this->Command("VOLU -"); + return true; + } + function SetVolume($v) + { + if(!$this->handle) return false; + $this->Command("VOLU $v"); + return true; + } + function GetVolume() + { + if(!$this->handle) return false; + $v = $this->Command("VOLU"); + if($v == "Audio is mute") return 0; + if(!preg_match("/Audio volume is (.*)/", $v, $m)) return false; + + return $m[1]; + } + function GetDiskStat() + { + if(!$this->handle) return false; + $stat = $this->Command("STAT DISK"); + sscanf($stat, "%dMB %dMB %d%%", $FreeMUsedMB, $FreeMB, $Percent); + $ret["FreeMB + UsedMB"] = $FreeMUsedMB; + $ret["FreeMB"] = $FreeMB; + $ret["UsedMB"] = $FreeMUsedMB - $FreeMB; + $ret["Percent"] = $Percent; + return $ret; + } + function StartScan() + { + if(!$this->handle) return false; + $this->Command("SCAN"); + return true; + } + function MoveChannel($number, $to) + { + if(!$this->handle) return false; + $this->Command("MOVC $number $to"); + return true; + + } + + function DeleteTimer($id) + { + if(!$this->handle) return false; + $this->Command("DELT $id"); + return true; + } + + function MoveTimer($number, $to) + { + if(!$this->handle) return false; + $this->Command("MOVT $number $to"); + return true; + } + + function TimerOnOff($n, $state = "on") + { + if(!$this->handle) return false; + //if($state == "1") $state = "on"; + //if($state == "0") $state = "off"; + //if($state == false) $state = "off"; + // if($state == true) $state = "on"; + switch($state) + { + case false: + case "off": + case "0": + $state = "off"; + break; + default: + $state = "on"; + break; + } + + return $this->Command("MODT $n $state"); + } + + function ListTimers() + { + + } + + function ShowMessage($msg = "") + { + if(!$this->handle) return false; + return $this->Command("MESG $msg"); + } + + function ListRecords() + { + if(!$this->handle) return false; + + $lines = $this->Command("LSTR"); + $records = array(); + foreach($lines as $l) + { + + if(!preg_match("/^(\\d)\s(\\d*)\\.(\\d*)\\.(\\d*) (\\d*)\\:(\\d*).\s(.*)$/", $l, $m)) continue; + $id = $m[1]; + $m["id"] = $m[1]; + $m["day"] = $m[2]; + $m["month"] = $m[3]; + $m["year"] = $m[4]; + $m["hour"] = $m[5]; + $m["minute"] = $m[6]; + $m["desc"] = $m[7]; + + $records[$id] = $m; + } + + return $records; + + } + + // TODO: perhaps better implementation + function ListRecord($n) + { + if(!$this->handle) return false; + $m = $this->Command("LSTR $n"); + return $m[0]; + } + + + + //TODO: Implement following commands: + /* + + + LSTT MODT NEWT UPDT + MODC NEWC + NEXT + PUTE + + */ +} + +// Small Example +/* +echo ""; +$a = new SVDRP(); +$a->Connect(); +print_r($a->Help()); +print_r($a->ListChannels()); +$a->GetKeys(); +print_r($a->GetVolume()); +print_r($a->GetDiskStat()); +$a->Disconnect(); +*/ +?> + + diff --git a/includes/inc_vdr.php b/includes/inc_vdr.php new file mode 100755 index 0000000..d36c8cc --- /dev/null +++ b/includes/inc_vdr.php @@ -0,0 +1,204 @@ +Connect(); + $allepg = $svdrp->Command("LSTE NOW"); + $svdrp->Disconnect(); + $allepgfilled = 1; + } + + $channame = $stream; + } + else + { + $infofile = $vdrrecpath .$stream ."/info"; + if (file_exists($infofile)) + $info= file_get_contents($infofile); + else + { + $infofile = $vdrrecpath .$stream ."/info.vdr"; + if (file_exists($infofile)) + $info= file_get_contents($infofile); + else + $info=""; + } + + $allepg = explode("\n", $info); + } + + if ($ischan) + $chanfound = 0; + else + $chanfound = 1; + $epgtitlefound = 0; + + $epgtitle=""; + $epgdesc=""; + + // For all epg + $count = count($allepg); + for ($i = 0; $i < $count; $i++) + { + // Find the right chan (take the first one) + if ($chanfound == 0) + { + if (strstr($allepg[$i], $stream) == $stream) + $chanfound = 1; + } + else + { + // Now find T or C + if(ereg("^C", $allepg[$i])) + { + // Check if it is our chan too, else search again + if ($ischan) + { + if(!ereg("$stream$", $allepg[$i])) + { + $chanfound = 0; + continue; + } + } + else + { + $channame = substr($allepg[$i], 2); + $channames = explode(" ", $channame); + $channame = substr($channame, strlen($channames[0])); + } + } + else if(ereg("^T", $allepg[$i])) + $epgtitle=substr($allepg[$i], 2); + else if(ereg("^D", $allepg[$i])) + $epgdesc=substr($allepg[$i], 2); + } + } + + return array($epgtitle, $epgdesc, $channame); +} + +function vdrgetchannum($chan = "NULL") +{ + global $svdrpip, $svdrpport; + + $svdrp = new SVDRP($svdrpip, $svdrpport); + $svdrp->Connect(); + $channels = $svdrp->Command("LSTC"); + $svdrp->Disconnect(); + + // Get channel number + $channels = preg_grep(quotemeta('"'.$chan.';|'.$chan.':"'), $channels); + reset($channels); + + $channels = explode(" ", $channels[key($channels)]); + $channum = $channels[0]; + + return $channum; +} + +function vdrlistcategories() +{ + global $vdrchannels; + + // All chans + print "
  • All channels
  • \r\n"; + print "
    \r\n"; + + $fp = fopen ($vdrchannels,"r"); + while ($line = fgets($fp, 1024)) + { + // Check if it is a categorie + if ($line[0] == ":") + { + // Remove : and @ + $cat = substr($line, 1, -1); + if($cat[0] == '@') + { + $cat_array = explode(' ', $cat); + $cat = substr($cat, strlen($cat_array[0])+1); + } + + $cat2 = addslashes($cat); + + print "
  • $cat
  • \r\n"; + print "
    \r\n"; + } + } + fclose($fp); +} + +function vdrlistchannels($category = "NULL") +{ + global $epgtitle; + global $vdrchannels; + + if ($category == "All") + $cat_found=1; + else + $cat_found=0; + + $fp = fopen ($vdrchannels,"r"); + while ($line = fgets($fp, 1024)) + { + if ($cat_found) + { + if ($line[0] == ":") + { + if ($category == "All") + continue; + else + break; + } + + $channels = explode(":", $line); + $channels = explode(";", $channels[0]); + $chan = $channels[0]; + + // Get EPG title + $epgtitle = NULL; + list($epgtitle, $epgdesc, $channame) = vdrgetinfostream($chan, 1); + print "
  • "; + $chan2=addslashes($chan); + print " \r\n"; + if (!file_exists('logos/'.$chan.'.png')) + print " \r\n"; + else + print " \r\n"; + print " $chan\r\n"; + print " $epgtitle\r\n
  • \r\n"; + print "
    "; + print " "; + print " "; + print " "; + print "
    \r\n"; + } + else + { + if ($line[0] == ":") + { + // Remove : and @ + $cat = substr($line, 1, -1); + if($cat[0] == '@') + { + $cat_array = explode(' ', $cat); + $cat = substr($cat, strlen($cat_array[0])+1); + } + + // Check category + if ("$cat" == "$category") + $cat_found = 1; + } + } + } + fclose($fp); +} +?> diff --git a/includes/include.php b/includes/include.php new file mode 100755 index 0000000..9078aad --- /dev/null +++ b/includes/include.php @@ -0,0 +1,112 @@ + -- cgit v1.2.3