from unshackle.core.tracks.subtitle import Subtitle def test_strip_webvtt_cue_classes(): text = ( "WEBVTT\n\n" "00:00:01.000 --> 00:00:04.000\n" "Mor, da vi blev gift,\n" "kom Ben og jeg til dig.\n" "Keep these and this\n" "class on styling\n" "voice jp \u6f22\u304b\u3093\n" "kara <00:00:01.500>timing <00:01.500>short\n" ) out = Subtitle.strip_webvtt_cue_classes(text) assert "bg_transparent" not in out and "" not in out and "" not in out assert "Mor, da vi blev gift," in out assert "Keep these and this" in out assert "class on styling" in out assert "voice jp \u6f22\u304b\u3093" in out assert "kara timing short" in out def test_decode_entities(tmp_path): from unshackle.core.tracks.subtitle_convert import decode_entities out = tmp_path / "a.srt" out.write_text( "1\n00:00:01,000 --> 00:00:04,000\nROBERT & RA'ED  x 'q'\nTom ¬ sure, AT&T\n", encoding="utf8", ) decode_entities(out) text = out.read_text(encoding="utf8") assert "ROBERT & RA'ED \xa0x 'q'" in text assert "Tom ¬ sure, AT&T" in text def test_filter_subs_converts_before_stripping(tmp_path, monkeypatch): """``sdh_method: filter-subs`` used to hand subtitle-filter a .vtt and raise OSError.""" from unshackle.core import binaries from unshackle.core.config import config monkeypatch.setattr(binaries, "SubtitleEdit", None) monkeypatch.setattr(config, "subtitle", {"sdh_method": "filter-subs"}, raising=False) path = tmp_path / "sub.vtt" path.write_text( "WEBVTT\n\n00:00:01.000 --> 00:00:03.000\n[MUSIC PLAYING]\n\n" "00:00:04.000 --> 00:00:06.000\nPlain dialogue stays.\n", encoding="utf8", ) sub = Subtitle(url="https://example.test/x", language="en", codec=Subtitle.Codec.WebVTT) sub.path = path sub.strip_hearing_impaired() assert sub.codec == Subtitle.Codec.SubRip text = sub.path.read_text(encoding="utf8") assert "MUSIC PLAYING" not in text assert "Plain dialogue stays." in text