diff --git a/CLAUDE.md b/CLAUDE.md index 2ede5a4..94d6d1a 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -126,7 +126,9 @@ The hook and title come from the detail pass, which only reads the transcript, so on a clip whose meaning is on the screen (a settings dialog, a spreadsheet) they summarise the video's topic instead of naming what is shown. After the render, if the `.layout.json` sidecar says at least -25% of the clip is `screencast` / `wide` / `inset`, three frames from those +25% of the clip is `screencast` / `wide` / `inset` (plus `general` when the +layout picker called the video a screencast: a face-less scene there is a +slide or a dialog, not a group shot), three frames from those stretches at 1024px plus the clip's own words go to Gemini (`GroundedHook`) and `viral_hook_text` / `video_title_for_youtube_short` are rewritten in place before `auto_hook_clip` burns them; the originals diff --git a/hook_grounding.py b/hook_grounding.py index 1151b95..cb70785 100644 --- a/hook_grounding.py +++ b/hook_grounding.py @@ -35,11 +35,27 @@ def enabled() -> bool: return os.environ.get("HOOK_GROUNDING", "1").strip() != "0" -def screen_ranges(ranges): +def screen_video() -> bool: + """True when the layout picker (or the user) called this source a + screencast. On such a video a GENERAL stretch, which the scene classifier + emits for "no face in frame", is a full-screen slide, dialog or terminal + (verified on a product update video: every GENERAL scene was a stats + card), even when the width gate did not upgrade it to SCREENCAST.""" + try: + import screencast_layout + return bool(getattr(screencast_layout, "ENABLED", False)) + except Exception: + return False + + +def screen_ranges(ranges, on_screen_video=None): """(start, end) pairs, clip seconds, of the stretches rendered on-screen.""" import layout_ranges + layouts = set(SCREEN_LAYOUTS) + if screen_video() if on_screen_video is None else on_screen_video: + layouts.add("general") return [(r["start"], r["end"]) for r in layout_ranges.normalise(ranges) - if r["layout"] in SCREEN_LAYOUTS] + if r["layout"] in layouts] def wanted(ranges, clip_duration) -> bool: diff --git a/tests/test_hook_grounding.py b/tests/test_hook_grounding.py index 8cb0ee7..dfd28f1 100644 --- a/tests/test_hook_grounding.py +++ b/tests/test_hook_grounding.py @@ -19,13 +19,25 @@ MIXED = [{"start": 0, "end": 5, "layout": "track"}, # --- when to run ----------------------------------------------------------- -def test_screen_layouts_trigger_and_face_layouts_do_not(): +def test_screen_layouts_trigger_and_face_layouts_do_not(monkeypatch): + monkeypatch.setattr(hg, "screen_video", lambda: False) assert hg.wanted(SCREEN, 30) is True assert hg.wanted(MIXED, 30) is True assert hg.wanted(FACE, 30) is False assert hg.wanted([], 30) is False +def test_general_counts_as_screen_only_on_a_screencast_video(monkeypatch): + # The reported case: picker said screencast, the render emitted + # track/general only (stats cards have no face), grounding never ran. + general = [{"start": 0, "end": 8, "layout": "track"}, + {"start": 8, "end": 30, "layout": "general"}] + monkeypatch.setattr(hg, "screen_video", lambda: True) + assert hg.wanted(general, 30) is True + monkeypatch.setattr(hg, "screen_video", lambda: False) + assert hg.wanted(general, 30) is False # a group shot is not a screen + + def test_a_blip_is_not_enough(monkeypatch): blip = [{"start": 0, "end": 2, "layout": "screencast"}, {"start": 2, "end": 30, "layout": "track"}]