Revision 4e104f20

View differences:

configure.ac
1
AC_INIT(dvbd, 0.6.0)
1
AC_INIT(dvbd, 0.7.0)
2 2
AC_CONFIG_SRCDIR(src/dvbd.cpp)
3 3
AM_INIT_AUTOMAKE
4 4
AM_CONFIG_HEADER(config.h)
dvbdguide/COPYING
1
		    GNU GENERAL PUBLIC LICENSE
2
		       Version 2, June 1991
3

  
4
 Copyright (C) 1989, 1991 Free Software Foundation, Inc.
5
                          675 Mass Ave, Cambridge, MA 02139, USA
6
 Everyone is permitted to copy and distribute verbatim copies
7
 of this license document, but changing it is not allowed.
8

  
9
			    Preamble
10

  
11
  The licenses for most software are designed to take away your
12
freedom to share and change it.  By contrast, the GNU General Public
13
License is intended to guarantee your freedom to share and change free
14
software--to make sure the software is free for all its users.  This
15
General Public License applies to most of the Free Software
16
Foundation's software and to any other program whose authors commit to
17
using it.  (Some other Free Software Foundation software is covered by
18
the GNU Library General Public License instead.)  You can apply it to
19
your programs, too.
20

  
21
  When we speak of free software, we are referring to freedom, not
22
price.  Our General Public Licenses are designed to make sure that you
23
have the freedom to distribute copies of free software (and charge for
24
this service if you wish), that you receive source code or can get it
25
if you want it, that you can change the software or use pieces of it
26
in new free programs; and that you know you can do these things.
27

  
28
  To protect your rights, we need to make restrictions that forbid
29
anyone to deny you these rights or to ask you to surrender the rights.
30
These restrictions translate to certain responsibilities for you if you
31
distribute copies of the software, or if you modify it.
32

  
33
  For example, if you distribute copies of such a program, whether
34
gratis or for a fee, you must give the recipients all the rights that
35
you have.  You must make sure that they, too, receive or can get the
36
source code.  And you must show them these terms so they know their
37
rights.
38

  
39
  We protect your rights with two steps: (1) copyright the software, and
40
(2) offer you this license which gives you legal permission to copy,
41
distribute and/or modify the software.
42

  
43
  Also, for each author's protection and ours, we want to make certain
44
that everyone understands that there is no warranty for this free
45
software.  If the software is modified by someone else and passed on, we
46
want its recipients to know that what they have is not the original, so
47
that any problems introduced by others will not reflect on the original
48
authors' reputations.
49

  
50
  Finally, any free program is threatened constantly by software
51
patents.  We wish to avoid the danger that redistributors of a free
52
program will individually obtain patent licenses, in effect making the
53
program proprietary.  To prevent this, we have made it clear that any
54
patent must be licensed for everyone's free use or not licensed at all.
55

  
56
  The precise terms and conditions for copying, distribution and
57
modification follow.
58

59
		    GNU GENERAL PUBLIC LICENSE
60
   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61

  
62
  0. This License applies to any program or other work which contains
63
a notice placed by the copyright holder saying it may be distributed
64
under the terms of this General Public License.  The "Program", below,
65
refers to any such program or work, and a "work based on the Program"
66
means either the Program or any derivative work under copyright law:
67
that is to say, a work containing the Program or a portion of it,
68
either verbatim or with modifications and/or translated into another
69
language.  (Hereinafter, translation is included without limitation in
70
the term "modification".)  Each licensee is addressed as "you".
71

  
72
Activities other than copying, distribution and modification are not
73
covered by this License; they are outside its scope.  The act of
74
running the Program is not restricted, and the output from the Program
75
is covered only if its contents constitute a work based on the
76
Program (independent of having been made by running the Program).
77
Whether that is true depends on what the Program does.
78

  
79
  1. You may copy and distribute verbatim copies of the Program's
80
source code as you receive it, in any medium, provided that you
81
conspicuously and appropriately publish on each copy an appropriate
82
copyright notice and disclaimer of warranty; keep intact all the
83
notices that refer to this License and to the absence of any warranty;
84
and give any other recipients of the Program a copy of this License
85
along with the Program.
86

  
87
You may charge a fee for the physical act of transferring a copy, and
88
you may at your option offer warranty protection in exchange for a fee.
89

  
90
  2. You may modify your copy or copies of the Program or any portion
91
of it, thus forming a work based on the Program, and copy and
92
distribute such modifications or work under the terms of Section 1
93
above, provided that you also meet all of these conditions:
94

  
95
    a) You must cause the modified files to carry prominent notices
96
    stating that you changed the files and the date of any change.
97

  
98
    b) You must cause any work that you distribute or publish, that in
99
    whole or in part contains or is derived from the Program or any
100
    part thereof, to be licensed as a whole at no charge to all third
101
    parties under the terms of this License.
102

  
103
    c) If the modified program normally reads commands interactively
104
    when run, you must cause it, when started running for such
105
    interactive use in the most ordinary way, to print or display an
106
    announcement including an appropriate copyright notice and a
107
    notice that there is no warranty (or else, saying that you provide
108
    a warranty) and that users may redistribute the program under
109
    these conditions, and telling the user how to view a copy of this
110
    License.  (Exception: if the Program itself is interactive but
111
    does not normally print such an announcement, your work based on
112
    the Program is not required to print an announcement.)
113

