Add program reminders and category filtering to the guide UI
Enhance health diagnostics with EPG quality and source metrics
This commit is contained in:
+111
-7
@@ -30,24 +30,56 @@ function health_parse_xmltv(string $xml): array {
|
||||
$subtitles = $xp->query('/tv/programme/sub-title');
|
||||
$ratings = $xp->query('/tv/programme/rating');
|
||||
$dates = $xp->query('/tv/programme/date');
|
||||
$channel_icons = $xp->query('/tv/channel/icon');
|
||||
|
||||
$first = null;
|
||||
$last = null;
|
||||
$with_desc = 0;
|
||||
$with_subtitle = 0;
|
||||
$with_category = 0;
|
||||
$with_rating = 0;
|
||||
$with_date = 0;
|
||||
$with_stop = 0;
|
||||
$unique_categories = [];
|
||||
|
||||
foreach ($programmes as $programme) {
|
||||
$start = $programme->getAttribute('start');
|
||||
$stop = $programme->getAttribute('stop');
|
||||
if ($start !== '' && ($first === null || strcmp($start, $first) < 0)) $first = $start;
|
||||
if ($stop !== '' && ($last === null || strcmp($stop, $last) > 0)) $last = $stop;
|
||||
if ($stop !== '') $with_stop++;
|
||||
if (trim($xp->evaluate('string(desc)', $programme)) !== '') $with_desc++;
|
||||
if (trim($xp->evaluate('string(sub-title)', $programme)) !== '') $with_subtitle++;
|
||||
if (trim($xp->evaluate('string(category)', $programme)) !== '') $with_category++;
|
||||
if (trim($xp->evaluate('string(rating/value)', $programme)) !== '') $with_rating++;
|
||||
if (trim($xp->evaluate('string(date)', $programme)) !== '') $with_date++;
|
||||
foreach ($xp->query('category', $programme) as $category) {
|
||||
$value = trim($category->textContent);
|
||||
if ($value !== '') $unique_categories[strtolower($value)] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$channel_count = $channels->length;
|
||||
$programme_count = $programmes->length;
|
||||
|
||||
return [
|
||||
'ok' => true,
|
||||
'channels' => $channels->length,
|
||||
'programmes' => $programmes->length,
|
||||
'channels' => $channel_count,
|
||||
'programmes' => $programme_count,
|
||||
'categories' => $categories->length,
|
||||
'subtitles' => $subtitles->length,
|
||||
'ratings' => $ratings->length,
|
||||
'dates' => $dates->length,
|
||||
'channel_icons' => $channel_icons->length,
|
||||
'channels_without_icon' => max(0, $channel_count - $channel_icons->length),
|
||||
'programmes_with_desc' => $with_desc,
|
||||
'programmes_with_subtitle' => $with_subtitle,
|
||||
'programmes_with_category' => $with_category,
|
||||
'programmes_with_rating' => $with_rating,
|
||||
'programmes_with_date' => $with_date,
|
||||
'programmes_with_stop' => $with_stop,
|
||||
'unique_categories' => count($unique_categories),
|
||||
'avg_programmes_per_channel' => $channel_count > 0 ? round($programme_count / $channel_count, 1) : 0,
|
||||
'first_start' => $first,
|
||||
'last_stop' => $last,
|
||||
];
|
||||
@@ -57,6 +89,10 @@ function health_parse_m3u(string $body): array {
|
||||
$lines = preg_split('/\r\n|\r|\n/', $body);
|
||||
$streams = 0;
|
||||
$extinf = 0;
|
||||
$http = 0;
|
||||
$https = 0;
|
||||
$duplicates = 0;
|
||||
$seen_urls = [];
|
||||
foreach ($lines as $line) {
|
||||
$line = trim($line);
|
||||
if ($line === '') continue;
|
||||
@@ -64,9 +100,22 @@ function health_parse_m3u(string $body): array {
|
||||
$extinf++;
|
||||
continue;
|
||||
}
|
||||
if ($line[0] !== '#') $streams++;
|
||||
if ($line[0] !== '#') {
|
||||
$streams++;
|
||||
if (stripos($line, 'https://') === 0) $https++;
|
||||
if (stripos($line, 'http://') === 0) $http++;
|
||||
if (isset($seen_urls[$line])) $duplicates++;
|
||||
$seen_urls[$line] = true;
|
||||
}
|
||||
}
|
||||
return ['streams' => $streams, 'extinf' => $extinf];
|
||||
return [
|
||||
'streams' => $streams,
|
||||
'extinf' => $extinf,
|
||||
'http_streams' => $http,
|
||||
'https_streams' => $https,
|
||||
'duplicate_urls' => $duplicates,
|
||||
'size_bytes' => strlen($body),
|
||||
];
|
||||
}
|
||||
|
||||
function health_format_xmltv_stamp(?string $stamp): string {
|
||||
@@ -185,6 +234,9 @@ function health_build_payload(array $config, string $locale): array {
|
||||
|
||||
$epg_fetch = $epg_url !== '' ? gridtv_fetch_url($epg_url, 25) : ['ok' => false, 'status' => 0, 'error' => 'Missing URL', 'body' => '', 'content_type' => '', 'final_url' => '', 'time_total' => 0.0];
|
||||
$epg_stats = $epg_fetch['ok'] ? health_parse_xmltv($epg_fetch['body']) : ['ok' => false, 'error' => $epg_fetch['error'] ?: 'HTTP ' . $epg_fetch['status']];
|
||||
$epg_fetch_public = $epg_fetch;
|
||||
$epg_fetch_public['body_bytes'] = strlen((string) ($epg_fetch_public['body'] ?? ''));
|
||||
unset($epg_fetch_public['body']);
|
||||
|
||||
$m3u_fetch = null;
|
||||
$m3u_stats = null;
|
||||
@@ -192,6 +244,16 @@ function health_build_payload(array $config, string $locale): array {
|
||||
$m3u_fetch = gridtv_fetch_url($m3u_url, 20);
|
||||
$m3u_stats = $m3u_fetch['ok'] ? health_parse_m3u($m3u_fetch['body']) : null;
|
||||
}
|
||||
$m3u_fetch_public = $m3u_fetch;
|
||||
if (is_array($m3u_fetch_public)) {
|
||||
$m3u_fetch_public['body_bytes'] = strlen((string) ($m3u_fetch_public['body'] ?? ''));
|
||||
unset($m3u_fetch_public['body']);
|
||||
}
|
||||
|
||||
if (!empty($epg_stats['ok'])) {
|
||||
$epg_stats['first_start_local'] = health_format_xmltv_stamp($epg_stats['first_start'] ?? null);
|
||||
$epg_stats['last_stop_local'] = health_format_xmltv_stamp($epg_stats['last_stop'] ?? null);
|
||||
}
|
||||
|
||||
$source_reports[] = [
|
||||
'name' => $source['name'] ?: 'Source ' . ($index + 1),
|
||||
@@ -199,9 +261,9 @@ function health_build_payload(array $config, string $locale): array {
|
||||
'm3u_url' => $m3u_url,
|
||||
'epg_host' => gridtv_extract_host($epg_url),
|
||||
'm3u_host' => gridtv_extract_host($m3u_url),
|
||||
'epg_fetch' => $epg_fetch,
|
||||
'epg_fetch' => $epg_fetch_public,
|
||||
'epg_stats' => $epg_stats,
|
||||
'm3u_fetch' => $m3u_fetch,
|
||||
'm3u_fetch' => $m3u_fetch_public,
|
||||
'm3u_stats' => $m3u_stats,
|
||||
];
|
||||
}
|
||||
@@ -361,18 +423,54 @@ function renderChecks(checks, labels) {
|
||||
}
|
||||
|
||||
function renderSources(sources, labels) {
|
||||
function percent(part, total) {
|
||||
if (!total) return '0%';
|
||||
return Math.round((part / total) * 100) + '%';
|
||||
}
|
||||
|
||||
function qualityScore(stats) {
|
||||
if (!stats || !stats.programmes) return 0;
|
||||
const values = [
|
||||
stats.programmes_with_desc / stats.programmes,
|
||||
stats.programmes_with_category / stats.programmes,
|
||||
stats.programmes_with_subtitle / stats.programmes,
|
||||
stats.programmes_with_rating / stats.programmes
|
||||
];
|
||||
return Math.round((values.reduce((sum, value) => sum + value, 0) / values.length) * 100);
|
||||
}
|
||||
|
||||
function qualityLabel(score) {
|
||||
if (score >= 85) return 'Excellent';
|
||||
if (score >= 70) return 'Good';
|
||||
if (score >= 50) return 'Partial';
|
||||
return 'Poor';
|
||||
}
|
||||
|
||||
document.getElementById('sourceList').innerHTML = sources.map(report => {
|
||||
const epgHealthy = report.epg_fetch.ok && report.epg_stats.ok;
|
||||
const m3uHealthy = report.m3u_fetch ? report.m3u_fetch.ok : true;
|
||||
const score = epgHealthy ? qualityScore(report.epg_stats) : 0;
|
||||
const epgRows = epgHealthy ? `
|
||||
<div>Channels</div><div>${report.epg_stats.channels}</div>
|
||||
<div>Programmes</div><div>${report.epg_stats.programmes}</div>
|
||||
<div>Channel logos</div><div>${report.epg_stats.channel_icons} (${report.epg_stats.channels_without_icon} missing)</div>
|
||||
<div>Descriptions</div><div>${report.epg_stats.programmes_with_desc} (${percent(report.epg_stats.programmes_with_desc, report.epg_stats.programmes)})</div>
|
||||
<div>Categories coverage</div><div>${report.epg_stats.programmes_with_category} (${percent(report.epg_stats.programmes_with_category, report.epg_stats.programmes)})</div>
|
||||
<div>Subtitle coverage</div><div>${report.epg_stats.programmes_with_subtitle} (${percent(report.epg_stats.programmes_with_subtitle, report.epg_stats.programmes)})</div>
|
||||
<div>Rating coverage</div><div>${report.epg_stats.programmes_with_rating} (${percent(report.epg_stats.programmes_with_rating, report.epg_stats.programmes)})</div>
|
||||
<div>Date coverage</div><div>${report.epg_stats.programmes_with_date} (${percent(report.epg_stats.programmes_with_date, report.epg_stats.programmes)})</div>
|
||||
<div>Stop time coverage</div><div>${report.epg_stats.programmes_with_stop} (${percent(report.epg_stats.programmes_with_stop, report.epg_stats.programmes)})</div>
|
||||
<div>Unique categories</div><div>${report.epg_stats.unique_categories}</div>
|
||||
<div>Programmes / channel</div><div>${report.epg_stats.avg_programmes_per_channel}</div>
|
||||
<div>Sub-titles</div><div>${report.epg_stats.subtitles}</div>
|
||||
<div>Ratings</div><div>${report.epg_stats.ratings}</div>
|
||||
<div>Categories</div><div>${report.epg_stats.categories}</div>
|
||||
<div>Date tags</div><div>${report.epg_stats.dates}</div>
|
||||
<div>Window</div><div>${report.epg_stats.first_start || '—'} → ${report.epg_stats.last_stop || '—'}</div>
|
||||
<div>Window (local)</div><div>${report.epg_stats.first_start_local || '—'} → ${report.epg_stats.last_stop_local || '—'}</div>
|
||||
<div>Content-Type</div><div>${report.epg_fetch.content_type || '—'}</div>
|
||||
<div>Final URL</div><div class="mono">${report.epg_fetch.final_url || report.epg_url}</div>
|
||||
<div>Payload size</div><div>${report.epg_fetch.headers['content-length'] || report.epg_fetch.body_bytes || '—'} bytes</div>
|
||||
` : `<div>Parse</div><div>${report.epg_stats.error || 'Unable to read XMLTV'}</div>`;
|
||||
|
||||
const m3uRows = !report.m3u_url ? `<div class="small">No M3U URL configured for this source.</div>` : `
|
||||
@@ -384,7 +482,12 @@ function renderSources(sources, labels) {
|
||||
${report.m3u_fetch.ok && report.m3u_stats ? `
|
||||
<div>Streams</div><div>${report.m3u_stats.streams}</div>
|
||||
<div>#EXTINF</div><div>${report.m3u_stats.extinf}</div>
|
||||
<div>HTTPS streams</div><div>${report.m3u_stats.https_streams}</div>
|
||||
<div>HTTP streams</div><div>${report.m3u_stats.http_streams}</div>
|
||||
<div>Duplicate URLs</div><div>${report.m3u_stats.duplicate_urls}</div>
|
||||
<div>Payload size</div><div>${report.m3u_fetch.headers['content-length'] || report.m3u_fetch.body_bytes || report.m3u_stats.size_bytes} bytes</div>
|
||||
<div>Content-Type</div><div>${report.m3u_fetch.content_type || '—'}</div>
|
||||
<div>Final URL</div><div class="mono">${report.m3u_fetch.final_url || report.m3u_url}</div>
|
||||
` : `<div>Parse</div><div>Unable to load playlist.</div>`}
|
||||
</div>`;
|
||||
|
||||
@@ -395,13 +498,14 @@ function renderSources(sources, labels) {
|
||||
<div class="source-title">${report.name}</div>
|
||||
<div class="small">EPG host: ${report.epg_host || '—'}${report.m3u_host ? ' · M3U host: ' + report.m3u_host : ''}</div>
|
||||
</div>
|
||||
<span class="pill">${epgHealthy ? 'Healthy XMLTV' : 'Check source'}</span>
|
||||
<span class="pill">${epgHealthy ? `${qualityLabel(score)} XMLTV · ${score}%` : 'Check source'}</span>
|
||||
</div>
|
||||
<div class="split">
|
||||
<div class="panel">
|
||||
<h3>XMLTV</h3>
|
||||
<div class="kv">
|
||||
<div>Status</div><div>${statusHtml(epgHealthy, labels)}</div>
|
||||
<div>Quality score</div><div>${epgHealthy ? `${score}% · ${qualityLabel(score)}` : '—'}</div>
|
||||
<div>URL</div><div class="mono">${report.epg_url}</div>
|
||||
<div>HTTP</div><div>${report.epg_fetch.status}${report.epg_fetch.error ? ' · ' + report.epg_fetch.error : ''}</div>
|
||||
<div>Response time</div><div>${Number(report.epg_fetch.time_total).toFixed(2)} s</div>
|
||||
|
||||
Reference in New Issue
Block a user