Revision 723fa73a

View differences:

utils/README
1
Here are some scripts that I use to manage dvbd
2
You will need to change /home/jak/bin in the scripts 
3
to reflect your own installation
4

  
utils/cgi/index.html
1
<html>
2
<head>
3
<title>DVBD Remote Control</title>
4
</head>
5
<body>
6
<h1>General</h1>
7
<ul>
8
  <li><a href="killav.cgi">Kill audio/visual</a></li>
9
  <li><a href="ampache/docs">Ampache</a></li>
10
  <li><a href="tv.cgi">TV recorder</a></li>
11
  <li><a href="media.cgi?catalogue=avi">Movies</a></li>
12
  <li><a href="media.cgi?catalogue=recordings">Recorded TV</a></li>
13
</ul>
14
<h1>TV Stations</h1>
15

  
16
<h2>Terrestrial</h2>
17
<ul>
18
  <li><a href="livetv.cgi?station=BBC%20ONE">BBC One</a></li>
19
  <li><a href="livetv.cgi?station=BBC%20TWO">BBC Two</a></li>
20
  <li><a href="livetv.cgi?station=ITV1">ITV 1</a></li>
21
  <li><a href="livetv.cgi?station=Channel%204">Channel 4</a></li>
22
  <li><a href="livetv.cgi?station=five">Five</a></li>
23
</ul>
24
<h2>Freeview</h2>
25
<ul>
26
  <li><a href="livetv.cgi?station=BBC%20NEWS%2024">BBC News 24</a></li>
27
  <li><a href="livetv.cgi?station=BBC%20THREE">BBC Three</a></li>
28
  <li><a href="livetv.cgi?station=BBC%20FOUR">BBC Four</a></li>
29
  <li><a href="livetv.cgi?station=ITV2">ITV 2</a></li>
30
  <li><a href="livetv.cgi?station=The%20HITS">The HITS</a></li>
31
  <li><a href="livetv.cgi?station=TMF">The Music Factory</a></li>
32
</ul>
33
<h1>Radio Stations</h1>
34
<h2>Streaming</h2>
35
<ul>
36
  <li><a href="streammusic.cgi?station=music1">Music One</a></li>
37
  <li><a href="streammusic.cgi?station=groovesalad">Groove Salad</a></li>
38
  <li><a href="streammusic.cgi?station=secretagent">Secret Agent</a></li>
39
  <li><a href="streammusic.cgi?station=rfi">Radio France Internationale</a></li>
40
  <li>Insert hyperlink:
41
  <form action="streammusic.cgi" method="GET"> 
42
    <input type="text" name="stationurl" size="100"> 
43
    <input type="hidden" name="station" value="userdef"> 
44
    <input type="submit" value="Submit"> 
45
  </form></li>
46
</ul>
47
<h2>Freeview</h2>
48
<ul>
49
  <li><a href="radio.cgi?station=BBC%20Radio%201">BBC Radio 1</a></li>
50
  <li><a href="radio.cgi?station=BBC%20Radio%202">BBC Radio 2</a></li>
51
  <li><a href="radio.cgi?station=BBC%20Radio%204">BBC Radio 4</a></li>
52
  <li><a href="radio.cgi?station=BBC%207">BBC Radio 7</a></li>
53
  <li><a href="radio.cgi?station=JAZZFM">Jazz FM</a></li>
54
</ul>
55
</body>
56

  
57
</html>
utils/cgi/killav.cgi
1
#!/usr/bin/perl
2
use CGI;
3
$q = new CGI;
4
print $q->header;
5
print "<pre>";
6
print "Killing Audio Visual Processes...\n";
7

  
8
system("/home/jak/bin/killav 2>&1");
9
print "</pre>";
10
fflush(stdout);
11

  
utils/cgi/livetv.cgi
1
#!/usr/bin/perl
2
use CGI;
3
use POSIX 'setsid';
4

  
5
$q = new CGI;
6
print $q->header;
7
print "<pre>";
8
$station = $q->param('station');
9
print "<pre>Play TV $station...\n</pre>";
10
$SIG{'CHLD'}="IGNORE";
11
if (fork() == 0) {
12
    daemonize();
13
    exec("/home/jak/bin/livetv", $station);
14
}
15

  
16
sub daemonize {
17
    chdir '/'               or die "Can't chdir to /: $!";
18
    open STDIN, '/dev/null' or die "Can't read /dev/null: $!";
19
    open STDOUT, '>/dev/null'
20
		   or die "Can't write to /dev/null: $!";
21
    defined(my $pid = fork) or die "Can't fork: $!";
22
    exit if $pid;
23
    setsid                  or die "Can't start a new session: $!";
24
    open STDERR, '>&STDOUT' or die "Can't dup stdout: $!";
25
}
26

  
utils/cgi/media.cgi
1
#!/usr/bin/perl
2
use CGI;
3
use POSIX 'setsid';
4
use URI::Escape;
5
use HTML::Entities;
6
use File::Find;
7
use Date::Format;
8
use sort 'stable';
9

  
10
%catalogues = ("avi" => "/mnt/media2/avi", 
11
	       "recordings" => "/mnt/media1/recordings");
