1
|
<?
|
2
|
error_reporting(E_ALL);
|
3
|
ini_set('display_errors',1);
|
4
|
|
5
|
define('TVHEADEND','http://192.168.6.61:9981/');
|
6
|
define('WEBPAGE_URL','http://192.168.6.61/digiguide/');
|
7
|
define('OUTPUT_DIR','/var/www/digiguide/');
|
8
|
define('EIT_TIMEZONE','Europe/London');
|
9
|
|
10
|
$json = json_decode(file_get_contents(TVHEADEND . 'channels?op=list'));
|
11
|
|
12
|
// Build DGC
|
13
|
$dgc = "[info]\r\n";
|
14
|
$dgc .= "Name=TV Headend\r\n";
|
15
|
$dgc .= "[email protected]\r\n";
|
16
|
$dgc .= "HomeURL=" . TVHEADEND . "\r\n";
|
17
|
$dgc .= "Description=TV Headend EPG\r\n";
|
18
|
$dgc .= "ChannelCount=" . count($json->entries) . "\r\n\r\n";
|
19
|
$idx = 0;
|
20
|
foreach($json->entries as $channel)
|
21
|
{
|
22
|
$xml = WEBPAGE_URL . "{$channel->chid}.xml";
|
23
|
$xml_disk = OUTPUT_DIR . "{$channel->chid}.xml";
|
24
|
$idx++;
|
25
|
$dgc .= "[channel{$idx}]\r\n";
|
26
|
$dgc .= "Name={$channel->name}.\r\n";
|
27
|
if (isset($channel->ch_icon))
|
28
|
{
|
29
|
$dgc .= "LogoURL={$channel->ch_icon}\r\n";
|
30
|
}
|
31
|
else
|
32
|
{
|
33
|
$dgc .= "LogoURL=http://192.168.6.61/logos/unknown.png\r\n";
|
34
|
}
|
35
|
$dgc .= "DataURL=" . WEBPAGE_URL . "{$channel->chid}.xml\r\n\r\n";
|
36
|
|
37
|
buildXML($channel->name,$xml_disk);
|
38
|
}
|
39
|
|
40
|
file_put_contents(OUTPUT_DIR . "channels.dgc",$dgc);
|
41
|
|
42
|
function buildXML($channel_name,$file_name)
|
43
|
{
|
44
|
echo "$channel_name\n";
|
45
|
$count = 50;
|
46
|
$idx = 0;
|
47
|
$done = false;
|
48
|
$out = "<channels>\r\n<channel name=\"{$channel_name}.\">\r\n<programmes>";
|
49
|
while($done == false)
|
50
|
{
|
51
|
|
52
|
$progs = fetchProgrammes($idx,$count,$channel_name);
|
53
|
echo "\t{$idx}/" . $progs->totalCount . "\n";
|
54
|
if (count($progs->entries) < $count)
|
55
|
{
|
56
|
$done = true;
|
57
|
}
|
58
|
foreach($progs->entries as $prog)
|
59
|
{
|
60
|
$name = htmlentities($prog->title);
|
61
|
$start = new datetime(date('Y-m-d H:i:s',$prog->start),new DateTimeZone(EIT_TIMEZONE));
|
62
|
$start->setTimeZone(new DateTimeZone('UTC'));
|
63
|
$start_date = $start->format('Y/m/d');
|
64
|
$start_time = $start->format('Hi');
|
65
|
$duration = $prog->duration / 60;
|
66
|
$plot = htmlentities(@initVar($prog->description,""));
|
67
|
$out .= "<programme name=\"{$name}\" startdate=\"{$start_date}\" starttime=\"{$start_time}\" duration=\"{$duration}\"><synopsis>{$plot}</synopsis></programme>";
|
68
|
}
|
69
|
$idx += count($progs->entries);
|
70
|
}
|
71
|
$out .= "</programmes></channel></channels>";
|
72
|
file_put_contents($file_name,$out);
|
73
|
}
|
74
|
function fetchProgrammes($idx,$limit,$channel_name)
|
75
|
{
|
76
|
$channel_name = urlencode($channel_name);
|
77
|
$json = json_decode(file_get_contents(TVHEADEND . "epg?start={$idx}&limit={$limit}&channel={$channel_name}"));
|
78
|
return $json;
|
79
|
}
|
80
|
function initVar($var,$default)
|
81
|
{
|
82
|
return isset($var) ? $var : $default;
|
83
|
}
|
84
|
echo "\n";
|
85
|
|
86
|
|
87
|
|
88
|
?>
|