Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_caption_length(self):
captions = SCCReader().read(SAMPLE_SCC.decode(u'utf-8'))
self.assertEquals(7, len(captions.get_captions(u"en-US")))
def test_proper_timestamps(self):
captions = SCCReader().read(SAMPLE_SCC.decode(u'utf-8'))
paragraph = captions.get_captions(u"en-US")[2]
delta_start = abs(paragraph.start - 17000000)
delta_end = abs(paragraph.end - 18752000)
self.assertTrue(delta_start < TOLERANCE_MICROSECONDS)
self.assertTrue(delta_end < TOLERANCE_MICROSECONDS)
def test_eoc_on_newline_rejection(self):
with self.assertRaises(ValueError):
caption_set = SCCReader().read(SAMPLE_SCC_FLASHING_CAPTIONS)
def _test_srt_to_scc_to_srt_conversion(self, srt_captions):
captions_1 = SRTReader().read(srt_captions)
scc_results = SCCWriter().write(captions_1)
scc_captions = SCCReader().read(scc_results)
srt_results = SRTWriter().write(scc_captions)
captions_2 = SRTReader().read(srt_results)
self.assertCaptionSetAlmostEquals(captions_1, captions_2,
TOLERANCE_MICROSECONDS)
def test_dfxp_is_valid_xml_when_scc_source_has_weird_italic_commands(self):
caption_set = SCCReader().read(
SAMPLE_SCC_CREATED_DFXP_WITH_WRONGLY_CLOSING_SPANS)
dfxp = DFXPWriter().write(caption_set)
self.assertEqual(dfxp, SAMPLE_DFXP_WITH_PROPERLY_CLOSING_SPANS_OUTPUT)
def test_webvtt_newlines_are_properly_rendered(self):
caption_set = SCCReader().read(
SCC_THAT_GENERATES_WEBVTT_WITH_PROPER_NEWLINES)
webvtt = WebVTTWriter().write(caption_set)
self.assertEqual(
webvtt,
SAMPLE_WEBVTT_FROM_SCC_PROPERLY_WRITES_NEWLINES_OUTPUT
)
def test_empty_file(self):
self.assertRaises(
CaptionReadNoCaptions,
SCCReader().read, SAMPLE_SCC_EMPTY.decode(u'utf-8'))
def test_scc_to_dfxp(self):
caption_set = SCCReader().read(SAMPLE_SCC_MULTIPLE_POSITIONING)
dfxp = DFXPWriter(
relativize=False, fit_to_screen=False).write(caption_set)
self.assertEqual(SAMPLE_DFXP_FROM_SCC_OUTPUT, dfxp)
def v3(self, episode):
## Get transcription data
transcript_filename = '12022017 NBPY SCC.scc'
transcript_pathname = os.path.join( self.show_dir,
"assets", "transcripts", transcript_filename )
caps = open(transcript_pathname, encoding='iso-8859-1').read()
transcript = pycaption.SCCReader().read( caps )
language = transcript.get_languages()[0] # ['en-US']
captions = transcript.get_captions( language )
## Get markes for this video
cls = Cut_List.objects.filter(
episode=episode, apply=True).order_by('sequence')
transcriptions = get_transcriptions(cls)
for transcription in transcriptions:
pprint(transcription)
state = 0
for c in captions:
if c.format_start() == \
transcription['start']['timestamp']:
def v4(self, episode):
epoch = datetime.datetime(2017, 12, 2, 10, 6, 36, 841067)
# 2017-12-02 10:06:36.841067
## Get transcription data
transcript_filename = '12022017 NBPY SCC.scc'
transcript_pathname = os.path.join( self.show_dir,
"assets", "transcripts", transcript_filename )
caps = open(transcript_pathname, encoding='iso-8859-1').read()
transcript = pycaption.SCCReader().read( caps )
language = transcript.get_languages()[0] # ['en-US']
captions = transcript.get_captions( language )
cls = Cut_List.objects.filter(
episode=episode, apply=True).order_by('sequence')
# transcriptions = get_transcriptions(cls)
for cl in cls:
print( cl.get_start_wall() )
cl_start = ( cl.get_start_wall() - epoch
).total_seconds() * 1000000
cl_end = ( cl.get_end_wall() - epoch
).total_seconds() * 1000000
state = 0
for c in captions: