1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
|
<?php
include ('includes/inc_svdrp.php');
function vdrgetinfostream($stream = "NULL", $ischan = 1)
{
global $allepg, $allepgfilled, $svdrpip, $svdrpport;
if ($ischan)
{
// Fill epg if not yet done
if ($allepgfilled == 0)
{
$svdrp = new SVDRP($svdrpip, $svdrpport);
$svdrp->Connect();
$allepg = $svdrp->Command("LSTE NOW");
$svdrp->Disconnect();
$allepgfilled = 1;
}
$channame = $stream;
}
else
{
$infofile = $stream ."/info";
if (file_exists($infofile))
$info= file_get_contents($infofile);
else
{
$infofile = $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)
{
$streamArray = explode(",",$stream);
if (strstr($allepg[$i], $streamArray[0]) == $streamArray[0])
$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])+1);
}
}
else if(ereg("^T", $allepg[$i]))
$epgtitle=substr($allepg[$i], 2);
else if(ereg("^D", $allepg[$i]))
$epgdesc=substr($allepg[$i], 2);
}
}
// Convert if needed
if (!is_utf8($epgtitle))
$epgtitle = utf8_encode($epgtitle);
if (!is_utf8($epgdesc))
$epgdesc = utf8_encode($epgdesc);
return array($epgtitle, $epgdesc, $channame);
}
function vdrgettimerinfo($timernum=-1)
{
global $svdrpip, $svdrpport;
if ($timernum != -1)
{
$svdrp = new SVDRP($svdrpip, $svdrpport);
$svdrp->Connect();
$timer = $svdrp->Command("LSTT " .$timernum);
$svdrp->Disconnect();
$timerarray = explode(":", $timer);
$typearray = explode(" ", $timerarray[0]);
$type = $typearray[1];
$channel = $timerarray[1];
$date = $timerarray[2];
$stime = $timerarray[3];
$etime = $timerarray[4];
$desc = $timerarray[7];
}
else
{
$type = 1;
$channel = 1;
$date = date('Y-m-d');
$stime = date('Hi');
$etime = date('Hi');
$desc = "New timer";
}
$channame = vdrgetchanname($channel);
return array($type, $channame, $date, $stime, $etime, $desc);
}
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 vdrgetchanname($channum = 0)
{
global $svdrpip, $svdrpport;
$svdrp = new SVDRP($svdrpip, $svdrpport);
$svdrp->Connect();
$channel = $svdrp->Command("LSTC " .$channum);
$svdrp->Disconnect();
// Get channel name
$chanarray = explode(":", $channel);
$chanarray = explode(";", $chanarray[0]);
$channame = $chanarray[0];
$channame = substr($channame, strlen($channum)+1);
return $channame;
}
function vdrlistcategories()
{
global $vdrchannels;
// All chans
print "<li class=\"menu\"><a class=\"noeffect\" href=\"javascript:sendForm('All');\"><span class=\"name\">All channels</span><span class=\"arrow\"></span></a></li>\r\n";
print "<form name=\"All channels\" id=\"All\" method=\"post\" action=\"index.php\"><input name=\"action\" type=\"hidden\" id=\"action\" value=\"listchannels\"/><input name=\"cat\" type=\"hidden\" id=\"cat\" value=\"All\" /></form>\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 "<li class=\"menu\"><a class=\"noeffect\" href=\"javascript:sendForm('$cat2');\"><span class=\"name\">$cat</span><span class=\"arrow\"></span></a></li>\r\n";
print "<form name=\"$cat\" id=\"$cat\" method=\"post\" action=\"index.php\"><input name=\"action\" type=\"hidden\" id=\"action\" value=\"listchannels\"/><input name=\"cat\" type=\"hidden\" id=\"cat\" value=\"$cat\" /></form>\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 "<li class=\"withimage\">";
$chan2=addslashes($chan);
print " <a class=\"noeffect\" href=\"javascript:sendForm('$chan2');\">\r\n";
if (!file_exists('logos/'.$chan.'.png'))
print " <img src=\"logos/nologoTV.png\" />\r\n";
else
print " <img src=\"logos/{$chan}.png\" />\r\n";
print " <span class=\"name\">$chan</span>\r\n";
print " <span class=\"comment\">$epgtitle</span><span class=\"arrow\"></span></a>\r\n</li>\r\n";
print " <form name=\"$chan\" id=\"$chan\" method=\"post\" action=\"index.php\">";
print " <input name=\"action\" type=\"hidden\" id=\"action\" value=\"stream\" />";
print " <input name=\"type\" type=\"hidden\" id=\"type\" value=1 />";
print " <input name=\"name\" type=\"hidden\" id=\"name\" value=\"$chan\" />";
print " </form>\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);
}
function vdrlistchannelsdrop($chansel = "")
{
global $vdrchannels;
$chanselected = 0;
$fp = fopen ($vdrchannels,"r");
while ($line = fgets($fp, 1024))
{
if ($line[0] == ":")
continue;
$channels = explode(":", $line);
$channels = explode(";", $channels[0]);
$chan = $channels[0];
if (($chan == $chansel) && !$chanselected)
{
print "<option selected value=\"{$chan}\">{$chan}</option>";
$chanselected = 1;
}
else
print "<option value=\"{$chan}\">{$chan}</option>";
}
}
function vdrlisttimers()
{
global $svdrpip, $svdrpport;
$svdrp = new SVDRP($svdrpip, $svdrpport);
$svdrp->Connect();
$timers = $svdrp->Command("LSTT");
$svdrp->Disconnect();
foreach($timers as $timer)
{
// Extract timer #
$timerarray = explode(" ", $timer);
$timernum = $timerarray[0];
list($type, $channame, $date, $starthour, $endhour, $desc) = vdrgettimerinfo($timernum);
print "<li class=\"menu\">";
print " <a href=\"javascript:sendForm('timer {$timernum}')\">";
print " <img alt=\"list\" src=\"images/pictos/timers.png\" />";
print " <span class=\"name\">{$date}: {$channame}</span><span class=\"arrow\"></span>";
print " </a>";
print "</li>";
print "<form name=\"timer {$timernum}\" id=\"timer {$timernum}\" method=\"post\" action=\"index.php\">";
print " <input name=\"action\" type=\"hidden\" id=\"action\" value=\"edittimer\"/>";
print " <input name=\"timer\" type=\"hidden\" id=\"timer\" value=\"{$timernum}\" />";
print "</form>";
}
}
function vdrdeltimer($timer=0)
{
global $svdrpip, $svdrpport;
$svdrp = new SVDRP($svdrpip, $svdrpport);
$svdrp->Connect();
$svdrp->Command("DELT " .$timer);
$svdrp->Disconnect();
}
function vdrsettimer($channame, $date, $stime, $etime, $desc)
{
global $svdrpip, $svdrpport;
$channum = vdrgetchannum($channame);
$timer = "1:" .$channum .":" .$date .":" .$stime .":" .$etime .":99:99:" .$desc;
print $timer;
$svdrp = new SVDRP($svdrpip, $svdrpport);
$svdrp->Connect();
$svdrp->Command("ADDT " .$timer);
$svdrp->Disconnect();
}
?>
|