Mailing List archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[vdr] new script: epg2tt.pl



Hello everybody.

I have done some work to convert epg2html.pl into a script which I
call epg2tt.pl that creates a single html page containing a table with
all the program contents of the next hours.

Feel happy to play with it.

Klaus, if you like, feel free to include this into future releases of
vdr.

Robert

---
#!/usr/bin/perl

# A simple EPG to HTML time table converter
#
# Converts the EPG data written by 'vdr' into the file /video/epg.data
# into a simple HTML time table to stdout.
#
# Usage: epg2tt.pl < /video/epg.data > timetable.html
#
# Copyright (C) 2003  Robert Schiele <rschiele@uni-mannheim.de>
#
# This file is distributed under the same license as vdr by Klaus
# Schmidinger.  See the main source file 'vdr.c' for copyright
# information.
#
# $Id: epg2tt.pl -.- 2003/01/27 21:40:17 robert Exp $

@Index = ();

sub GetTime
{
  return substr(localtime(shift), 11, 5);
}

sub Tags
{
  my $s = shift;
  $s =~ s/\&/&amp;/g;
  $s =~ s/</&lt;/g;
  $s =~ s/>/&gt;/g;
  return $s;
}

my $realtime = (int (time / 60)) * 60;
my $maxtime = 120;
my $hpartition = 15;
my $vpartition = 5;

while (<>) {
    chomp;
    if (/^C ([^ ]+) *(.*)/) {
	my $Channel = $2;
	$Channel = Tags($Channel);
	my %Events = ();
	while (<>) {
	    if (/^E (.*?) (.*?) ([^ ]*)/) {
		(my $Time, $Duration) = ($2, $3);
		my $Title = "", $Subtitle = "", $Description = "";
		while (<>) {
		    if    (/^T (.*)/) { $Title       = Tags($1); }
		    elsif (/^S (.*)/) { $Subtitle    = Tags($1); }
		    elsif (/^D (.*)/) { $Description = Tags($1); }
		    elsif (/^e/) {
			$Events{$Time} = [($Duration, $Title, $Subtitle,
					   $Description)];
			last;
		    }
		}
	    } elsif (/^c/) {
		my @Schedule = ();
		my $curtime = $realtime;
		my $oldtitle = "";
		push(@Schedule, "<tr><th>$Channel</th>\n");
		for $t (sort keys %Events) {
		    (my $Duration, $Title, $Subtitle, $Description) =
			@{$Events{$t}};
		    if (($t - $realtime) < 60 * $maxtime) {
			if (($t - $curtime) > 0) {
			    push(@Schedule, '<td colspan="' .
				 (int (($t - $curtime) / 60)) . '">' .
				 $oldtitle . '</td>');
			    $curtime = $t;
			}
			$oldtitle = "<b>$Title</b>";
			$oldtitle .= "<br/><i>$Subtitle</i>" if ($Subtitle);
			$oldtitle .= "<br/>$Description" if ($Description);
		    }
		}
		push(@Schedule, '<td colspan="' .
		     (int (($realtime + 60 * $maxtime - $curtime) / 60)) .
		     '">' . $oldtitle . '</td></tr>');
		push(@Index, qq{@Schedule});
		last;
	    }
	}
    }
}

print << 'EOT';
<?xml version="1.0" encoding="iso-8859-1"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
    "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd";>
<html><head><title>Time Table</title><style type="text/css">
  th { background: black; color: white; }
  td { background: silver; color: black; }
</style></head><body><table>
EOT

my @Schedule = ();
my $curtime = $realtime;
my $oldtitle = GetTime($realtime);
push(@Schedule, '<tr><td/>');
for (my $t = ((int ($realtime / 60 / $hpartition)) + 1) * 60 * $hpartition;
     $t < ($realtime + 60 * $maxtime); $t += 60 * 15) {
    push(@Schedule,
	 '<th colspan="' . (int (($t - $curtime) / 60)) . '">' .
	 $oldtitle . '</th>' . "\n");
    $curtime = $t;
    $oldtitle = GetTime($t);
}
push(@Schedule, '<th colspan="' .
     (int (($realtime + 60 * $maxtime - $curtime) / 60)) . '">' . $oldtitle .
     '</th></tr>');

my $vcount = 0;
for (sort { lc($a) cmp lc($b) } @Index) {
    if ($vcount == 0) {
	print @Schedule;
	$vcount = $vpartition;
    }
    $vcount--;
    print;
}
print '</table></body></html>';
---

-- 
Robert Schiele			Tel.: +49-621-181-2517
Dipl.-Wirtsch.informatiker	mailto:rschiele@uni-mannheim.de

-- Attached file included as plaintext by Listar --

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)

iQEVAwUBPjWlsMQAnns5HcHpAQGlCQf+JBVxKW+38i6D39mxEjRh0iuNu7ARvRdS
ZspCFCaWK587+5nyrgZCGm1V//B8ml6ef+Hwq2oE2ram21ZhEYdNzgXZQlqE5gi8
OJIA7srhnyPSlnRAbRhIm9Tqs7MuYzp0qDo7fnCrgMyG9Gzd0+fyrmianVvoXHpg
aoH+AY2hoTgbWDbNs7zr0NDhyOBwEVV/RMvfPw5FDrHgZFUwHLrCQz+icSMBpfaZ
N1RiHSPIKAJPe9UgWy2fiGldLhSXIlKmMlB9vKgVa2rWAKW6MfQnAgTVR0As3T2+
rrnGsux82pPc4+ZH6rYWl0ffgO1bqP5WCKrvEC29YKZprtHNEj9n4g==
=b6Hg
-----END PGP SIGNATURE-----



-- 
Info:
To unsubscribe send a mail to listar@linuxtv.org with "unsubscribe vdr" as subject.



Home | Main Index | Thread Index