def test_sami_to_sami_conversion(self, sample_sami): caption_set = SAMIReader().read(sample_sami) results = SAMIWriter(relativize=False, fit_to_screen=False).write(caption_set) assert isinstance(results, str) self.assert_sami_equals(sample_sami, results)
def test_is_relativized(self): # Absolute positioning settings (e.g. px) are converted to percentages caption_set = SAMIReader().read(SAMPLE_SAMI_PARTIAL_MARGINS) result = SAMIWriter( video_width=VIDEO_WIDTH, video_height=VIDEO_HEIGHT ).write(caption_set) self.assertSAMIEquals(result, SAMPLE_SAMI_PARTIAL_MARGINS_RELATIVIZED)
def test_sami_to_sami_conversion(self, sample_sami_with_lang, sample_sami_no_lang): caption_set = SAMIReader().read(sample_sami_no_lang) results = SAMIWriter().write(caption_set) assert isinstance(results, str) self.assert_sami_equals(sample_sami_with_lang, results) assert "lang: und;" in results
def test_is_relativized(self, sample_sami_partial_margins_relativized, sample_sami_partial_margins): # Absolute positioning settings (e.g. px) are converted to percentages caption_set = SAMIReader().read(sample_sami_partial_margins) result = SAMIWriter(video_width=VIDEO_WIDTH, video_height=VIDEO_HEIGHT).write(caption_set) self.assert_sami_equals(result, sample_sami_partial_margins_relativized)
def test_dfxp_to_sami_with_margins(self): caption_set = DFXPReader().read(SAMPLE_DFXP_FROM_SAMI_WITH_MARGINS) results = SAMIWriter(video_width=VIDEO_WIDTH, video_height=VIDEO_HEIGHT).write(caption_set) margins = [ u"margin-right: 6.04%;", u"margin-bottom: 0%;", u"margin-top: 0%;", u"margin-left: 6.04%;" ] for margin in margins: self.assertIn(margin, results)
def test_dfxp_to_sami_with_margins( self, sample_dfxp_from_sami_with_margins): caption_set = DFXPReader().read(sample_dfxp_from_sami_with_margins) results = SAMIWriter(video_width=VIDEO_WIDTH, video_height=VIDEO_HEIGHT).write(caption_set) margins = ["margin-right: 6.04%;", "margin-bottom: 0%;", "margin-top: 0%;", "margin-left: 6.04%;"] for margin in margins: assert margin in results
def srt2sami(srt_file_path: str, sami_file_path: Optional[str] = None) -> None: """Convert SubRip subtitles to SAMI subtitles. Arguments: srt_file_path {string} -- The path to the SubRip file. sami_file_path {string} -- The path to the SAMI file. """ file: Union[TextIO, BinaryIO] converter = CaptionConverter() encoding = Utils.detect_encoding(srt_file_path) with open(srt_file_path, "r", encoding=encoding) as file: converter.read(file.read(), SRTReader()) if sami_file_path is None: sami_file_path = srt_file_path.replace(".srt", ".smi") with open(sami_file_path, "wb") as file: file.write(converter.write(SAMIWriter()).encode(encoding))
def test_dfxp_to_sami_conversion(self): caption_set = DFXPReader().read(SAMPLE_DFXP) results = SAMIWriter().write(caption_set) self.assertTrue(isinstance(results, unicode)) self.assertSAMIEquals(SAMPLE_SAMI, results)
def test_srt_to_sami_conversion(self): caption_set = SRTReader().read(SAMPLE_SRT) results = SAMIWriter().write(caption_set) self.assertTrue(isinstance(results, six.text_type)) self.assertSAMIEquals(SAMPLE_SAMI, results)
def test_dfxp_empty_cue_to_sami(self, sample_sami_empty_cue_output, sample_dfxp_empty_cue): caption_set = DFXPReader().read(sample_dfxp_empty_cue) results = SAMIWriter().write(caption_set) self.assert_sami_equals(sample_sami_empty_cue_output, results)
from pycaption import SRTReader, SAMIWriter import os dir = './srt' srtnames = [n for n in os.listdir(dir) if n[-4:] == '.srt'] for name in srtnames: puretxt = open(os.path.join(dir, name), 'r', encoding = 'utf-8').read() content = SRTReader().read(puretxt) smitext = SAMIWriter().write(content) print(smitext)
def test_sami_to_sami_conversion(self): caption_set = SAMIReader().read(SAMPLE_SAMI_NO_LANG) results = SAMIWriter().write(caption_set) self.assertTrue(isinstance(results, unicode)) self.assertSAMIEquals(SAMPLE_SAMI_WITH_LANG, results) self.assertTrue(u"lang: en-US;" in results)
def test_sami_to_sami_conversion(self): captions = SAMIReader().read(self.sample_sami) results = SAMIWriter().write(captions) self.assertTrue(isinstance(results, unicode)) self.assertSAMIEquals(self.sample_sami_with_lang, results) self.assertTrue(u"lang: en-US;" in results)
def test_webvtt_to_sami_conversion(self): caption_set = WebVTTReader().read(SAMPLE_WEBVTT) results = SAMIWriter().write(caption_set) self.assertTrue(isinstance(results, str)) self.assertSAMIEquals(SAMPLE_SAMI, results)
def test_dfxp_to_sami_conversion(self): results = SAMIWriter().write(self.captions) self.assertTrue(isinstance(results, unicode)) self.assertSAMIEquals(SAMPLE_SAMI.decode(u'utf-8'), results)
def test_webvtt_to_sami_conversion(self): results = SAMIWriter().write(self.captions) self.assertTrue(isinstance(results, unicode)) self.assertSAMIEquals(SAMPLE_SAMI_UNICODE, results)
def test_dfxp_to_sami_conversion(self, sample_sami, sample_dfxp): caption_set = DFXPReader().read(sample_dfxp) results = SAMIWriter().write(caption_set) assert isinstance(results, str) self.assert_sami_equals(sample_sami, results)
def test_sami_to_sami_conversion(self): caption_set = SAMIReader().read(SAMPLE_SAMI) results = SAMIWriter(relativize=False, fit_to_screen=False).write(caption_set) self.assertTrue(isinstance(results, unicode)) self.assertSAMIEquals(SAMPLE_SAMI, results)
def test_webvtt_to_sami_conversion(self, sample_sami, sample_webvtt): caption_set = WebVTTReader().read(sample_webvtt) results = SAMIWriter().write(caption_set) assert isinstance(results, str) self.assert_sami_equals(sample_sami, results)