Fix HLS proxy fallback and avoid overwriting invalid config

This commit is contained in:
Johnnybegood90
2026-03-14 13:16:09 +01:00
parent 90679e9221
commit fc608ee0e0
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();
// 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);
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(); }
+4 -2
View File
@@ -3,7 +3,8 @@ $config_path = __DIR__ . '/config.json';
// Automatically migrate the legacy config format.
if (file_exists($config_path)) {
$existing = json_decode(file_get_contents($config_path), true) ?? [];
$existing = json_decode(file_get_contents($config_path), true);
if (is_array($existing)) {
if (isset($existing['epg_url']) && !isset($existing['epg_sources'])) {
$existing['epg_sources'] = [[
'name' => 'Main',
@@ -20,12 +21,13 @@ if (file_exists($config_path)) {
file_put_contents($config_path, json_encode($existing, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
}
}
}
$is_first_setup = !file_exists($config_path);
$existing = [];
$corrupt_config = false;
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)) {
$existing = [];
$corrupt_config = true;