-
Notifications
You must be signed in to change notification settings - Fork 1
/
bouquets2m3u8.php
111 lines (97 loc) · 3.11 KB
/
bouquets2m3u8.php
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
<?php
require_once "enigma2.php";
require_once "lamedb.php";
$host = $argv[2];
$port = $argv[3];
$protocol = "http";
$playlistFn = $argv[1];
$onlySD = true;
$ftp = new Enigma2Ftp($host, $argv[4], $argv[5]);
$fld = "/tmp/xxx/";
$fldOut = dirname($playlistFn) . "/playlists/";
// prepare target
@mkdir($fldOut, 0777, true);
// TODO remove old files
// download files from enigma2
@mkdir($fld, 0777, true);
$ftp->getBouquets($fld);
$ftp->get("/etc/enigma2/lamedb", $fld . "lamedb");
// load lamedb information
$lamedb = LameDb::factoryFromFile($fld . "lamedb");
// loop over all bouquets
$favFiles = array();
foreach (glob($fld . "user*.tv") as $fn) {
echo "processing $fn" . PHP_EOL;
$services = file($fn);
$bqName = array_shift($services);
$lines = array();
foreach ($services as $service) {
if (!preg_match("/^#SERVICE (.*)$/", $service, $m)) {
// description, could be handled better
continue;
}
$service = $m[1];
// find channel in lamedb
// TODO move this parsing to lamedb
$data = explode(":", $service);
if ($data[1] == 134) {
// read first alternative
if (!preg_match("/FROM BOUQUET \"([^\"]*)\" ORDER BY bouquet/", $data[10], $m)) {
echo "wrong alternative file reference $data[10]\n";
continue;
}
$alt = file($fld . $m[1]);
$service = $alt[1];
if (!preg_match("/^#SERVICE (.*)$/", $service, $m)) {
// description, could be handled better
echo "wrong alternative file $data[10]\n";
continue;
}
$service = $m[1];
// find channel in lamedb
$data = explode(":", $service);
}
// decode
$a = sprintf("%08s", strtoupper($data[6]));
$b = sprintf("%04s", strtoupper($data[3]));
$c = sprintf("%04s", strtoupper($data[4]));
if ($data[1] & 64) {
// separator
continue;
}
$r = $lamedb->getService("$a#$b#$c");
if (!$r) {
echo "channel '$a#$b#$c' not found" . PHP_EOL;
continue;
}
$name = $r->name;
$t = $lamedb->getTransponder($r->getTransponderKey());
if ($onlySD && !is_null($t->system)) {
// not SD
continue;
}
// TODO filter channels
if ($r->serviceType != 1) {
// not tv
continue;
}
// TODO detect picon
$icon = "";
$lines[] = "#EXTINF:0,$name" . ($icon ? ",:$icon,0" : ",,0");
$lines[] = "$protocol://$host:$port/$service";
}
if (!preg_match("/^#NAME (.*)$/", $bqName, $m)) {
die("error in file name");
}
$outFn = $fldOut . "{$host}-$m[1].m3u8";
file_put_contents($outFn, "#EXTM3U\n#EXTVLCOPT--http-reconnect=true\n" . implode("\n", $lines));
$favFiles[$m[1]] = $outFn;
}
// write supper playlist
$f = fopen($playlistFn, "w");
fputs($f, "#EXTM3U\n");
foreach ($favFiles as $name => $favFn) {
fputs($f, "#EXTINF:0,$name,,1\n");
fputs($f, $favFn . "\n");
}
fclose($f);