Browse Source

first checkin :-)

Thomas Merkel 14 years ago
commit
d2ca0cd3e1
6 changed files with 243 additions and 0 deletions
  1. 30 0
      channels.dvb
  2. 12 0
      frutv.css
  3. BIN
      frutv.png
  4. BIN
      frutv_ico.png
  5. 200 0
      index.php
  6. 1 0
      tuning.dat

+ 30 - 0
channels.dvb

@@ -0,0 +1,30 @@
+# generated by tmerkel
+TV:Das Erste:11836:h:0:27500:101:102:28106
+TV:EinsExtra:10743:h:0:22000:101:102:28721
+TV:EinsPlus:10743:h:0:22000:301:302:28723
+TV:EinsFestival:10743:h:0:22000:201:202:28722
+TV:ZDF:11953:h:0:27500:110:120:28006
+TV:ZDFinfokanal:11953:h:0:27500:610:620:28011
+TV:ZDFdokukanal:11953:h:0:27500:660:670:28014
+TV:ZDFtheaterkanal:11953:h:0:27500:1110:1120:28016
+TV:RTL Television:12187:h:0:27500:163:104:12003
+TV:RTL2:12187:h:0:27500:166:128:12020
+TV:Super RTL:12187:h:0:27500:165:120:12040
+TV:ProSieben:12544:h:0:22000:511:512:17501
+TV:kabel eins:12544:h:0:22000:767:768:17502
+TV:SAT.1:12544:h:0:22000:255:256:17500
+TV:3sat:11953:h:0:27500:210:220:28007
+TV:VOX:12187:h:0:27500:167:136:12060
+TV:DAS VIERTE:12460:h:0:27500:2047:2048:1793
+TV:DSF:12480:v:0:27500:1023:1024:900
+TV:COMEDY CENTRAL Germany:11973:v:0:27500:4071:4072:28677
+TV:ARTE:11567:v:0:22000:167:136:9019
+TV:DMAX:12246:v:0:27500:511:512:10101
+TV:n-tv:12187:h:0:27500:169:73:12090
+TV:N24:12544:h:0:22000:1023:1024:17503
+TV:TELE 5:12480:v:0:27500:1535:1536:51
+TV:Phoenix:10743:h:0:22000:501:502:28725
+TV:NICK Germany:11973:v:0:27500:4101:4102:28680
+TV:MTV Germany:11973:v:0:27500:4031:4032:28673
+TV:VIVA Germany:11973:v:0:27500:4061:4062:28676
+TV:DELUXE MUSIC:12246:v:0:27500:255:256:10100

+ 12 - 0
frutv.css

@@ -0,0 +1,12 @@
+body {
+	color:       black;
+	font-family: Verdana, Arial, sans-serif;
+}
+h1 {
+	font-size: 200%;
+}
+.orange_h1 {
+	color:     orange;
+	font-size: 80%;
+}
+

BIN
frutv.png


BIN
frutv_ico.png


+ 200 - 0
index.php