114
These requirements apply to the modified work as a whole.  If
115
identifiable sections of that work are not derived from the Program,
116
and can be reasonably considered independent and separate works in
117
themselves, then this License, and its terms, do not apply to those
118
sections when you distribute them as separate works.  But when you
119
distribute the same sections as part of a whole which is a work based
120
on the Program, the distribution of the whole must be on the terms of
121
this License, whose permissions for other licensees extend to the
122
entire whole, and thus to each and every part regardless of who wrote it.
123

  
124
Thus, it is not the intent of this section to claim rights or contest
125
your rights to work written entirely by you; rather, the intent is to
126
exercise the right to control the distribution of derivative or
127
collective works based on the Program.
128

  
129
In addition, mere aggregation of another work not based on the Program
130
with the Program (or with a work based on the Program) on a volume of
131
a storage or distribution medium does not bring the other work under
132
the scope of this License.
133

  
134
  3. You may copy and distribute the Program (or a work based on it,
135
under Section 2) in object code or executable form under the terms of
136
Sections 1 and 2 above provided that you also do one of the following:
137

  
138
    a) Accompany it with the complete corresponding machine-readable
139
    source code, which must be distributed under the terms of Sections
140
    1 and 2 above on a medium customarily used for software interchange; or,
141

  
142
    b) Accompany it with a written offer, valid for at least three
143
    years, to give any third party, for a charge no more than your
144
    cost of physically performing source distribution, a complete
145
    machine-readable copy of the corresponding source code, to be
146
    distributed under the terms of Sections 1 and 2 above on a medium
147
    customarily used for software interchange; or,
148

  
149
    c) Accompany it with the information you received as to the offer
150
    to distribute corresponding source code.  (This alternative is
151
    allowed only for noncommercial distribution and only if you
152
    received the program in object code or executable form with such
153
    an offer, in accord with Subsection b above.)
154

  
155
The source code for a work means the preferred form of the work for
156
making modifications to it.  For an executable work, complete source
157
code means all the source code for all modules it contains, plus any
158
associated interface definition files, plus the scripts used to
159
control compilation and installation of the executable.  However, as a
160
special exception, the source code distributed need not include
161
anything that is normally distributed (in either source or binary
162
form) with the major components (compiler, kernel, and so on) of the
163
operating system on which the executable runs, unless that component
164
itself accompanies the executable.
165

  
166
If distribution of executable or object code is made by offering
167
access to copy from a designated place, then offering equivalent
168
access to copy the source code from the same place counts as
169
distribution of the source code, even though third parties are not
170
compelled to copy the source along with the object code.
171

172
  4. You may not copy, modify, sublicense, or distribute the Program
173
except as expressly provided under this License.  Any attempt
174
otherwise to copy, modify, sublicense or distribute the Program is
175
void, and will automatically terminate your rights under this License.
176
However, parties who have received copies, or rights, from you under
177
this License will not have their licenses terminated so long as such
178
parties remain in full compliance.
179

  
180
  5. You are not required to accept this License, since you have not
181
signed it.  However, nothing else grants you permission to modify or
182
distribute the Program or its derivative works.  These actions are
183
prohibited by law if you do not accept this License.  Therefore, by
184
modifying or distributing the Program (or any work based on the
185
Program), you indicate your acceptance of this License to do so, and
186
all its terms and conditions for copying, distributing or modifying
187
the Program or works based on it.
188

  
189
  6. Each time you redistribute the Program (or any work based on the
190
Program), the recipient automatically receives a license from the
191
original licensor to copy, distribute or modify the Program subject to
192
these terms and conditions.  You may not impose any further
193
restrictions on the recipients' exercise of the rights granted herein.
194
You are not responsible for enforcing compliance by third parties to
195
this License.
196

  
197
  7. If, as a consequence of a court judgment or allegation of patent
198
infringement or for any other reason (not limited to patent issues),
199
conditions are imposed on you (whether by court order, agreement or
200
otherwise) that contradict the conditions of this License, they do not
201
excuse you from the conditions of this License.  If you cannot
202
distribute so as to satisfy simultaneously your obligations under this
203
License and any other pertinent obligations, then as a consequence you
204
may not distribute the Program at all.  For example, if a patent
205
license would not permit royalty-free redistribution of the Program by
206
all those who receive copies directly or indirectly through you, then
207
the only way you could satisfy both it and this License would be to
208
refrain entirely from distribution of the Program.
209

  
210
If any portion of this section is held invalid or unenforceable under
211
any particular circumstance, the balance of the section is intended to
212
apply and the section as a whole is intended to apply in other
213
circumstances.
214

  
215
It is not the purpose of this section to induce you to infringe any
216
patents or other property right claims or to contest validity of any
217
such claims; this section has the sole purpose of protecting the
218
integrity of the free software distribution system, which is
219
implemented by public license practices.  Many people have made
220
generous contributions to the wide range of software distributed
221
through that system in reliance on consistent application of that
222
system; it is up to the author/donor to decide if he or she is willing
223
to distribute software through any other system and a licensee cannot
224
impose that choice.
225

  
226
This section is intended to make thoroughly clear what is believed to
227
be a consequence of the rest of this License.
228

229
  8. If the distribution and/or use of the Program is restricted in
230
certain countries either by patents or by copyrighted interfaces, the
231
original copyright holder who places the Program under this License
232
may add an explicit geographical distribution limitation excluding
233
those countries, so that distribution is permitted only in or among
234
countries not thus excluded.  In such case, this License incorporates
235
the limitation as if written in the body of this License.
236

  
237
  9. The Free Software Foundation may publish revised and/or new versions
