Fix HLS proxy fallback and avoid overwriting invalid config
This commit is contained in:
@@ -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(); }
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,8 @@ $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 (is_array($existing)) {
|
||||||
if (isset($existing['epg_url']) && !isset($existing['epg_sources'])) {
|
if (isset($existing['epg_url']) && !isset($existing['epg_sources'])) {
|
||||||
$existing['epg_sources'] = [[
|
$existing['epg_sources'] = [[
|
||||||
'name' => 'Main',
|
'name' => 'Main',
|
||||||
@@ -19,13 +20,14 @@ if (file_exists($config_path)) {
|
|||||||
$existing['admin_key'] = bin2hex(random_bytes(16));
|
$existing['admin_key'] = bin2hex(random_bytes(16));
|
||||||
file_put_contents($config_path, json_encode($existing, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
|
file_put_contents($config_path, json_encode($existing, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$is_first_setup = !file_exists($config_path);
|
$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;
|
||||||
|
|||||||
Reference in New Issue
Block a user