|
| 1 | +#!/usr/bin/env python3 |
| 2 | +from __future__ import annotations |
| 3 | + |
| 4 | +import importlib.util |
| 5 | +from pathlib import Path |
| 6 | + |
| 7 | +ROOT = Path(__file__).resolve().parents[1] |
| 8 | +V3 = ROOT / 'scripts' / 'tmp_apply_strict_content_fix_v3.py' |
| 9 | +spec = importlib.util.spec_from_file_location('strict_fix_v3', V3) |
| 10 | +if spec is None or spec.loader is None: |
| 11 | + raise RuntimeError('cannot load strict content fix v3') |
| 12 | +mod = importlib.util.module_from_spec(spec) |
| 13 | +spec.loader.exec_module(mod) |
| 14 | + |
| 15 | +# Importing v3 executes its top-level patch sequence before this refinement. |
| 16 | +path = ROOT / 'scripts' / 'nuvio_client_lab.cjs' |
| 17 | +text = path.read_text(encoding='utf-8') |
| 18 | +needle = """ const strongIdentityLabels = [stream?.title, stream?.filename, mediaFilename] |
| 19 | + .map((value) => String(value || '').trim()) |
| 20 | + .filter(Boolean); |
| 21 | + for (const strongLabel of strongIdentityLabels) { |
| 22 | +""" |
| 23 | +replacement = """ const strongIdentityLabels = [stream?.title, stream?.filename, mediaFilename] |
| 24 | + .map((value) => String(value || '').trim()) |
| 25 | + .filter(Boolean); |
| 26 | + if (normalized && forbiddenAliases.some((alias) => normalized.includes(alias))) return { status: 'contradiction', reason: 'forbidden_title_alias' }; |
| 27 | + for (const strongLabel of strongIdentityLabels) { |
| 28 | +""" |
| 29 | +if needle not in text: |
| 30 | + raise RuntimeError('strong identity block missing after v3 patch') |
| 31 | +text = text.replace(needle, replacement, 1) |
| 32 | +late = " if (normalized && forbiddenAliases.some((alias) => normalized.includes(alias))) return { status: 'contradiction', reason: 'forbidden_title_alias' };\n if (normalized && expected.some((alias) => normalized.includes(alias))) return { status: 'match', reason: 'expected_title_alias' };\n" |
| 33 | +if late not in text: |
| 34 | + raise RuntimeError('late forbidden alias gate missing') |
| 35 | +text = text.replace(late, " if (normalized && expected.some((alias) => normalized.includes(alias))) return { status: 'match', reason: 'expected_title_alias' };\n", 1) |
| 36 | +path.write_text(text, encoding='utf-8') |
| 37 | +print('strict content promotion patch v4 applied') |
0 commit comments