diff --git a/health.php b/health.php
index 7e95ee8..1e4f019 100644
--- a/health.php
+++ b/health.php
@@ -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 ? `
Channels
${report.epg_stats.channels}
Programmes
${report.epg_stats.programmes}
+ Channel logos
${report.epg_stats.channel_icons} (${report.epg_stats.channels_without_icon} missing)
+ Descriptions
${report.epg_stats.programmes_with_desc} (${percent(report.epg_stats.programmes_with_desc, report.epg_stats.programmes)})
+ Categories coverage
${report.epg_stats.programmes_with_category} (${percent(report.epg_stats.programmes_with_category, report.epg_stats.programmes)})
+ Subtitle coverage
${report.epg_stats.programmes_with_subtitle} (${percent(report.epg_stats.programmes_with_subtitle, report.epg_stats.programmes)})
+ Rating coverage
${report.epg_stats.programmes_with_rating} (${percent(report.epg_stats.programmes_with_rating, report.epg_stats.programmes)})
+ Date coverage
${report.epg_stats.programmes_with_date} (${percent(report.epg_stats.programmes_with_date, report.epg_stats.programmes)})
+ Stop time coverage
${report.epg_stats.programmes_with_stop} (${percent(report.epg_stats.programmes_with_stop, report.epg_stats.programmes)})
+ Unique categories
${report.epg_stats.unique_categories}
+ Programmes / channel
${report.epg_stats.avg_programmes_per_channel}
Sub-titles
${report.epg_stats.subtitles}
Ratings
${report.epg_stats.ratings}
Categories
${report.epg_stats.categories}
Date tags
${report.epg_stats.dates}
Window
${report.epg_stats.first_start || '—'} → ${report.epg_stats.last_stop || '—'}
+ Window (local)
${report.epg_stats.first_start_local || '—'} → ${report.epg_stats.last_stop_local || '—'}
Content-Type
${report.epg_fetch.content_type || '—'}
+ Final URL
${report.epg_fetch.final_url || report.epg_url}
+ Payload size
${report.epg_fetch.headers['content-length'] || report.epg_fetch.body_bytes || '—'} bytes
` : `Parse
${report.epg_stats.error || 'Unable to read XMLTV'}
`;
const m3uRows = !report.m3u_url ? `No M3U URL configured for this source.
` : `
@@ -384,7 +482,12 @@ function renderSources(sources, labels) {
${report.m3u_fetch.ok && report.m3u_stats ? `
Streams
${report.m3u_stats.streams}
#EXTINF
${report.m3u_stats.extinf}
+ HTTPS streams
${report.m3u_stats.https_streams}
+ HTTP streams
${report.m3u_stats.http_streams}
+ Duplicate URLs
${report.m3u_stats.duplicate_urls}
+ Payload size
${report.m3u_fetch.headers['content-length'] || report.m3u_fetch.body_bytes || report.m3u_stats.size_bytes} bytes
Content-Type
${report.m3u_fetch.content_type || '—'}
+ Final URL
${report.m3u_fetch.final_url || report.m3u_url}
` : `Parse
Unable to load playlist.
`}
`;
@@ -395,13 +498,14 @@ function renderSources(sources, labels) {
${report.name}
EPG host: ${report.epg_host || '—'}${report.m3u_host ? ' · M3U host: ' + report.m3u_host : ''}
- ${epgHealthy ? 'Healthy XMLTV' : 'Check source'}
+ ${epgHealthy ? `${qualityLabel(score)} XMLTV · ${score}%` : 'Check source'}
XMLTV
Status
${statusHtml(epgHealthy, labels)}
+
Quality score
${epgHealthy ? `${score}% · ${qualityLabel(score)}` : '—'}
URL
${report.epg_url}
HTTP
${report.epg_fetch.status}${report.epg_fetch.error ? ' · ' + report.epg_fetch.error : ''}
Response time
${Number(report.epg_fetch.time_total).toFixed(2)} s
diff --git a/locales/en.json b/locales/en.json
index 2dc5931..20b6243 100644
--- a/locales/en.json
+++ b/locales/en.json
@@ -32,10 +32,28 @@
"search_placeholder": "Search channel or program...",
"copy_epg": "EPG",
"copy_m3u": "M3U",
+ "category_filter_title": "Filter by category",
+ "category_all": "All categories",
"copied": "✓ copied",
"program_info": "Program info",
"watch_now": "Watch now",
"imdb_search": "Search on IMDb",
+ "reminder_button": "Reminder",
+ "reminder_title": "Notify me before broadcast",
+ "reminder_save": "Enable reminder",
+ "reminder_remove": "Remove reminder",
+ "reminder_when": "A browser notification will be sent {minutes} minutes before broadcast.",
+ "reminder_when_soon": "This program starts soon. The reminder will fire almost immediately.",
+ "reminder_status_idle": "No reminder active.",
+ "reminder_status_set": "Reminder active for {time}.",
+ "reminder_status_started": "This program is already airing.",
+ "reminder_saved": "Reminder enabled.",
+ "reminder_removed": "Reminder removed.",
+ "reminder_error_unsupported": "This browser does not support notifications.",
+ "reminder_error_denied": "Notifications are blocked in this browser.",
+ "reminder_error_generic": "Unable to enable reminder.",
+ "reminder_notification_title": "GridTV reminder",
+ "reminder_notification_body": "\"{title}\" starts at {time} on {channel}.",
"close": "Close",
"duration_min": "min",
"personal_epg_title": "Personal EPG",
diff --git a/locales/es.json b/locales/es.json
index 3f84350..f365a40 100644
--- a/locales/es.json
+++ b/locales/es.json
@@ -32,10 +32,28 @@
"search_placeholder": "Buscar canal o programa...",
"copy_epg": "EPG",
"copy_m3u": "M3U",
+ "category_filter_title": "Filtrar por categoría",
+ "category_all": "Todas las categorías",
"copied": "✓ copiado",
"program_info": "Info del programa",
"watch_now": "Ver ahora",
"imdb_search": "Buscar en IMDb",
+ "reminder_button": "Recordatorio",
+ "reminder_title": "Avísame antes de la emisión",
+ "reminder_save": "Activar recordatorio",
+ "reminder_remove": "Eliminar recordatorio",
+ "reminder_when": "Se enviará una notificación del navegador {minutes} minutos antes de la emisión.",
+ "reminder_when_soon": "Este programa empieza pronto. El recordatorio saldrá casi de inmediato.",
+ "reminder_status_idle": "No hay recordatorio activo.",
+ "reminder_status_set": "Recordatorio activo para las {time}.",
+ "reminder_status_started": "Este programa ya está en emisión.",
+ "reminder_saved": "Recordatorio activado.",
+ "reminder_removed": "Recordatorio eliminado.",
+ "reminder_error_unsupported": "Este navegador no admite notificaciones.",
+ "reminder_error_denied": "Las notificaciones están bloqueadas en este navegador.",
+ "reminder_error_generic": "No se puede activar el recordatorio.",
+ "reminder_notification_title": "Recordatorio GridTV",
+ "reminder_notification_body": "\"{title}\" empieza a las {time} en {channel}.",
"close": "Cerrar",
"duration_min": "min",
"personal_epg_title": "EPG Personal",
diff --git a/locales/fr.json b/locales/fr.json
index 0094539..5356344 100644
--- a/locales/fr.json
+++ b/locales/fr.json
@@ -32,10 +32,28 @@
"search_placeholder": "Rechercher une chaîne ou un programme...",
"copy_epg": "EPG",
"copy_m3u": "M3U",
+ "category_filter_title": "Filtrer par catégorie",
+ "category_all": "Toutes catégories",
"copied": "✓ copié",
"program_info": "Infos programme",
"watch_now": "Regarder",
"imdb_search": "Rechercher sur IMDb",
+ "reminder_button": "Rappel",
+ "reminder_title": "Préviens-moi avant la diffusion",
+ "reminder_save": "Activer le rappel",
+ "reminder_remove": "Supprimer le rappel",
+ "reminder_when": "Une notification navigateur sera envoyée {minutes} minutes avant la diffusion.",
+ "reminder_when_soon": "Ce programme commence bientôt. Le rappel partira presque immédiatement.",
+ "reminder_status_idle": "Aucun rappel actif.",
+ "reminder_status_set": "Rappel actif pour {time}.",
+ "reminder_status_started": "Ce programme est déjà en cours.",
+ "reminder_saved": "Rappel activé.",
+ "reminder_removed": "Rappel supprimé.",
+ "reminder_error_unsupported": "Ce navigateur ne gère pas les notifications.",
+ "reminder_error_denied": "Les notifications sont bloquées dans ce navigateur.",
+ "reminder_error_generic": "Impossible d'activer le rappel.",
+ "reminder_notification_title": "Rappel GridTV",
+ "reminder_notification_body": "“{title}” commence à {time} sur {channel}.",
"close": "Fermer",
"duration_min": "min",
"personal_epg_title": "EPG Personnel",
diff --git a/setup.php b/setup.php
index bb88005..973c570 100644
--- a/setup.php
+++ b/setup.php
@@ -216,7 +216,7 @@ $submitted_key = trim($_POST['admin_key_input'] ?? $_POST['admin_key_hidden']
GridTV is already configured.
Enter your admin key to edit the settings.
@@ -349,6 +349,41 @@ function syncPersonalM3uToggle() {
}
allowPersonalEpgToggle?.addEventListener('change', syncPersonalM3uToggle);
syncPersonalM3uToggle();
+
+const GRIDTV_ADMIN_KEY_STORAGE = 'gridtv-admin-key';
+const setupAdminKeyInput = document.getElementById('setupAdminKeyInput');
+const setupAdminHiddenInput = document.querySelector('input[name="admin_key_hidden"]');
+
+try {
+ const savedAdminKey = localStorage.getItem(GRIDTV_ADMIN_KEY_STORAGE) || '';
+ if (setupAdminKeyInput && savedAdminKey) setupAdminKeyInput.value = savedAdminKey;
+ if (setupAdminHiddenInput && savedAdminKey) setupAdminHiddenInput.value = savedAdminKey;
+} catch (_) {}
+
+if (setupAdminKeyInput?.form) {
+ setupAdminKeyInput.form.addEventListener('submit', () => {
+ try {
+ localStorage.setItem(GRIDTV_ADMIN_KEY_STORAGE, setupAdminKeyInput.value.trim());
+ } catch (_) {}
+ });
+}
+
+if (setupAdminHiddenInput?.form) {
+ const persistHiddenAdminKey = () => {
+ try {
+ const currentKey = setupAdminHiddenInput.value.trim();
+ if (currentKey) localStorage.setItem(GRIDTV_ADMIN_KEY_STORAGE, currentKey);
+ } catch (_) {}
+ };
+ persistHiddenAdminKey();
+ setupAdminHiddenInput.form.addEventListener('submit', persistHiddenAdminKey);
+}
+
+
+try {
+ localStorage.setItem(GRIDTV_ADMIN_KEY_STORAGE, = json_encode($new_key) ?>);
+} catch (_) {}
+