12

  
13
$q = new CGI;
14
print $q->header;
15

  
16
$cataloguename = $q->param('catalogue');
17
$catalogue = $catalogues{$cataloguename};
18
if (!defined($cataloguename) || !defined($catalogue)) {
19
    print "<pre>Unrecognised catalogue $cataloguename (edit media.cgi)</pre>\n";
20
    exit 1;
21
}
22

  
23
if (defined($q->param('play'))) {
24
    # Play a particular movie
25

  
26
    $file = $q->param('play');
27
    $file =~ s/;//g;
28
    $file =~ s/^[\/.]*//g;
29

  
30
    $movie = $catalogue . "/" . $file;
31
    print "<pre>Play movie $movie...\n</pre>";
32
    $SIG{'CHLD'}="IGNORE";
33
    if (fork() == 0) {
34
	daemonize();
35
	exec("/home/jak/bin/playmovie", $movie);
36
    }
37
} else {
38
    # Get available movies
39
    @files = ();
40
    find({ wanted => sub {
41
	push @files, $File::Find::name
42
	    if (/\.(avi|mpg|wmv)/ && -f $File::Find::name);
43
	$File::Find::prune = 1 
44
	    if (/\.AppleDouble/);
45
    } }, $catalogue );
46

  
47
    # Sort
48
    @files = sort { -M $a <=> -M $b } @files;
49

  
50
    $prefixlength = length($catalogue) + 1;
51
    foreach $file (@files) {
52
	$shortfile = substr($file, $prefixlength);
53
	$playurl = "?catalogue=" . uri_escape($cataloguename) . "&play=" . uri_escape($shortfile);
54
	$playanchor = "<a href=\"$playurl\">" . encode_entities($shortfile) . "</a>";
55
	print "<tt>" . ctime((stat $file)[9]) . "</tt> $playanchor<br>";
56
    }
57
}
58

  
59

  
60
sub daemonize {
61
    chdir '/'               or die "Can't chdir to /: $!";
62
    open STDIN, '/dev/null' or die "Can't read /dev/null: $!";
63
    open STDOUT, '>/dev/null'
64
		   or die "Can't write to /dev/null: $!";
65
    defined(my $pid = fork) or die "Can't fork: $!";
66
    exit if $pid;
67
    setsid                  or die "Can't start a new session: $!";
68
    open STDERR, '>&STDOUT' or die "Can't dup stdout: $!";
69
}
70

  
utils/cgi/radio.cgi
1
#!/usr/bin/perl
2
use CGI;
3
use POSIX 'setsid';
4

  
5
$q = new CGI;
6
print $q->header;
7
print "<pre>";
8
$station = $q->param('station');
9
print "<pre>Play Radio $station...\n</pre>";
10
$SIG{'CHLD'}="IGNORE";
11
if (fork() == 0) {
12
    daemonize();
13
    exec("/home/jak/bin/radio", $station);
14
}
15

  
16
sub daemonize {
17
    chdir '/'               or die "Can't chdir to /: $!";
18
    open STDIN, '/dev/null' or die "Can't read /dev/null: $!";
19
    open STDOUT, '>/dev/null'
20
		   or die "Can't write to /dev/null: $!";
21
    defined(my $pid = fork) or die "Can't fork: $!";
22
    exit if $pid;
23
    setsid                  or die "Can't start a new session: $!";
24
    open STDERR, '>&STDOUT' or die "Can't dup stdout: $!";
25
}
26

  
utils/cgi/streammusic.cgi
1
#!/usr/bin/perl
2
use CGI;
3
use POSIX 'setsid';
4

  
5
%stations=('music1' => "http://www.m1live.com/listen/musicone_hi.pls",
6
	   'groovesalad' => "http://www.somafm.com/groovesalad.pls",
7
	   'secretagent' => "http://www.somafm.com/secretagent.pls",
8
	   'rfi' => "http://www.tv-radio.com/ondemand/rfi/mere/francais/../../../../station/rfi/rfi-20k.asx",
9
	   'userdef' => "userdef" );
10
	   