@@ -0,0 +1,200 @@
+<?php
+//--------------------------------------------------------------------
+// $Id: index.php,v 0.7 2008/07/24 18:46:16 tmerkel Exp $
+// Copyright 2008 Frubar Network (drscream@frubar.net | wiedi@frubar.net)
+//--------------------------------------------------------------------
+
+/*
+ * information:
+ * - vlc under gentoo is compiled with the following useflags:
+ *   X a52 aac aalib alsa avahi bidi dbus dts dvb dvd esd ffmpeg flac
+ *   gnutls hal httpd libgcrypt mmx modplug mp3 mpeg musepack musicbrainz
+ *   ncurses ogg opengl png pvr qt4 samba sdl shout sse stream taglib 
+ *   truetype upnp v4l v4l2 vcd vcdx vlm vorbis xml xv
+ * - apache must in the same group that the dvb device, for example
+ *   video and audio.
+ * - the channels.dvb must be in the following format (the first is the
+ *   line number :P ):
+ *   1: # generated by tmerkel
+ *   2: info:channel name:frequency:orientation:unknown:symbols:unused:unused:channel
+ *   3: TV  :Das Erste   :11836    :h          :0      :27500  :101   :102   :28106
+ *   example line:
+ *   4: TV:Das Erste:11836:h:0:27500:101:102:28106
+ *
+ */
+
+define( 'NL', "\n" );
+
+/*
+ * functions
+ */
+function rmnl( $in ) {
+	return str_replace("\n", "", $in);
+}
+
+function init( $station = 0 ) {
+	$channels = array();
+	$chandb[0] = file('channels.dvb');
+	$chandb[1] = count($chandb[0]);
+
+	foreach( $chandb[0] as $chan ) {
+		$channels[] = rmnl(explode(':', $chan));
+	}
+
+	for( $s = 0; $chandb[1] >= $s; $s++ ) {
+		$channels[$s]['channel']   = $channels[$s][8];
+		$channels[$s]['frequency'] = $channels[$s][2] . '000';
+		$channels[$s]['symbols']   = $channels[$s][5] . '000';
+
+		if($channels[$s][3] == 'v')
+			$channels[$s]['voltage'] = 13;
+		else
+			$channels[$s]['voltage'] = 18;
+	}
+
+	if( $station > 0 )
+		return $channels[$station];
+	else
+		return $channels; 
+}
+
+function inerr( $error, $text ) {
+	if ( $error ) {
+		echo $text; exit();
+	} else {
+		echo $text;
+	}
+}
+
+function channelname( $station, $channels ) {
+	return $channels[$station][1];
+}
+
+function vlc_status( ) {
+	// proccess check
+	$pid = file_get_contents('vlc.pid');
+	if( $pid ) 
+		$s['s'] = true;
+	else
+		$s['s'] = false;
+
+	if( $s['s'] ) {
+		$tuned = file_get_contents('tuning.dat');
+		$s['i'] = $tuned;
+		$s['p'] = $pid;
+	}
+	return $s;
+}
+
+function exec_vlc( $station, $cmd_http ) {
+	$status = vlc_status();
+	if( $status['s'] ) {
+		exec( 'kill -9 '.(int)$status['p'] );
+		sleep(2);	// waiting for the kill
+	}
+	shell_exec( 'env -i bash -c '.escapeshellarg($cmd_http) );
+	file_put_contents( 'tuning.dat', $station );
+	$status = vlc_status();
+	if( $status['s'] )
+		return true;
+	else
+		return false;
+}
+
+function playlist( $channels ) {
+	header('Content-type: application/xspf+xml');
+	header('Content-Disposition: attachment; filename="tv.xspf"');
+
+	echo '<?xml version="1.0" encoding="UTF-8"?>' . NL
+	   . '<playlist version="1" xmlns="http://xspf.org/ns/0/">' . NL 
+	   . '<trackList>' . NL
+       . '<track><location>http://'.$_SERVER[HTTP_HOST].':8080</location><title>Last Tuned</title></track>';
+
+	foreach( $channels as $num => $c ) {
+		if( $c[0] != 'TV' && $c[0] != 'RA' ) continue;
+			echo '<track><location>http://'.$_SERVER[HTTP_HOST].'/frutv/?station=' . $num 
+			   . '&amp;playlist=true</location><title>' . $c[0] 
+			   . ': ' . htmlspecialchars(utf8_encode($c[1])). '</title></track>'.NL;
+    }
+
+	echo '</trackList></playlist>';
+    exit();
+}
+
+/*
+ * parameters
+ */
+function cmd( $channel, $frequency, $voltage, $symbols ) {
+	$cmd_http = '/usr/bin/vlc -d --pidfile vlc.pid --ts-es-id-pid'
+	          . ' --program ' . $channel
+	          . ' --dvb-frequency=' . $frequency
+	          . ' --dvb-adapter=1'
+	          . '  dvb:// -I telnet telnet-password=asdfjedn3jdsw3jd'
+	          . ' --dvb-voltage=' . $voltage
+	          . ' --dvb-srate=' . $symbols
+	          . ' --sout \'#duplicate{dst="standard{access'
+	          . '=http,mux=ts,url=:8080/tv},select="program=' . $channel . '"}\' ';
+	//          . ' --sout \'#duplicate{dst="transcode{acodec=mp3, vcodec=mp4v,vb=2000,ab=128,vt=800000,keyint=80}:standard{access'
+	//          . '=http,mux=ts,url=:8080/tv}",select="program=' . $channel . '"}\' ';
+
+	return $cmd_http;
+}
+
+
+
+/*
+ * main
+ */
+// param
+$playlist = $_GET['playlist'];
+$station  = (int)$_GET['station'];
+
+$channels = init( $station );
+
+if( $station > 0 ) {
+	$cmd = cmd( $channels['channel'], 
+	            $channels['frequency'], 
+	            $channels['voltage'],
+	            $channels['symbols']);
+	$status = exec_vlc( $station, $cmd );
+	
+	if( isset($playlist) ) {
+		sleep(5);	// fix for a slow machine, slow dvb card...
+		header( 'Location: http://'.$_SERVER[HTTP_HOST].':8080/', true, 303 );
+	} elseif( $status )
+		header( 'Location: http://'.$_SERVER[HTTP_HOST].'/frutv/' );
+}
+elseif( isset($playlist) ) {
+	playlist( $channels );
+}
+else {
+	$status = vlc_status();
+	$channelname = channelname( $status['i'], $channels );
+	$channelname = ( $channelname ) ? 'currrent channel: '.$channelname : '';
+
+	// default channel list
+	echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"'.NL
+	    .'"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'.NL
+	    .'<html xmlns="http://www.w3.org/1999/xhtml">'.NL
+	    .'  <head>'.NL
+	    .'    <title>FruTV</title>'.NL
+	    .'    <meta http-equiv="content-type" content="text/html; charset=utf-8" />'.NL
+	    .'    <link rel="stylesheet" type="text/css" href="frutv.css" />'.NL
+		.'    <link rel="shortcut icon" type="image/png" href="frutv_ico.png" />'.NL
+	    .'  </head>'.NL
+	    .'  <body>'.NL;
+	echo '    <h1><img src="frutv.png" /> <span class="orange_h1">Fru</span>TV</h1>'.NL
+	    .'    <hr />'.NL
+	    .'    <h2>Channel List</h2>'.NL
+	    .'    '.$channelname.'<br /><br />'.NL
+	    .'    <a href="?playlist">&raquo; playlist</a><br /><br />'.NL;
+
+	foreach($channels as $num => $c) {
+		if($c[0] != 'TV' && $c[0] != 'RA') continue;
+			echo '    '.$c[0] . ' <a href="?station=' . $num . '">' . $c[1] . '</a><br />'.NL;
+	}
+	echo '  </body>'.NL
+	    .'</html>';
+}
+
+?>

+ 1 - 0
tuning.dat

@@ -0,0 +1 @@
+