Use channel configuration for visibility and ordering
This commit is contained in:
@@ -1 +1,24 @@
|
|||||||
{}
|
{
|
||||||
|
"orf1.at": {
|
||||||
|
"uuid": "58a965b21f48319d1a4051476667f5e2",
|
||||||
|
"name": "ORF 1",
|
||||||
|
"icon": "\/logos\/orf1.png",
|
||||||
|
"country": "",
|
||||||
|
"language": "",
|
||||||
|
"enabled": true,
|
||||||
|
"favorite": false,
|
||||||
|
"number": 1,
|
||||||
|
"group": "Unknown"
|
||||||
|
},
|
||||||
|
"orf2.at": {
|
||||||
|
"uuid": "4c9dba34a821b5b25c8e1e2b65abc4df",
|
||||||
|
"name": "ORF 2",
|
||||||
|
"icon": "\/logos\/orf2.png",
|
||||||
|
"country": "",
|
||||||
|
"language": "",
|
||||||
|
"enabled": true,
|
||||||
|
"favorite": false,
|
||||||
|
"number": 2,
|
||||||
|
"group": "Unknown"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
require_once '/var/www/src/Config.php';
|
||||||
require_once '/var/www/src/XmlTv.php';
|
require_once '/var/www/src/XmlTv.php';
|
||||||
require_once '/var/www/src/View.php';
|
require_once '/var/www/src/View.php';
|
||||||
require_once '/var/www/src/Config.php';
|
|
||||||
|
|
||||||
$config = new Config(
|
$config = new Config(
|
||||||
'/var/www/config/config.json',
|
'/var/www/config/config.json',
|
||||||
@@ -14,13 +14,14 @@ $xmltv = new XmlTv(
|
|||||||
$config->get('timezone', 'Europe/Vienna')
|
$config->get('timezone', 'Europe/Vienna')
|
||||||
);
|
);
|
||||||
|
|
||||||
$xmltv = new XmlTv('/var/www/epg/guide.xml', 'Europe/Vienna');
|
$xmltv->synchronizeChannels($config);
|
||||||
[$channels, $programmes] = $xmltv->load();
|
|
||||||
|
[$channels, $programmes] = $xmltv->load($config);
|
||||||
|
|
||||||
$contentTemplate = '/var/www/templates/home.php';
|
$contentTemplate = '/var/www/templates/home.php';
|
||||||
|
|
||||||
View::render('layout', [
|
View::render('layout', [
|
||||||
'title' => $config->get('title'),
|
'title' => $config->get('title', 'TVGuide'),
|
||||||
'channels' => $channels,
|
'channels' => $channels,
|
||||||
'programmes' => $programmes,
|
'programmes' => $programmes,
|
||||||
'contentTemplate' => $contentTemplate,
|
'contentTemplate' => $contentTemplate,
|
||||||
|
|||||||
+66
-3
@@ -11,10 +11,11 @@ class XmlTv
|
|||||||
$this->timezone = $timezone;
|
$this->timezone = $timezone;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function load(): array
|
public function load(?Config $config = null): array
|
||||||
{
|
{
|
||||||
$channels = [];
|
$channels = [];
|
||||||
$programmes = [];
|
$programmes = [];
|
||||||
|
$channelConfig = $config ? $config->getChannels() : [];
|
||||||
|
|
||||||
if (!file_exists($this->file)) {
|
if (!file_exists($this->file)) {
|
||||||
return [$channels, $programmes];
|
return [$channels, $programmes];
|
||||||
@@ -25,15 +26,27 @@ class XmlTv
|
|||||||
foreach ($xml->channel as $channel) {
|
foreach ($xml->channel as $channel) {
|
||||||
$id = (string)$channel['id'];
|
$id = (string)$channel['id'];
|
||||||
|
|
||||||
|
$cfg = $channelConfig[$id] ?? [];
|
||||||
|
|
||||||
|
if (($cfg['enabled'] ?? true) !== true) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$channels[$id] = [
|
$channels[$id] = [
|
||||||
'id' => $id,
|
'id' => $id,
|
||||||
'name' => (string)$channel->{'display-name'},
|
'name' => $cfg['name'] ?? (string)$channel->{'display-name'},
|
||||||
'icon' => isset($channel->icon) ? (string)$channel->icon['src'] : null,
|
'icon' => $cfg['icon'] ?? (isset($channel->icon) ? (string)$channel->icon['src'] : null),
|
||||||
|
'number' => (int)($cfg['number'] ?? 999999),
|
||||||
|
'favorite' => (bool)($cfg['favorite'] ?? false),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($xml->programme as $programme) {
|
foreach ($xml->programme as $programme) {
|
||||||
$channelId = (string)$programme['channel'];
|
$channelId = (string)$programme['channel'];
|
||||||
|
if (!isset($channels[$channelId])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$start = $this->parseTime((string)$programme['start']);
|
$start = $this->parseTime((string)$programme['start']);
|
||||||
$stop = $this->parseTime((string)$programme['stop']);
|
$stop = $this->parseTime((string)$programme['stop']);
|
||||||
|
|
||||||
@@ -50,9 +63,59 @@ class XmlTv
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uasort($channels, function ($a, $b) {
|
||||||
|
return ($a['number'] ?? 999999) <=> ($b['number'] ?? 999999);
|
||||||
|
});
|
||||||
|
|
||||||
return [$channels, $programmes];
|
return [$channels, $programmes];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function synchronizeChannels(Config $config): void
|
||||||
|
{
|
||||||
|
if (!file_exists($this->file)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$xml = simplexml_load_file($this->file);
|
||||||
|
$storedChannels = $config->getChannels();
|
||||||
|
|
||||||
|
$maxNumber = 0;
|
||||||
|
foreach ($storedChannels as $stored) {
|
||||||
|
$maxNumber = max($maxNumber, (int)($stored['number'] ?? 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($xml->channel as $channel) {
|
||||||
|
$id = (string)$channel['id'];
|
||||||
|
$name = (string)$channel->{'display-name'};
|
||||||
|
$icon = isset($channel->icon) ? (string)$channel->icon['src'] : '';
|
||||||
|
|
||||||
|
if (!isset($storedChannels[$id])) {
|
||||||
|
$maxNumber++;
|
||||||
|
|
||||||
|
$storedChannels[$id] = [
|
||||||
|
'uuid' => bin2hex(random_bytes(16)),
|
||||||
|
'name' => $name,
|
||||||
|
'icon' => $icon,
|
||||||
|
'country' => '',
|
||||||
|
'language' => '',
|
||||||
|
'enabled' => true,
|
||||||
|
'favorite' => false,
|
||||||
|
'number' => $maxNumber,
|
||||||
|
'group' => 'Unknown',
|
||||||
|
];
|
||||||
|
} else {
|
||||||
|
$storedChannels[$id]['name'] = $name;
|
||||||
|
$storedChannels[$id]['icon'] = $icon;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uasort($storedChannels, function ($a, $b) {
|
||||||
|
return ((int)($a['number'] ?? 999999)) <=> ((int)($b['number'] ?? 999999));
|
||||||
|
});
|
||||||
|
|
||||||
|
$config->saveChannels($storedChannels);
|
||||||
|
}
|
||||||
|
|
||||||
private function parseTime(string $value): ?DateTime
|
private function parseTime(string $value): ?DateTime
|
||||||
{
|
{
|
||||||
if (!preg_match('/^(\d{14})\s+([+-]\d{4})$/', trim($value), $m)) {
|
if (!preg_match('/^(\d{14})\s+([+-]\d{4})$/', trim($value), $m)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user