refactor: persist stream selection in .stream_state instead of config.toml

This commit is contained in:
Honney OC committed 2026-09-14 02:09:02 +00:00
1 parent 8e3db0d7f4
commit 30015d5cad
3 files changed
+34 -32

No files matched your search

+14 -3
View File
@@ -660,7 +660,6 @@ def main():
args = ap.parse_args()
cfg = load_config(args.config)
ext = cfg.get("extract", {})
sync_cfg = cfg.get("sync", {})
audio_cfg = cfg.get("audio", {})
@@ -669,6 +668,17 @@ def main():
out_dir = args.out or sync_cfg.get("out_dir", "output")
lag_sec = args.lag
# Load stream selection from .stream_state (created by extract.py)
_state_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), ".stream_state")
_state = {}
if os.path.exists(_state_path):
try:
import json
with open(_state_path, "r") as _sf:
_state = json.load(_sf)
except Exception:
pass
if args.mode == "full":
synced = args.synced
if not synced:
@@ -691,11 +701,12 @@ def main():
# Determine which streams to extract from synced MKV
# A's streams are first, B's delayed streams follow
ext = cfg.get("extract", {})
video_a = ext.get("file_a", "")
a_streams_in = probe_audio_streams(video_a) if os.path.exists(video_a) else []
n_a = len(a_streams_in)
sel_a = ext.get("audio_stream_a", 0) or 0
sel_b = ext.get("audio_stream_b", 0) or 0
sel_a = _state.get("audio_stream_a", 0) or 0
sel_b = _state.get("audio_stream_b", 0) or 0
sel_a = int(sel_a)
sel_b = int(sel_b)
# Output indices: A's selected stream stays at sel_a, B's becomes n_a + sel_b