Files
Johnnybegood90 9b068e7c74 Add program reminders and category filtering to the guide UI
Enhance health diagnostics with EPG quality and source metrics
2026-03-17 03:10:21 +01:00

539 lines
26 KiB
PHP

<?php
require_once __DIR__ . '/src/lib/admin.php';
function health_status_class(bool $ok): string {
return $ok ? 'ok' : 'ko';
}
function health_parse_xmltv(string $xml): array {
if (!class_exists('DOMDocument')) {
return ['ok' => false, 'error' => 'PHP DOM/XML extension is not installed.'];
}
if ($xml === '') {
return ['ok' => false, 'error' => 'Empty response'];
}
libxml_use_internal_errors(true);
$dom = new DOMDocument();
$loaded = $dom->loadXML($xml, LIBXML_NOERROR | LIBXML_NOWARNING);
$errors = array_map(static fn($e) => trim($e->message), libxml_get_errors());
libxml_clear_errors();
if (!$loaded) {
return ['ok' => false, 'error' => $errors[0] ?? 'Invalid XML'];
}
$xp = new DOMXPath($dom);
$programmes = $xp->query('/tv/programme');
$channels = $xp->query('/tv/channel');
$categories = $xp->query('/tv/programme/category');
$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' => $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,
];
}
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;
if (stripos($line, '#EXTINF') === 0) {
$extinf++;
continue;
}
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,
'http_streams' => $http,
'https_streams' => $https,
'duplicate_urls' => $duplicates,
'size_bytes' => strlen($body),
];
}
function health_format_xmltv_stamp(?string $stamp): string {
if (!$stamp) return '—';
$dt = DateTime::createFromFormat('YmdHis O', $stamp);
if (!$dt) return $stamp;
return $dt->format('d/m/Y H:i');
}
function health_probe_payload(): array {
$config_path = gridtv_config_path();
$config_exists = file_exists($config_path);
$config_valid = false;
$config = [];
if ($config_exists) {
$decoded = json_decode(file_get_contents($config_path), true);
if (is_array($decoded)) {
$config = $decoded;
$config_valid = true;
}
}
$sources = $config_valid ? array_values($config['epg_sources'] ?? []) : [];
$first_source = $sources[0] ?? null;
$checks = [
'config_exists' => $config_exists,
'config_valid' => $config_valid,
'php_curl' => extension_loaded('curl'),
'php_xml' => class_exists('DOMDocument'),
'source_configured' => !empty($sources),
];
$details = [
'group_name' => $config['group_name'] ?? 'GridTV',
'source_count' => count($sources),
];
if ($first_source && !empty($first_source['epg_url'])) {
$fetch = gridtv_fetch_url((string) $first_source['epg_url'], 12);
$checks['xmltv_reachable'] = $fetch['ok'];
$details['xmltv_status'] = $fetch['status'];
$details['xmltv_time_total'] = round((float) $fetch['time_total'], 3);
if ($fetch['ok']) {
$stats = health_parse_xmltv($fetch['body']);
$checks['xmltv_valid'] = !empty($stats['ok']);
if (!empty($stats['ok'])) {
$details['xmltv_channels'] = $stats['channels'];
$details['xmltv_programmes'] = $stats['programmes'];
} else {
$details['xmltv_error'] = $stats['error'] ?? 'Invalid XMLTV';
}
} else {
$details['xmltv_error'] = $fetch['error'] ?: ('HTTP ' . $fetch['status']);
}
} else {
$checks['xmltv_reachable'] = false;
$details['xmltv_error'] = 'No XMLTV source configured';
}
$ok = !in_array(false, $checks, true);
return [
'ok' => $ok,
'status' => $ok ? 'ok' : 'degraded',
'timestamp' => gmdate('c'),
'checks' => $checks,
'details' => $details,
];
}
function health_build_payload(array $config, string $locale): array {
$config_path = gridtv_config_path();
$config_exists = file_exists($config_path);
$config_writable = $config_exists ? is_writable($config_path) : is_writable(dirname($config_path));
$sources = array_values($config['epg_sources'] ?? []);
$checks = [
[
'label' => 'Config file',
'ok' => $config_exists,
'detail' => $config_exists ? basename($config_path) . ' found' : 'Missing config.json',
],
[
'label' => 'Config writable',
'ok' => $config_writable,
'detail' => $config_writable ? 'Writable by PHP' : 'Not writable by PHP',
],
[
'label' => 'PHP version',
'ok' => version_compare(PHP_VERSION, '8.0.0', '>='),
'detail' => 'PHP ' . PHP_VERSION,
],
[
'label' => 'php-curl',
'ok' => extension_loaded('curl'),
'detail' => extension_loaded('curl') ? 'Extension loaded' : 'Missing php-curl',
],
[
'label' => 'php-xml / DOM',
'ok' => class_exists('DOMDocument'),
'detail' => class_exists('DOMDocument') ? 'Extension loaded' : 'Missing php-xml / DOM',
],
[
'label' => 'Configured sources',
'ok' => count($sources) > 0,
'detail' => count($sources) . ' source(s) in config',
],
];
$source_reports = [];
foreach ($sources as $index => $source) {
$epg_url = trim((string) ($source['epg_url'] ?? ''));
$m3u_url = trim((string) ($source['m3u_url'] ?? ''));
$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;
if ($m3u_url !== '') {
$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),
'epg_url' => $epg_url,
'm3u_url' => $m3u_url,
'epg_host' => gridtv_extract_host($epg_url),
'm3u_host' => gridtv_extract_host($m3u_url),
'epg_fetch' => $epg_fetch_public,
'epg_stats' => $epg_stats,
'm3u_fetch' => $m3u_fetch_public,
'm3u_stats' => $m3u_stats,
];
}
return [
'summary' => [
'group_name' => $config['group_name'] ?? 'GridTV',
'source_count' => count($sources),
'locale' => strtoupper($locale),
'config_size' => $config_exists ? gridtv_format_bytes((int) filesize($config_path)) : '0 B',
'config_path' => $config_path,
],
'checks' => $checks,
'sources' => $source_reports,
'helpers' => [
'status_ok' => 'OK',
'status_bad' => 'Issue',
],
];
}
if (isset($_GET['format']) && $_GET['format'] === 'probe') {
$payload = health_probe_payload();
http_response_code($payload['ok'] ? 200 : 503);
if (isset($_GET['plain']) && $_GET['plain'] === '1') {
header('Content-Type: text/plain; charset=UTF-8');
echo $payload['ok'] ? 'OK' : 'KO';
} else {
header('Content-Type: application/json; charset=UTF-8');
echo json_encode($payload, JSON_UNESCAPED_SLASHES);
}
exit;
}
$config = gridtv_load_config();
gridtv_require_admin($config, 'Health');
[$locale, $L] = gridtv_load_locale($config);
if (isset($_GET['format']) && $_GET['format'] === 'json') {
header('Content-Type: application/json; charset=UTF-8');
echo json_encode(health_build_payload($config, $locale), JSON_UNESCAPED_SLASHES);
exit;
}
?><!DOCTYPE html>
<html lang="<?= htmlspecialchars($locale) ?>">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>GridTV — Health</title>
<link rel="stylesheet" href="/assets/fonts/fonts.css">
<style>
:root{--bg:#0b0d10;--surface:#13161b;--surface2:#1a1f27;--border:#2a3240;--accent:#e8c842;--accent2:#5ec0ff;--text:#eaf0f6;--muted:#8f9aac;--ok:#4fd18b;--warn:#ff6767}
*{box-sizing:border-box}body{margin:0;background:radial-gradient(circle at top left,#1b2330 0,#0b0d10 48%);color:var(--text);font-family:'Barlow Condensed',sans-serif}
.page{max-width:1200px;margin:0 auto;padding:32px 20px 56px}
.hero{display:flex;justify-content:space-between;gap:18px;align-items:flex-end;margin-bottom:24px}
.logo{font-family:'Share Tech Mono',monospace;font-size:26px;letter-spacing:.12em;color:var(--accent);text-transform:uppercase}
.subtitle{color:var(--muted);font-size:14px;max-width:700px;line-height:1.5}
.actions{display:flex;gap:10px;flex-wrap:wrap}.btn{display:inline-flex;align-items:center;gap:8px;padding:11px 14px;border:1px solid var(--border);background:var(--surface);color:var(--text);text-decoration:none;font-size:13px;letter-spacing:.08em;text-transform:uppercase}.btn-primary{background:var(--accent);color:#000;border-color:var(--accent)}
.probe-box{margin-bottom:20px;padding:18px 20px;background:rgba(19,22,27,.95);border:1px solid var(--border)}
.probe-box h2{margin:0 0 10px;font-size:18px;letter-spacing:.06em;text-transform:uppercase}
.probe-box p{margin:0 0 12px;color:var(--muted);font-size:13px;line-height:1.5}
.probe-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(280px,1fr));gap:12px}
.probe-item{padding:12px;background:var(--surface2);border:1px solid var(--border)}
.probe-item .eyebrow{margin-bottom:6px}
.grid,.checks,.source-list{display:grid;gap:14px}.grid{grid-template-columns:repeat(auto-fit,minmax(220px,1fr));margin-bottom:22px}.checks{grid-template-columns:repeat(auto-fit,minmax(220px,1fr));margin-bottom:24px}.source-list{gap:18px}
.card,.source,.check{background:rgba(19,22,27,.95);border:1px solid var(--border)}.card,.check,.source{padding:16px}.source{padding:20px}
.eyebrow{font-family:'Share Tech Mono',monospace;font-size:11px;color:var(--accent2);letter-spacing:.12em;text-transform:uppercase;margin-bottom:10px}.value{font-size:28px;font-weight:700}.small{font-size:13px;color:var(--muted)}
.status{display:inline-flex;align-items:center;gap:8px;font-family:'Share Tech Mono',monospace;font-size:11px;letter-spacing:.1em;text-transform:uppercase}.status::before{content:'';width:10px;height:10px;border-radius:50%}.status.ok{color:var(--ok)}.status.ok::before{background:var(--ok)}.status.ko{color:var(--warn)}.status.ko::before{background:var(--warn)}
.source-head{display:flex;justify-content:space-between;gap:14px;align-items:flex-start;margin-bottom:16px}.source-title{font-size:24px;font-weight:700}.pill{display:inline-block;padding:6px 10px;font-family:'Share Tech Mono',monospace;font-size:11px;letter-spacing:.1em;text-transform:uppercase;background:var(--surface2);border:1px solid var(--border);color:var(--accent2)}
.split{display:grid;grid-template-columns:repeat(auto-fit,minmax(280px,1fr));gap:14px}.panel{padding:16px;background:var(--surface2);border:1px solid var(--border)}.panel h3{margin:0 0 10px;font-size:16px;letter-spacing:.06em;text-transform:uppercase}
.kv{display:grid;grid-template-columns:160px 1fr;gap:8px;font-size:14px;line-height:1.45}.kv div:nth-child(odd){color:var(--muted)}.mono{font-family:'Share Tech Mono',monospace;font-size:12px;word-break:break-all}
.skeleton{position:relative;overflow:hidden}.skeleton::after{content:'';position:absolute;inset:0;background:linear-gradient(90deg,transparent,rgba(255,255,255,.08),transparent);transform:translateX(-100%);animation:shine 1.5s infinite}.skeleton-line{height:16px;background:#1c2430;margin-top:8px}.skeleton-line.short{width:42%}.splash{display:flex;align-items:center;gap:14px;padding:18px 20px;margin-bottom:20px;background:rgba(19,22,27,.95);border:1px solid var(--border)}.spinner{width:22px;height:22px;border:3px solid rgba(94,192,255,.18);border-top-color:var(--accent2);border-radius:50%;animation:spin 1s linear infinite}
.hidden{display:none!important}
@keyframes spin{to{transform:rotate(360deg)}}@keyframes shine{100%{transform:translateX(100%)}}@media (max-width:700px){.hero{flex-direction:column;align-items:flex-start}.kv{grid-template-columns:1fr}}
</style>
</head>
<body>
<div class="page">
<div class="hero">
<div>
<div class="logo">GridTV / Health</div>
<div class="subtitle">Page de diagnostic admin. L’écran apparaît tout de suite, puis les checks XMLTV/M3U se remplissent en arrière-plan.</div>
</div>
<div class="actions">
<a class="btn btn-primary" href="/export.php">Export 24h</a>
<a class="btn" href="/setup.php">Setup</a>
<a class="btn" href="/index.php">Guide</a>
</div>
</div>
<div class="splash" id="splash">
<div class="spinner"></div>
<div>
<div style="font-size:18px;font-weight:700">Loading diagnostics…</div>
<div class="small">Configuration, XMLTV et M3U sont testés en arrière-plan.</div>
</div>
</div>
<section class="probe-box">
<h2>Monitoring probe</h2>
<p>Use these public endpoints with Uptime Kuma or any HTTP monitoring tool. They return <code>200</code> when the instance is healthy and <code>503</code> when a critical check fails.</p>
<div class="probe-grid">
<div class="probe-item">
<div class="eyebrow">JSON probe</div>
<div class="mono"><?= htmlspecialchars(strtok($_SERVER['REQUEST_URI'] ?? '/health.php', '?')) ?>?format=probe</div>
</div>
<div class="probe-item">
<div class="eyebrow">Plain text probe</div>
<div class="mono"><?= htmlspecialchars(strtok($_SERVER['REQUEST_URI'] ?? '/health.php', '?')) ?>?format=probe&amp;plain=1</div>
</div>
</div>
</section>
<div class="grid" id="summaryGrid">
<div class="card skeleton"><div class="eyebrow">Group</div><div class="skeleton-line"></div><div class="skeleton-line short"></div></div>
<div class="card skeleton"><div class="eyebrow">Sources</div><div class="skeleton-line"></div><div class="skeleton-line short"></div></div>
<div class="card skeleton"><div class="eyebrow">Locale</div><div class="skeleton-line"></div><div class="skeleton-line short"></div></div>
<div class="card skeleton"><div class="eyebrow">Config Size</div><div class="skeleton-line"></div><div class="skeleton-line short"></div></div>
</div>
<div class="checks" id="checksGrid">
<div class="check skeleton"><div class="skeleton-line"></div><div class="skeleton-line short"></div></div>
<div class="check skeleton"><div class="skeleton-line"></div><div class="skeleton-line short"></div></div>
<div class="check skeleton"><div class="skeleton-line"></div><div class="skeleton-line short"></div></div>
</div>
<div class="source-list" id="sourceList">
<div class="source skeleton"><div class="skeleton-line"></div><div class="skeleton-line"></div><div class="skeleton-line short"></div></div>
</div>
</div>
<script>
const healthUrl = '<?= htmlspecialchars(strtok($_SERVER['REQUEST_URI'] ?? '/health.php', '?')) ?>?format=json';
function statusHtml(ok, labels) {
const cls = ok ? 'ok' : 'ko';
return `<span class="status ${cls}">${ok ? labels.status_ok : labels.status_bad}</span>`;
}
function renderSummary(summary) {
document.getElementById('summaryGrid').innerHTML = `
<div class="card"><div class="eyebrow">Group</div><div class="value">${summary.group_name}</div><div class="small">Configured TV group name</div></div>
<div class="card"><div class="eyebrow">Sources</div><div class="value">${summary.source_count}</div><div class="small">Configured XMLTV sources</div></div>
<div class="card"><div class="eyebrow">Locale</div><div class="value">${summary.locale}</div><div class="small">Detected UI locale</div></div>
<div class="card"><div class="eyebrow">Config Size</div><div class="value">${summary.config_size}</div><div class="small">${summary.config_path}</div></div>
`;
}
function renderChecks(checks, labels) {
document.getElementById('checksGrid').innerHTML = checks.map(check => `
<div class="check">
${statusHtml(check.ok, labels)}
<div style="font-size:18px;font-weight:700;margin:8px 0 6px">${check.label}</div>
<div class="small">${check.detail}</div>
</div>
`).join('');
}
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>` : `
<div class="kv">
<div>Status</div><div>${statusHtml(m3uHealthy, labels)}</div>
<div>URL</div><div class="mono">${report.m3u_url}</div>
<div>HTTP</div><div>${report.m3u_fetch.status || 0}${report.m3u_fetch.error ? ' · ' + report.m3u_fetch.error : ''}</div>
<div>Response time</div><div>${Number(report.m3u_fetch.time_total || 0).toFixed(2)} s</div>
${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>`;
return `
<section class="source">
<div class="source-head">
<div>
<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 ? `${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>
${epgRows}
</div>
</div>
<div class="panel">
<h3>M3U</h3>
${m3uRows}
</div>
</div>
</section>
`;
}).join('');
}
fetch(healthUrl, {credentials: 'same-origin'})
.then(r => r.json())
.then(data => {
renderSummary(data.summary);
renderChecks(data.checks, data.helpers);
renderSources(data.sources, data.helpers);
document.getElementById('splash').classList.add('hidden');
})
.catch(err => {
document.getElementById('splash').innerHTML = `<div><div style="font-size:18px;font-weight:700;color:#ff6767">Unable to load diagnostics</div><div class="small">${err.message}</div></div>`;
});
</script>
</body>
</html>