Fix HLS proxy fallback and avoid overwriting invalid config

This commit is contained in:
Johnnybegood90
2026-03-14 13:16:29 +01:00
2 changed files with 23 additions and 16 deletions
+5
View File
@@ -166,7 +166,12 @@ if ($is_segment) {
if (ob_get_level()) ob_end_clean(); if (ob_get_level()) ob_end_clean();
// Resolve redirects with HEAD first so we do not download the segment twice. // Resolve redirects with HEAD first so we do not download the segment twice.
// Some HLS/CDN servers reject HEAD on media objects even when GET works.
[$code, , , $final_url] = fetch_with_checked_redirects($url, $allowed_hosts, true); [$code, , , $final_url] = fetch_with_checked_redirects($url, $allowed_hosts, true);
if ($code === 403 || $code === 405) {
[, , , $final_url] = fetch_with_checked_redirects($url, $allowed_hosts, false);
$code = 200;
}
if ($code >= 400) { http_response_code($code); die(); } if ($code >= 400) { http_response_code($code); die(); }
+18 -16
View File
@@ -3,21 +3,23 @@ $config_path = __DIR__ . '/config.json';
// Automatically migrate the legacy config format. // Automatically migrate the legacy config format.
if (file_exists($config_path)) { if (file_exists($config_path)) {
$existing = json_decode(file_get_contents($config_path), true) ?? []; $existing = json_decode(file_get_contents($config_path), true);
if (isset($existing['epg_url']) && !isset($existing['epg_sources'])) { if (is_array($existing)) {
$existing['epg_sources'] = [[ if (isset($existing['epg_url']) && !isset($existing['epg_sources'])) {
'name' => 'Main', $existing['epg_sources'] = [[
'epg_url' => $existing['epg_url'], 'name' => 'Main',
'm3u_url' => $existing['m3u_url'] ?? '', 'epg_url' => $existing['epg_url'],
]]; 'm3u_url' => $existing['m3u_url'] ?? '',
$existing['allow_personal_epg'] = false; ]];
unset($existing['epg_url'], $existing['m3u_url']); $existing['allow_personal_epg'] = false;
file_put_contents($config_path, json_encode($existing, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)); unset($existing['epg_url'], $existing['m3u_url']);
} file_put_contents($config_path, json_encode($existing, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
// Bootstrap an admin key for older configs that do not have one yet. }
if (empty($existing['admin_key'])) { // Bootstrap an admin key for older configs that do not have one yet.
$existing['admin_key'] = bin2hex(random_bytes(16)); if (empty($existing['admin_key'])) {
file_put_contents($config_path, json_encode($existing, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)); $existing['admin_key'] = bin2hex(random_bytes(16));
file_put_contents($config_path, json_encode($existing, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
}
} }
} }
@@ -25,7 +27,7 @@ $is_first_setup = !file_exists($config_path);
$existing = []; $existing = [];
$corrupt_config = false; $corrupt_config = false;
if (!$is_first_setup) { if (!$is_first_setup) {
$existing = json_decode(file_get_contents($config_path), true) ?? []; $existing = json_decode(file_get_contents($config_path), true);
if (!is_array($existing)) { if (!is_array($existing)) {
$existing = []; $existing = [];
$corrupt_config = true; $corrupt_config = true;