fix: preserve live streams on title edits

This commit is contained in:
hajimi
2026-06-21 13:44:05 +08:00
parent 08c1affb14
commit 75a529be35
6 changed files with 140 additions and 22 deletions
+56 -9
View File
@@ -105,17 +105,64 @@ if (!is_file($matchLiveLogicPath)) {
$matchLiveLogic = file_get_contents($matchLiveLogicPath);
foreach ([
"'play_url_m3u8' => ''",
"'play_url_hd_m3u8' => ''",
"'play_url_flv' => ''",
"'play_url_hd_flv' => ''",
"'fetch_status' => 0",
"'fetch_error' => ''",
"'last_fetch_at' => 0",
"'next_fetch_at' => \$now",
'$sourceUrl = trim((string) $params[\'source_url\']);',
'$sourceUrlChanged = $sourceUrl !== trim((string) $live->source_url);',
"'source_url' => \$sourceUrl",
'if ($sourceUrlChanged) {',
"\$saveData['play_url_m3u8'] = '';",
"\$saveData['play_url_hd_m3u8'] = '';",
"\$saveData['play_url_flv'] = '';",
"\$saveData['play_url_hd_flv'] = '';",
"\$saveData['fetch_status'] = 0;",
"\$saveData['fetch_error'] = '';",
"\$saveData['last_fetch_at'] = 0;",
"\$saveData['next_fetch_at'] = \$now;",
'$live->save($saveData);',
] as $needle) {
if (strpos($matchLiveLogic, $needle) === false) {
fwrite(STDERR, "missing match live logic reset token: {$needle}\n");
fwrite(STDERR, "missing match live logic source-url reset guard token: {$needle}\n");
exit(1);
}
}
$savePos = strpos($matchLiveLogic, '$live->save($saveData);');
$guardPos = strpos($matchLiveLogic, 'if ($sourceUrlChanged) {');
if ($savePos === false || $guardPos === false || $guardPos > $savePos) {
fwrite(STDERR, "match live logic must guard crawler resets inside source_url change branch\n");
exit(1);
}
$guardBody = substr($matchLiveLogic, $guardPos, $savePos - $guardPos);
foreach ([
"\$saveData['play_url_m3u8'] = '';",
"\$saveData['play_url_hd_m3u8'] = '';",
"\$saveData['play_url_flv'] = '';",
"\$saveData['play_url_hd_flv'] = '';",
"\$saveData['fetch_status'] = 0;",
"\$saveData['fetch_error'] = '';",
"\$saveData['last_fetch_at'] = 0;",
"\$saveData['next_fetch_at'] = \$now;",
] as $needle) {
if (strpos($guardBody, $needle) === false) {
fwrite(STDERR, "match live logic reset token not scoped to source_url change guard: {$needle}\n");
exit(1);
}
}
$unconditionalSaveBody = preg_replace('/if \\(\\$sourceUrlChanged\\) \\{.*?\\}/s', '', $matchLiveLogic, 1);
foreach ([
"\$saveData['play_url_m3u8'] = '';",
"\$saveData['play_url_hd_m3u8'] = '';",
"\$saveData['play_url_flv'] = '';",
"\$saveData['play_url_hd_flv'] = '';",
"\$saveData['fetch_status'] = 0;",
"\$saveData['fetch_error'] = '';",
"\$saveData['last_fetch_at'] = 0;",
"\$saveData['next_fetch_at'] = \$now;",
] as $needle) {
if (strpos($unconditionalSaveBody, $needle) !== false) {
fwrite(STDERR, "match live logic still unconditionally resets crawler state: {$needle}\n");
exit(1);
}
}