238
of the General Public License from time to time.  Such new versions will
239
be similar in spirit to the present version, but may differ in detail to
240
address new problems or concerns.
241

  
242
Each version is given a distinguishing version number.  If the Program
243
specifies a version number of this License which applies to it and "any
244
later version", you have the option of following the terms and conditions
245
either of that version or of any later version published by the Free
246
Software Foundation.  If the Program does not specify a version number of
247
this License, you may choose any version ever published by the Free Software
248
Foundation.
249

  
250
  10. If you wish to incorporate parts of the Program into other free
251
programs whose distribution conditions are different, write to the author
252
to ask for permission.  For software which is copyrighted by the Free
253
Software Foundation, write to the Free Software Foundation; we sometimes
254
make exceptions for this.  Our decision will be guided by the two goals
255
of preserving the free status of all derivatives of our free software and
256
of promoting the sharing and reuse of software generally.
257

  
258
			    NO WARRANTY
259

  
260
  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
262
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
266
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
267
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268
REPAIR OR CORRECTION.
269

  
270
  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278
POSSIBILITY OF SUCH DAMAGES.
279

  
280
		     END OF TERMS AND CONDITIONS
281

282
	Appendix: How to Apply These Terms to Your New Programs
283

  
284
  If you develop a new program, and you want it to be of the greatest
285
possible use to the public, the best way to achieve this is to make it
286
free software which everyone can redistribute and change under these terms.
287

  
288
  To do so, attach the following notices to the program.  It is safest
289
to attach them to the start of each source file to most effectively
290
convey the exclusion of warranty; and each file should have at least
291
the "copyright" line and a pointer to where the full notice is found.
292

  
293
    <one line to give the program's name and a brief idea of what it does.>
294
    Copyright (C) 19yy  <name of author>
295

  
296
    This program is free software; you can redistribute it and/or modify
297
    it under the terms of the GNU General Public License as published by
298
    the Free Software Foundation; either version 2 of the License, or
299
    (at your option) any later version.
300

  
301
    This program is distributed in the hope that it will be useful,
302
    but WITHOUT ANY WARRANTY; without even the implied warranty of
303
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
304
    GNU General Public License for more details.
305

  
306
    You should have received a copy of the GNU General Public License
307
    along with this program; if not, write to the Free Software
308
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
309

  
310
Also add information on how to contact you by electronic and paper mail.
311

  
312
If the program is interactive, make it output a short notice like this
313
when it starts in an interactive mode:
314

  
315
    Gnomovision version 69, Copyright (C) 19yy name of author
316
    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317
    This is free software, and you are welcome to redistribute it
