56 lines
1.7 KiB
Python
56 lines
1.7 KiB
Python
#!/usr/bin/env python3
|
|
import glob
|
|
import json
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
base = sys.argv[1]
|
|
|
|
def patch_ini() -> int:
|
|
removed = 0
|
|
for path in sorted(glob.glob(f"{base}/config/youtube.youtube2__*.ini")):
|
|
lines_out = []
|
|
for line in Path(path).read_text(encoding="utf-8-sig").splitlines():
|
|
key = line.split("=", 1)[0].strip().lower()
|
|
if key in {"video_mode", "bitrate"}:
|
|
removed += 1
|
|
continue
|
|
lines_out.append(line)
|
|
Path(path).write_text("\n".join(lines_out).rstrip() + "\n", encoding="utf-8")
|
|
return removed
|
|
|
|
|
|
def patch_profile() -> bool:
|
|
p = Path(f"{base}/config/hardware-profile.json")
|
|
if not p.is_file():
|
|
return False
|
|
data = json.loads(p.read_text(encoding="utf-8"))
|
|
if isinstance(data, dict) and "relay_strategy" in data:
|
|
data.pop("relay_strategy", None)
|
|
p.write_text(json.dumps(data, indent=2, ensure_ascii=False) + "\n", encoding="utf-8")
|
|
return True
|
|
return False
|
|
|
|
|
|
def patch_env() -> int:
|
|
p = Path(f"{base}/config/hardware.env")
|
|
if not p.is_file():
|
|
return 0
|
|
kept = []
|
|
removed = 0
|
|
for line in p.read_text(encoding="utf-8-sig").splitlines():
|
|
key = line.split("=", 1)[0].strip()
|
|
if key.startswith("LIVE_RELAY_"):
|
|
removed += 1
|
|
continue
|
|
kept.append(line)
|
|
p.write_text("\n".join(kept).rstrip() + "\n", encoding="utf-8")
|
|
return removed
|
|
|
|
|
|
text = Path(f"{base}/douyin_youtube_ffplay.py").read_text(encoding="utf-8", errors="ignore")
|
|
print("ini_removed", patch_ini())
|
|
print("relay_strategy_removed", patch_profile())
|
|
print("relay_env_removed", patch_env())
|
|
print("has_stream_copy_fn", "_resolve_stream_copy_plan" in text)
|