Files
Lee Hanken 9917320640 hpr-intro-stripper: layered intro/outro cut-point detection and trimming
Fetches HPR's own metadata, audio, and official transcripts live; falls
back to local speech recognition (tiny model, matching HPR's own
hpr-get-and-transcribe.bash tooling) only when needed, and to
correlation against vendored reference clips or sibling episodes
otherwise. License-aware, resumable, and never guesses -- flags
anything it isn't confident about for manual review rather than
producing a plausible-looking wrong cut.
2026-11-22 10:36:07 +00:00

37 lines
1.3 KiB
Python

import os
import unittest
from hpr_stripper import srt
REFERENCES_DIR = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "references")
class TestSrtParsing(unittest.TestCase):
def test_parses_vendored_outro_srt(self):
segments = srt.parse_file(os.path.join(REFERENCES_DIR, "outro.srt"))
self.assertEqual(len(segments), 5)
text0, start0, end0 = segments[0]
self.assertIn("Hacker Public Radio podcast", text0)
self.assertEqual(start0, 0.0)
self.assertAlmostEqual(end0, 5.56, places=2)
def test_parses_vendored_intro_srt_template(self):
segments = srt.parse_file(os.path.join(REFERENCES_DIR, "intro.srt"))
self.assertEqual(len(segments), 5)
self.assertEqual(segments[0][0], "REPLACE_LINE_1")
self.assertAlmostEqual(segments[-1][2], 27.32, places=2)
def test_handles_comma_or_dot_decimal_separator(self):
text = (
"1\n00:00:01,000 --> 00:00:02,500\nHello there\n\n"
"2\n00:00:02.500 --> 00:00:04.000\nSecond line\n"
)
segments = srt.parse(text)
self.assertEqual(len(segments), 2)
self.assertEqual(segments[0], ("Hello there", 1.0, 2.5))
self.assertEqual(segments[1], ("Second line", 2.5, 4.0))
if __name__ == "__main__":
unittest.main()