Multiple Provider, Rytec Import
This commit is contained in:
+51
-29
@@ -8,47 +8,69 @@ $config = new Config(
|
||||
);
|
||||
|
||||
$epg = $config->get('epg', []);
|
||||
$url = $epg['url'] ?? null;
|
||||
$urls = $epg['urls'] ?? [];
|
||||
|
||||
if (!$url) {
|
||||
fwrite(STDERR, "Keine epg.url in config.json gesetzt.\n");
|
||||
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';
|
||||
$xzFile = $target . '.xz';
|
||||
$tmpXml = $target . '.tmp';
|
||||
|
||||
echo "Lade EPG: {$url}\n";
|
||||
if (!is_dir($workDir)) {
|
||||
mkdir($workDir, 0775, true);
|
||||
}
|
||||
|
||||
$data = file_get_contents($url);
|
||||
$xmlFiles = [];
|
||||
|
||||
if ($data === false || trim($data) === '') {
|
||||
fwrite(STDERR, "Download fehlgeschlagen oder leer.\n");
|
||||
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);
|
||||
}
|
||||
|
||||
file_put_contents($xzFile, $data);
|
||||
echo "Merge XMLTV...\n";
|
||||
|
||||
echo "Entpacke XZ...\n";
|
||||
|
||||
$command = 'xz -dc ' . escapeshellarg($xzFile) . ' > ' . escapeshellarg($tmpXml);
|
||||
exec($command, $output, $code);
|
||||
|
||||
if ($code !== 0 || !file_exists($tmpXml) || filesize($tmpXml) === 0) {
|
||||
fwrite(STDERR, "XZ konnte nicht entpackt werden.\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$xml = @simplexml_load_file($tmpXml);
|
||||
|
||||
if (!$xml) {
|
||||
unlink($tmpXml);
|
||||
fwrite(STDERR, "XML ungültig.\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
rename($tmpXml, $target);
|
||||
$merge = new XmlTvMergeService();
|
||||
$merge->merge($xmlFiles, $target);
|
||||
|
||||
echo "guide.xml aktualisiert.\n";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user