86 lines
1.8 KiB
PHP
86 lines
1.8 KiB
PHP
<?php
|
|
|
|
require_once '/var/www/src/bootstrap.php';
|
|
|
|
$config = new Config(
|
|
'/var/www/config/config.json',
|
|
'/var/www/config/channels.json'
|
|
);
|
|
|
|
$epg = $config->get('epg', []);
|
|
$urls = $epg['urls'] ?? [];
|
|
|
|
if (!$urls && !empty($epg['url'])) {
|
|
$urls = [$epg['url']];
|
|
}
|
|
|
|
if (!$urls) {
|
|
fwrite(STDERR, "Keine epg.urls in config.json gesetzt.\n");
|
|
exit(1);
|
|
}
|
|
|
|
$workDir = '/var/www/epg/work';
|
|
$target = '/var/www/epg/guide.xml';
|
|
|
|
if (!is_dir($workDir)) {
|
|
mkdir($workDir, 0775, true);
|
|
}
|
|
|
|
$xmlFiles = [];
|
|
|
|
foreach ($urls as $index => $url) {
|
|
$base = $workDir . '/source-' . $index;
|
|
$xzFile = $base . '.xz';
|
|
$xmlFile = $base . '.xml';
|
|
|
|
echo "Lade EPG: {$url}\n";
|
|
|
|
$data = file_get_contents($url);
|
|
|
|
if ($data === false || trim($data) === '') {
|
|
fwrite(STDERR, "Download fehlgeschlagen oder leer: {$url}\n");
|
|
continue;
|
|
}
|
|
|
|
file_put_contents($xzFile, $data);
|
|
|
|
echo "Entpacke XZ...\n";
|
|
|
|
$command = 'xz -dc ' . escapeshellarg($xzFile) . ' > ' . escapeshellarg($xmlFile);
|
|
exec($command, $output, $code);
|
|
|
|
if ($code !== 0 || !file_exists($xmlFile) || filesize($xmlFile) === 0) {
|
|
fwrite(STDERR, "XZ konnte nicht entpackt werden: {$url}\n");
|
|
continue;
|
|
}
|
|
|
|
if (!@simplexml_load_file($xmlFile)) {
|
|
fwrite(STDERR, "XML ungültig: {$url}\n");
|
|
continue;
|
|
}
|
|
|
|
$xmlFiles[] = $xmlFile;
|
|
}
|
|
|
|
if (!$xmlFiles) {
|
|
fwrite(STDERR, "Keine gültigen XMLTV-Dateien geladen.\n");
|
|
exit(1);
|
|
}
|
|
|
|
echo "Merge XMLTV...\n";
|
|
|
|
$merge = new XmlTvMergeService();
|
|
$merge->merge($xmlFiles, $target);
|
|
|
|
echo "guide.xml aktualisiert.\n";
|
|
|
|
$cache = new XmlTvCacheService(
|
|
$target,
|
|
$config->get('timezone', 'Europe/Vienna'),
|
|
'/var/www/cache/guide.json'
|
|
);
|
|
|
|
$cache->rebuildCache();
|
|
|
|
echo "guide.json und guide.version aktualisiert.\n";
|