318
    under certain conditions; type `show c' for details.
319

  
320
The hypothetical commands `show w' and `show c' should show the appropriate
321
parts of the General Public License.  Of course, the commands you use may
322
be called something other than `show w' and `show c'; they could even be
323
mouse-clicks or menu items--whatever suits your program.
324

  
325
You should also get your employer (if you work as a programmer) or your
326
school, if any, to sign a "copyright disclaimer" for the program, if
327
necessary.  Here is a sample; alter the names:
328

  
329
  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330
  `Gnomovision' (which makes passes at compilers) written by James Hacker.
331

  
332
  <signature of Ty Coon>, 1 April 1989
333
  Ty Coon, President of Vice
334

  
335
This General Public License does not permit incorporating your program into
336
proprietary programs.  If your program is a subroutine library, you may
337
consider it more useful to permit linking proprietary applications with the
338
library.  If this is what you want to do, use the GNU Library General
339
Public License instead of this License.
dvbdguide/Makefile
1
VERSION=0.6.0
2
PROGRAM=dvbdguide-$(VERSION)
3
TMP=/tmp
4
DEST=$(TMP)/$(PROGRAM)
5
FILES=Makefile tv.cgi tv.xsl tv.css favourites.xml README COPYING
6

  
7
dist: 
8
	-rm -rf $(DEST)
9
	mkdir $(DEST) 
10
	cp $(FILES) $(DEST)
11
	tar -C $(TMP) -czf ../$(PROGRAM).tar.gz $(PROGRAM)
dvbdguide/README
1
dvbdguide (jak@users.sourceforge.net)
2

  
3
Installing the TV Guide CGI script
4
----------------------------------
5

  
6
Prerequisites:
7
   xsltproc - http://www.xmlsoft.org/
8

  
9
   perl - http://www.perl.com
10

  
11
   apache - http://www.apache.org/
12
      or other webserver supporting CGI
13
     
14
   dvbd - http://dvbd.sourceforge.net/
15
     
16
   Debian users: apt-get install perl xsltproc xmltv 
17
                 dpkg -i dvbd*.deb
18

  
19
1. This program is written to more easily schedule programs
20
   with dvbd. Make sure that the utility programs dvblist and
21
   dvbsched are in your path since they are invoked by tv.cgi
22
   script.
23

  
24
2. The TV Guide is based on an XMLTV compatible data source.
25
   You need to ensure that the listings for today are in a 
26
   file called listings.0.xml. Listings for tomorrow (if you
27
   have them should be in listings.1.xml, the day after
28
   in listings.2.xml and so on). 
29
   
30
   I use bleb2xmltv (http://www.doc.ic.ac.uk/~jak97/bleb/bleb2xmltv.tar.bz2)
31
   for basic UK listings, although the RadioTimes grabber should
32
   work well too. Since bleb2xmltv automatically rotates it's listings files
33
   making symbolic links to the /var/cache/bleb is good enough:
34

  
35
       listings.0.xml -> /var/cache/bleb/listings.0.xml
36
       listings.1.xml -> /var/cache/bleb/listings.1.xml
37
       ...
38

  
39
3. If you are using Apache, make sure that Apache has user directories and CGI enabled.
40
   For Apache2 make sure that the following is in your /etc/apache2/apache2.conf.
41
   NB ExecCGI option.
42
   
43
----8<----
44
UserDir public_html
45

  
46
<Directory /home/*/public_html>
47
	AllowOverride FileInfo AuthConfig Limit
48
	Options Indexes SymLinksIfOwnerMatch ExecCGI
49
</Directory>
50
----8<----
51

  
52
3. Make a ~/public_html directory
53

  
54
4. Copy the tv.cgi tv.xsl tv.css to ~/public_html
55
   cp tv.cgi tv.xsl tv.css ~/public_html
56

  
57
5. Make sure that listings.xml for today's TV listings is 
58
   present in ~/public_html
59

  
60
6. Make a recordings directory somewhere on your computer.
61
   Edit ~/public_html/tv.cgi:
62

  
63
   $recordingPath = "/home/jak/recordings";
64

  
65
   to point to a directory that you want to record to. 
66

  
67
   NB: the directory should be owned by you, but in the
68
   dvdb group, user and group writable.
69

  
70
7. Add any xmltv id to DVB id mappings in ~/public_html/tv.cgi
71
   I have added the ones for the channels I watch on UK freeview.
72

  
73
8. Assuming that dvbd is properly configured and running,
74
   open the web browser at http://yourhost/~youruser/tv.cgi
75
   Hopefully all should work!
76

  
77
9. If you have different favourite programs to me, edit
78
   ~/public_html/favourites.xml as appropriate.
79

  
80
10. Please send comments, suggestions, patches and contributions 
81
    to jak@users.sourceforge.net
82

  
83
TROUBLESHOOTING
84
---------------
85

  
86
1. If the page comes up blank, check that the listings.0.xml files are
87
   present and correct.
88

  
89
ACKNOWLEDGEMENTS
90
----------------
91

  
92
This code is based off tv-control by 
93
xmltvcntl@SlashHomeSlashAdrian.fsnet.co.uk
dvbdguide/favourites.xml
1
<favourites>
2
  <programme title="The Alan Clark Diaries"/>
3
  <programme title="Child of Our Time"/>
4
  <programme title="University Challenge"/>
5
  <programme title="Red Dwarf"/>
6
  <programme title="Alias"/>
7
  <programme title="Enterprise"/>
8
  <programme title="T4:Star Trek: Enterprise"/>
9
  <programme title="Monkey Dust"/>
10
  <programme title="Little Britain"/>
11
  <programme title="Charmed"/>
12
  <programme title="Robot Wars"/>
13
</favourites>
dvbdguide/tv.cgi
1
#!/usr/bin/perl
2

  
3
#   Copyright 2004 John Knottenbelt
4
#
5
#     This program is free software; you can redistribute it and/or modify
6
#     it under the terms of the GNU General Public License as published by
7
#     the Free Software Foundation; either version 2 of the License, or
8
#     (at your option) any later version.
9
#
10
#     This program is distributed in the hope that it will be useful,
11
#     but WITHOUT ANY WARRANTY; without even the implied warranty of
12
#     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
#     GNU General Public License for more details.
14
#
15
#     You should have received a copy of the GNU General Public License
16
#     along with this program; if not, write to the Free Software
17
#     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
18
#
19

  
20
#
21
# Possibilities to speed this up:
22
#  1. use libxml-libxslt-perl and mod_perl for apache (keep the compiled stylesheet)
23
#
24

  
25
use CGI;
26
use File::Temp qw/:POSIX/;
27
use Time::Local;
28

  
29
$recordingPath = "/home/jak/recordings";
30

  
31
%xmltvToDVB = ( "bbc1.bbc.co.uk" => "dvb-t/BBC ONE",
32
                "south-east.bbc1.bbc.co.uk" => "dvb-t/BBC ONE",
33
		"bbc2.bbc.co.uk" => "dvb-t/BBC TWO",
34
		"south-east.bbc2.bbc.co.uk" => "dvb-t/BBC TWO",
35
		"choice.bbc.co.uk" => "dvb-t/BBC THREE",
36
		"bbc3.bbc.co.uk" => "dvb-t/BBC THREE",
37
		"knowledge.bbc.co.uk" => "dvb-t/BBC FOUR",
38
		"news-24.bbc.co.uk" => "dvb-t/BBC NEWS 24", 
39
		"parliament.bbc.co.uk" => "dvb-t/BBC PARLMNT",
40
		"carlton.com" => "dvb-t/ITV 1",
41
		"itv2.itv.co.uk" => "dvb-t/ITV 2",
42
		"channel4.com" => "dvb-t/Channel 4",
43
		"channel5.co.uk" => "dvb-t/five" );
44

  
45
# Maximum number of days into the future
46
$maxoffset = 31;
47

  
48
sub listings {
49
  my $offset = shift;
50
  return "listings.$offset.xml" 
51
}
52

  
53
sub printScheduled ($$$) {
54
    my $output = shift;
55
    my $schedule = shift;
56
    my $element = shift;
57

  
58
    print $output "  <$element>\n";
59
    foreach my $r (@$schedule) {
60
	# <programme start="20040102011500 +0000" channel="bbc2.bbc.co.uk"/>
61
	print $output "    <programme start=\"$r->{start}\" channel=\"$r->{channel}\"/>\n";
62
    }
63
    print $output "  </$element>\n";
64
}
65

  
66
sub toIsoDateTime ($) {
67
    my $time = shift;
68
    ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time);
69
    return sprintf("%04d%02d%02d%02d%02d%02d", 
70
		   1900 + $year,$mon + 1,$mday, $hour,$min,$sec);
71
    
72
}
73

  
74
sub printFile($$) {
75
    my ($output, $filename) = @_;
76

  
77
    open INPUT, "<$filename"
78
	or return undef;
79
    
80
    while (<INPUT>) {
81
	print $output $_;
82
    }
83
    close INPUT;
84
}
85

  
86
sub printXml ($$$$) {
87
    my ($output, $scheduled, $recordings, $offset) = @_;
88

  
89
    open LISTING, "<" . listings($offset) 
90
	or die "Failed to open listings.xml: $!";
91
    
92
    $line = <LISTING>;
93
    print $output $line;
94

  
95
    $line = <LISTING>;
96
    print $output $line;
97

  
98
    my $now = toIsoDateTime(time);
99
    print $output "<root>\n";
100
    print $output "  <now>$now</now>\n";
101
    print $output "  <offset>$offset</offset>\n";
102

  
103
    printDays($output);
104
    printFile($output, "favourites.xml");
105
    printScheduled($output, $scheduled, "scheduled");
106
    printScheduled($output, $recordings, "recordings");
107

  
108
    while (<LISTING>) {
109
	print $output $_;
110
    }
111
    close LISTING;
112
    print $output "</root>\n";
113
}
114

  
115
sub printDays ($) {
116
    my ($output) = @_;
117
    my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
118
    my @days = ("Sun", "Mon", "Tue", "Wed", "Thur", "Fri", "Sat");
119

  
120
    # Earlier hours count as yesterday
121
    $wday = ($wday + 6) % 7 if ($hour < 6);
122

  
123
    for (my $o = 0; $o <= $maxoffset; $o++) {
124
	my $day = $days[($wday + $o) % 7];
125
	print $output "<day offset=\"$o\">$day</day>\n";
126
    }
127
}
128

  
129
sub printHtml ($$$) {
130
    my ($scheduled, $recordings, $offset) = @_;
131

  
132
    my $temp = tmpnam();
133
    open PIPE, "|/usr/bin/xsltproc --novalid tv.xsl - >$temp"
134
	or die "Failed to open XSLT pipe: $!\n";
135
    printXml(PIPE, $scheduled, $recordings, $offset);
136
    close PIPE;
137
    
138
    open TEMP, "<$temp"
139
	or die "Failed to open temp file: $temp: $!\n";
140
    while (<TEMP>) {
141
	print;
142
    }
143
    close TEMP;
144
    unlink $temp;
145

  
146
    # For debugging, save the XML to /tmp/state.xml
147
    open DEBUG, ">/tmp/state.xml"
148
	or die "Failed to open debug file state.xml: $!\n";
149
    printXml(DEBUG, $scheduled, $recordings, $offset);
150
    close DEBUG;
151
}
152

  
153
sub unescapeWS {
154
    my $arg = shift;
155
    # Unescape the WS
156
    $arg =~ s%\\_% %g;
157
    $arg =~ s%\\\\%\\%g;
158
    return $arg;
159
}
160

  
161
sub getScheduled {
162
    my @scheduled = ();
163
    open REC, "dvblist -h|";
164
    while (<REC>) {
165
	if (/^ (\d+) (\d+) (\S+) (\S+) (\S+) (\S+) (\S+) (\S+) (\S+) (\S+) \[(\S+)\]$/) {
166
	    my $job = $1;
167
	    my $path = unescapeWS($10);
168
	    my $extra = unescapeWS($11);
169

  
170
	    if ($extra =~ m%^(\S+) - (.+)$%) {
171

  
172
		my $channel = $1;
173
		my $start = "$2";
174

  
175
		my $r = { job => $job,
176
			  path => $path,
177
			  extra => $extra,
178
			  start => $start,
179
			  channel => $channel };
180

  
181
		push @scheduled, $r;
182
	    }
183
	}
184
    }
185
    close REC;
186
    return \@scheduled;
187
};
188

  
189
sub getRecordings {
190
    my @recordings = ();
191
    open REC, "dvblist -c|";
192
    while (<REC>) {
193
	if (/(\d+) (\d+) (\S+) (\S+) (\S+) (\S+) (\S+) (\S+) (\S+) (\S+) \[(\S+)\]$/) {
194
	    my $job = $1;
195
	    my $path = unescapeWS($10);
196
	    my $extra = unescapeWS($11);
197

  
198
	    if ($extra =~ m%^(\S+) - (.+)$%) {
199

  
200
		my $channel = $1;
201
		my $start = "$2";
202

  
203
		my $r = { job => $job,
204
			  path => $path,
205
			  extra => $extra,
206
			  start => $start,
207
			  channel => $channel };
208

  
209
		push @recordings, $r;
210
	    }
211
	}
212
    }
213
    close REC;
214
    return \@recordings;
215
};
216

  
217
sub alreadyScheduled {
218
    my ($schedule, $channel, $start) = @_;
219

  
220
    foreach my $r (@$schedule) {
221
	# <programme start="20040102011500 +0000" channel="bbc2.bbc.co.uk"/>
222
	return 1 if ($r->{start} eq $start &&
223
		     $r->{channel} eq $channel) ;
224
    }
225
    
226
    return undef;
227
}
228

  
229
sub toSeconds {
230
    my $iso = shift;
231
    
232
    if ($iso =~ /^(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)/) {
233
	my $sec = $6;
234
	my $min = $5;
235
	my $hour = $4;
236
	my $mday = $3;
237
	my $mon = $2 - 1;
238
	my $year = $1 - 1900;
239
	return timelocal($sec,$min,$hour,$mday,$mon,$year);
240
    }
241
}
242

  
243
sub calcDuration {
244
    my ($start, $stop) = @_;
245
    my $startSec = toSeconds($start);
246
    my $stopSec = toSeconds($stop);
247
    return $stopSec - $startSec;
248
}
249

  
250
sub toPosixDateTime {
251
    my $iso = shift;
252

  
253
    if ($iso =~ /^(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)/) {
254
	my $sec = $6;
255
	my $min = $5;
256
	my $hour = $4;
257
	my $mday = $3;
258
	my $mon = $2;
259
	my $year = $1;
260
	return "$hour:$min $year-$mon-$mday";
261
    }
262
}
263

  
264
sub cancel {
265
    my ($schedule, $recordings, $channel, $title, $subtitle, $start, $stop) = @_;
266

  
267
    foreach my $r (@$schedule, @$recordings) {
268
	# <programme start="20040102011500 +0000" channel="bbc2.bbc.co.uk"/>
269
	if ($r->{start} eq $start && $r->{channel} eq $channel) {
270
	    system("dvbsched -r $r->{job}");
271
	    return 1;
272
	}
273
    }
274
    return undef;
275
}
276

  
277
# Certain characters are invalid in a filename
278
# For example '/' which is the directory separator
279
# In order for the permissions check in dvbd to
280
# pass we need to remove any unintentional /
281

  
282
sub makeValidFilename {
283
    my $a = shift;
284
    $a =~ s%/%:%g;		# / is illegal in filenames
285
    return $a;
286
}
287

  
288
sub schedule {
289
    my ($schedule, $channel, $title, $subtitle, $start, $stop) = @_;
290
    my $duration = calcDuration($start, $stop);
291
    
292
    if (!alreadyScheduled($schedule, $channel, $start)) {
293
	# print "Scheduling: [$channel] [$xmltvToDVB{$channel}] $title ($subtitle)\n";
294
	if ($xmltvToDVB{$channel} =~ m%^(.*)/(.*)$%) {
295
	    my $dvbType = $1;
296
	    my $dvbChannel = $2;
297

  
298
	    # Start the recording 1 minute early
299
	    # Duration is 4 minutes longer
300

  
301
	    my $startTime = toPosixDateTime(toIsoDateTime(toSeconds($start) - 60));
302
	    my $dur = int (($duration + 240 + 59) / 60);
303

  
304
	    my $oktitle = $title;
305
	    my $outputFile = "$recordingPath/" . makeValidFilename($title);
306
	    if ($subtitle ne "") {
307
		$outputFile .= " - " . makeValidFilename($subtitle);
308
	    }
309

  
310
	    $outputFile .= ".mpg";
311

  
312
	    my @command = ("dvbsched", 
313
			   "-P", 
314
			   "-e", "$channel - $start",
315
			   "-n",
316
			   "$dvbType", "$dvbChannel", 
317
			   "$startTime", "$dur", 
318
			   "$outputFile");
319

  
320
	    # print "@command\n";
321
	    system(@command) and
322
		print "Failed: @command\n $!\n";
323
	    return 1;
324
	}
325
	else {
326
	    print "Fatal! Trying to schedule $title: ";
327
	    print "No mapping for XMLTV channel $channel\n";
328
	}
329
    }
330
    else {
331
	print "$title Already scheduled\n";
332
    }
333
};
334

  
335
sub main {
336
    my $q = new CGI;
337
    print $q->header;
338

  
339
    my $scheduled = getScheduled();
340
    my $recordings = getRecordings();
341
    my $offset = 0;
342

  
343
    my @names = $q->param;
344

  
345
    if ($q->param("record") =~ /^(.*)\|\|\|(.*)\|\|\|(.*)\|\|\|(.*)\|\|\|(.*)$/) {
346
	if (schedule($scheduled, $1, $2, $3, $4, $5)) {
347
	    $scheduled = getScheduled();
348
	    $recordings = getRecordings();
349
	}
350
    }
351

  
352
    if ($q->param("cancel") =~ /^(.*)\|\|\|(.*)\|\|\|(.*)\|\|\|(.*)\|\|\|(.*)$/) {
353
	if (cancel($scheduled, $recordings, $1, $2, $3, $4, $5)) {
354
	    $scheduled = getScheduled();
355
	    $recordings = getRecordings();
356
	}
357
    }
358

  
359
    if ($q->param("offset")) {
360
    	$offset = int($q->param("offset"));
361
	$offset = $maxoffset if ($offset > $maxoffset);
362
	$offset = 0 if ($offset < 0);
363
    }
364

  
365
    while ($maxoffset > 0 && ! -f listings($maxoffset)) {
366
	$maxoffset--;
367
    }
368

  
369
    printHtml($scheduled, $recordings, $offset);
370
}
371

  
372
sub test {
373
    printScheduled(STDOUT, getScheduled(), "scheduled");
374
    printScheduled(STDOUT, getRecordings(), "recordings");
375
}
376

  
377
main();
dvbdguide/tv.css
1
div.navbar {
2
  padding: 0px;
3
  margin-top: 8px;
4
}
5

  
6
table.navbar { 
7
  border-spacing: 0px;
8
  border-collapse: collapse;
9
}
10

  
11
td.navbar {
12
  border: 1px solid #d0d0c0;
13
  margin: 0px;
14
  text-align: center;
15
}
16

  
17
td.currentday {
18
  border: 1px solid #d0d0c0;
19
  background: #f9f9e9;
20
  text-align: center;
21
}
22

  
23
button {
24
  background-color: transparent;
25
  border: 1px solid #d0d0c0;
26
  padding-top: 4px;
27
  padding-button: 4px;
28
  padding-right: 8px;
29
  padding-left: 8px;
30
}
31

  
32
table.programmes { 
33
 /* width: 94%; */
34
 border-spacing: 0px;
35
 margin-left: 20px;
36
 margin-right: 20px;
37
}
38

  
39
div.navbar {
40
 margin-left: 20px;
41
 margin-right: 20px;
42
}
43

  
44
td.title { 
45
 text-decoration: underline;
46
} 
47

  
48
td.date-time {
49
  width: 11em;
50
}
51

  
52
td.channel {
53
  text-align: right;
54
}
55

  
56
td.button {
57
  text-align: left;
58
  vertical-align: top;
59
  padding: 4px;
60
}
61

  
62
span.channel {
63
  padding: 2px;
64
  border: none;
65
}
66

  
67
span.date, span.time { 
68
  font-weight:bold; 
69
}
70

  
71
tr.r0 { 
72
  background: #e0e0d0; 
73
}
74

  
75
td { 
76
  border: none;
77
  margin: none;
78
  padding: 4px; 
79
}
80

  
81
#sourceforgelogo {
82
 float:right;
83
}
84

  
85
body {
86
 background:#f0f0e0;
87
}
88

  
89
dt {
90
 font-weight:bold;	
91
}
92

  
93
h1, h2 {
94
}
95

  
96
h2 {
97
 text-decoration:underline;
98
}
99

  
100
pre {
101
 background:#d0d0b0;
102
 border:solid;
103
 padding:4px;
104
}
105

  
106
a:link {
107
 font-weight: bold;
108
 text-decoration: none;
109
 color: #606030;
110
}
111
a:visited {
112
 font-weight: bold;
113
 text-decoration: none;
114
 color: #808060;
115
}
116
a:hover, a:active {
117
 text-decoration: underline;
118
}
dvbdguide/tv.xsl
1
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
2
<xsl:key name="sched" match="/root/scheduled/programme" use="concat(@start,@channel)"/>
3
<xsl:key name="rec" match="/root/recordings/programme" use="concat(@start,@channel)"/>
4
<xsl:key name="fav" match="/root/favourites/programme" use="@title"/>
5
<xsl:output method="html" indent="yes"/>
6

  
7
<xsl:template match="/">
8
  <html>
9
    <head>
10
      <title>TV Listings</title>
11
      <link rel="stylesheet" href="tv.css" type="text/css"/>
12
    </head>
13
    <body>
14
      <form method="POST" action="tv.cgi">
15
        <input type="hidden" name="offset" value="{/root/offset}"/>
16
        <xsl:apply-templates select="/root/tv"/>
17
      </form>
18
    </body>
19
  </html>
20
</xsl:template>
21

  
22
<!-- Main starting/ending HTML -->
23
<xsl:template match="tv">
24
  <h1>TV Listings</h1>
25
  <xsl:variable name="now" select="/root/now"/>
26

  
27
  <p>
28
  <xsl:call-template name="navbar"/>
29
  <h2 id="favourites">Favourites</h2>
30
  </p>
31
  <table class="programmes" id="fav">
32
    <xsl:apply-templates select="programme[substring(@stop,0,15) &gt;= $now and key('fav', title)]"/>
33
  </table>
34

  
35
  <p>
36
  <xsl:call-template name="navbar"/>
37
  <h2 id="next">Next</h2>
38
  </p>
39
  <table class="programmes" id="next">
40
    <xsl:apply-templates select="programme[substring(@start,0,15) &gt;= $now]"/>
41
  </table>
42
  
43
  <p>
44
  <xsl:call-template name="navbar"/>
45
  <h2 id="now">Already Started</h2>
46
  </p>
47
  <table class="programmes" id="now">
48
    <xsl:apply-templates select="programme[substring(@start,0,15) &lt;= $now and $now &lt; substring(@stop,0,15)]"/>
49
  </table>
50

  
51
  <p>
52
  <xsl:call-template name="navbar"/>
53
  <h2 id="scheduled">Scheduled</h2>
54
  </p>
55
  <table class="programmes" id="scheduled">
56
    <xsl:apply-templates select="programme[key('sched', concat(@start,@channel))]">
57
      <xsl:with-param name="scheduled">true</xsl:with-param>
58
    </xsl:apply-templates>
59
  </table>
60

  
61
  <p>
62
  <xsl:call-template name="navbar"/>
63
  <h2 id="recording">Recording</h2>
64
  </p>
65
  <table class="programmes" id="recording">
66
    <xsl:apply-templates select="programme[key('rec', concat(@start,@channel))]">
67
      <xsl:with-param name="scheduled">true</xsl:with-param>
68
  </xsl:apply-templates>
69
  </table>
70
</xsl:template>
71

  
72
<xsl:template name="navbar">
73
  <div class="navbar">
74
    <table class="navbar">
75
      <tr class="navbar">
76
	<td>
77
	  <table class="navbar">
78
	    <tr class="navbar">
79
	      <td class="navbar"><a href="#favourites">Favourites</a></td>
80
	      <td class="navbar"><a href="#next">Next</a></td>
81
	      <td class="navbar"><a href="#now">Already Started</a></td>
82
	      <td class="navbar"><a href="#scheduled">Scheduled</a></td>
83
	      <td class="navbar"><a href="#recording">Recording</a></td>
84
	      <td class="navbar"><a href="">Refresh</a></td>
85
	    </tr>
86
	 </table>
87
       </td>
88
      </tr>
89
      <tr class="navbar">
90
	<td>
91
	  <table class="navbar" width="100%">
92
	    <tr class="navbar">
93
	      <xsl:call-template name="display-offset"/>
94
	    </tr>
95
	  </table>
96
	</td>
97
      </tr>
98
    </table>
99
  </div>
100
</xsl:template>
101

  
102
<!-- HTML for each 'programme' tag -->
103
<xsl:template match="tv/programme">
104
  <xsl:param name="scheduled">false</xsl:param>
105
  <tr class="r{position() mod 2}">
106
    <td class="date-time">
107
      <span class="date">
108
        <xsl:value-of select="substring(@start,7,2)"/>/<xsl:value-of select="concat(substring(@start,5,2),' ')"/>
109
      </span>
110
      <span class="time">
111
        <xsl:value-of select="substring(@start,9,2)"/>:<xsl:value-of select="substring(@start,11,2)"/>
112
      </span> - <span class="time"> <xsl:value-of select="substring(@stop,9,2)"/>:<xsl:value-of select="substring(@stop,11,2)"/> </span>
113
    </td>
114
    <xsl:choose>
115
      <xsl:when test="category='Film'">
116
        <div class="film">
117
          <td class="title">
118
            Film:
119
            <span class="film-title">
120
              <xsl:value-of select="title"/>
121
              <xsl:if test="sub-title">
122
                - <xsl:value-of select="sub-title"/>
123
              </xsl:if>
124
            </span>
125
            [<xsl:element name="a"><xsl:attribute name="href">http://www.imdb.com/Title?<xsl:value-of select="title"/>%20<xsl:if test="date">(<xsl:value-of select="date"/>)</xsl:if></xsl:attribute>imdb</xsl:element>]
126
          </td>
127
        </div>
128
      </xsl:when>
129
      <xsl:otherwise>
130
        <td class="title">
131
          <xsl:value-of select="title"/>
132
          <xsl:if test="sub-title">
133
            - <xsl:value-of select="sub-title"/>
134
          </xsl:if>
135
        </td>
136
      </xsl:otherwise>
137
    </xsl:choose>
138

  
139
    <div class="channel-{@channel}">
140
      <td class="channel">
141
        <span class="channel">
142
          <xsl:variable name="channel" select="@channel"/>
143
          <xsl:value-of select="/root/tv/channel[@id=$channel]/display-name[1]"/>
144
        </span>
145
      </td>
146
    </div>
147
  </tr>
148

  
149
  <tr class="r{position() mod 2}">
150
    <td class="button">
151
      <xsl:choose>
152
        <xsl:when test="$scheduled='true'">
153
          <button name="cancel" type="submit"
154
            value="{@channel}|||{title}|||{sub-title}|||{@start}|||{@stop}">Cancel</button>
155
        </xsl:when>
156
        <xsl:otherwise>
157
          <xsl:choose>
158
            <xsl:when test="key('rec', concat(@start,@channel)) or key('sched', concat(@start,@channel))">
159
                <button name="cancel" type="submit"
160
                  value="{@channel}|||{title}|||{sub-title}|||{@start}|||{@stop}">Cancel</button>
161
                
162
              <p>
163
                <xsl:choose>
164
                  <xsl:when test="key('sched', concat(@start,@channel))">
165
                    <a href="#scheduled">Scheduled</a>
166
                  </xsl:when>
167
                  <xsl:otherwise>
168
                    <a href="#recording">Recording</a>
169
                  </xsl:otherwise>
170
                </xsl:choose>
171
              </p>
172
            </xsl:when>
173
            <xsl:otherwise>
174
              <button name="record" type="submit" 
175
                value="{@channel}|||{title}|||{sub-title}|||{@start}|||{@stop}">Record</button>
176
            </xsl:otherwise>
177
          </xsl:choose>
178
        </xsl:otherwise>
179
      </xsl:choose>
180
    </td>
181
    <td colspan="2">
182
      <xsl:value-of select="desc"/>
183
    </td>
184
  </tr>
185
</xsl:template>
186

  
187
<xsl:template name="display-offset">
188
  <xsl:variable name="offset"><xsl:value-of select="/root/offset"/></xsl:variable>
189
  <xsl:for-each select="/root/day">
190
    <xsl:choose>
191
      <xsl:when test="number(@offset)=number($offset)">
192
        <td class="currentday">
193
          <xsl:value-of select="."/>
194
        </td>
195
      </xsl:when>
196
      <xsl:otherwise>
197
        <td class="navbar">
198
          <a href="?offset={@offset}"><xsl:value-of select="."/></a>
199
        </td>
200
      </xsl:otherwise>
201
    </xsl:choose>
202
  </xsl:for-each>
203
</xsl:template>
204

  
205
</xsl:stylesheet>
206

  

Also available in: Unified diff