11
$q = new CGI;
12
print $q->header;
13
print "<pre>";
14
$station = $q->param('station');
15
if ($station eq "userdef") { 
16
	$stationurl= $q->param('stationurl');
17
}
18
else {
19
	$stationurl = $stations{$station};
20
}
21
unless (defined($stationurl)) {
22
    print("<pre>Unknown station $station (edit streammusic.cgi to add)</pre>");
23
    exit 1;
24
}
25

  
26
print "<pre>Play Web $station from $stationurl...\n</pre>";
27
$SIG{'CHLD'}="IGNORE";
28
if (fork() == 0) {
29
    daemonize();
30
    exec("/home/jak/bin/streammusic", $stationurl);
31
}
32

  
33
sub daemonize {
34
    chdir '/'               or die "Can't chdir to /: $!";
35
    open STDIN, '/dev/null' or die "Can't read /dev/null: $!";
36
    open STDOUT, '>/dev/null'
37
		   or die "Can't write to /dev/null: $!";
38
    defined(my $pid = fork) or die "Can't fork: $!";
39
    exit if $pid;
40
    setsid                  or die "Can't start a new session: $!";
41
    open STDERR, '>&STDOUT' or die "Can't dup http://www.somafm.com/secstdout: $!";
42
}
43

  
utils/killav
1
#!/bin/sh
2
sudo killall amarok
3
sudo killall juk
4
sudo killall artsd
5
sudo killall radio
6
sudo killall livetv
7
sudo killall streammusic
8
sudo killall playmovie
9
sudo killall mplayer
10

  
11
mpc stop
12
sudo fuser -k /dev/snd/*
13

  
utils/livetv
1
#!/bin/sh
2
PATH=$PATH:/home/jak/bin
3

  
4
trap "" TERM
5
killav >& /dev/null
6

  
7
cleanup()
8
{
9
    echo "Cleaning up..."
10
    kill %1
11
}
12
trap cleanup TERM
13
trap cleanup CHLD
14

  
15
export DISPLAY=:0.0
16
export HOME=/home/jak
17
dvbcat -p 5 dvb-t "$1" | mplayer -fs -really-quiet - >& /tmp/mplayer.log &
18
wait %1
19

  
utils/playmovie
1
#!/bin/sh
2
PATH=$PATH:/home/jak/bin
3

  
4
trap "" TERM
5
killav >& /dev/null
6

  
7
cleanup()
8
{
9
    echo "Cleaning up..."
10
    kill %1
11
    exit 0
12
}
13
trap cleanup TERM
14
trap cleanup CHLD
15

  
16
echo "playing [$1]" >/tmp/bob
17
export DISPLAY=:0.0
18
export HOME=/home/jak
19
mplayer -fs -really-quiet "$1" </dev/null > /tmp/mplayer.log &
20
wait %1
utils/radio
1
#!/bin/bash
2

  
3
#
4
# Requires dvbtools (for ts2es) and madplay and alsa-utils (for aplay)
5
#
6

  
7
PATH=$PATH:/home/jak/bin
8

  
9
trap "" TERM
10
killav >& /dev/null
11

  
12
apid=`grep "^$1:" ~/.tzap/channels.conf | awk -F ':' '{ print $12 }'`
13

  
14
if [[ -z "$apid" ]] ; then
15
	echo "Invalid channel $1"
16
	exit 1
17
fi
18

  
19
cleanup()
20
{
21
    echo "Cleaning up..."
22
    kill %1
23
}
24
trap cleanup TERM
25
trap cleanup CHLD
26

  
27
dvbcat -p 5 dvb-t "$1" | \
28
ts2es $apid | \
29
madplay -b16 -R48000 -o raw:- - | \
30
aplay -r 48000 -f S16_LE -c 2 &
31

  
32
wait %1
utils/streammusic
1
#!/bin/sh
2

  
3
#
4
# Requires music player daemon (mpd) and console (mpc), and mplayer
5
#
6

  
7
PATH=$PATH:/home/jak/bin
8

  
9
playlist=$1
10

  
11
trap "" TERM
12
killav >& /dev/null
13

  
14
cleanup()
15
{
16
    echo "Cleaning up..."
17
    kill %1
18
    exit 0
19
}
20
trap cleanup TERM
21
trap cleanup CHLD
22

  
23
case "$playlist" in 
24
   *.pls)
25
   	mpc clear
26
	lynx -source "$playlist" | grep File | sed -e 's/^File.*=//' | \
27
	while read url ; do 
28
	   mpc add "$url"
29
	done
30
	mpc play
31
	;;
32

  
33
   *.asx)
34
	lynx -source "$playlist" | grep href= | sed -e 's/^.*href="//' -e 's/".*$//' | \
35
	while read url ; do 
36
	   echo Playing $url
37
	   mplayer -cache 32 "$url" </dev/null &
38
	   wait %1
39
	done
40
	;;
41
esac

Also available in: Unified diff