def make_subtitle_lines(count, is_synced=True): lines = [] for line_num in xrange(0, count): lines.append( SubtitleLine(line_num * 1000 if is_synced else None, line_num * 1000 + 900 if is_synced else None, "%s" % line_num, {})) return lines
def test_no_space_left(self): self.original_video.duration = 10 self.original_video.save() subs = [SubtitleLine( 2 * 1000, 10 * 1000, 'text', {}, )] subs = add_credit(self.version, self._subs_to_sset(subs)) self.assertEquals(len(subs), 1) last_sub = subs[-1] self.assertEquals(last_sub.text, 'text')
def test_only_a_second_left(self): subs = [SubtitleLine( 2 * 1000, 9 * 1000, 'text', {}, )] subs = add_credit(self.version, self._subs_to_sset(subs)) last_sub = subs[-1] self.assertEquals(last_sub.text, "Subtitles by the Amara.org community") self.assertEquals(last_sub.start_time, 9000) self.assertEquals(last_sub.end_time, 10 * 1000)
def test_straight_up_video(self): subs = [SubtitleLine( 2 * 1000, 3 * 1000, 'text', {}, )] subs = add_credit(self.version, self._subs_to_sset(subs)) last_sub = subs[-1] self.assertEquals(last_sub.text, "Subtitles by the Amara.org community") self.assertEquals(last_sub.start_time, 7000) self.assertEquals(last_sub.end_time, 10 * 1000)
def test_last_sub_not_synced(self): subs = [SubtitleLine( 2 * 1000, None, 'text', {}, )] last_sub = subs[-1] self.assertEquals(last_sub.end_time, None) subs = add_credit(self.version, self._subs_to_sset(subs)) self.assertEquals(last_sub.text, subs[-1].text)
def _sub_list_to_sv(self, subs): sublines = [] for sub in subs: sublines.append( SubtitleLine( sub['start'], sub['end'], sub['text'], {}, )) user = User.objects.all()[0] new_sv = pipeline.add_subtitles( self.original_video, self.language.language_code, sublines, author=user, ) return new_sv
def test_add_subtitles(self): def _get_tip_subs(): sl = SubtitleLanguage.objects.get(video=self.video, language_code='en') return list(sl.get_tip(full=True).get_subtitles().subtitle_items()) def _add(subs): pipeline.add_subtitles(self.video, 'en', subs) # Passing nil. _add(None) self.assertEqual(_get_tip_subs(), []) # Passing a list of tuples. _add([(100, 200, "foo", { 'new_paragraph': True }), (300, None, "bar", { 'new_paragraph': False })]) self.assertEqual(_get_tip_subs(), [ SubtitleLine(100, 200, "foo", {'new_paragraph': True}), SubtitleLine(300, None, "bar", {'new_paragraph': False}), ]) # Passing an iterable of tuples. iterable = (s for s in [(101, 200, "foo", { 'new_paragraph': True }), (300, None, "bar", { 'new_paragraph': False })]) # FIXME: this is failing because the genertator is getting exhausted along the pipeline # debug and pass the iterable directly _add(tuple(iterable)) self.assertEqual(_get_tip_subs(), [ SubtitleLine(101, 200, "foo", {'new_paragraph': True}), SubtitleLine(300, None, "bar", {'new_paragraph': False}) ]) # Passing a SubtitleSet. subs = SubtitleSet.from_list('en', [ SubtitleLine(110, 210, "foo", {'new_paragraph': True}), SubtitleLine(310, 410, "bar", {'new_paragraph': False}), SubtitleLine(None, None, '"baz"', {'new_paragraph': False}) ]) _add(subs) self.assertEqual(_get_tip_subs(), [(110, 210, "foo", { 'new_paragraph': True }), (310, 410, "bar", { 'new_paragraph': False }), (None, None, '"baz"', { 'new_paragraph': False })]) # Passing a hunk of XML. subs = SubtitleSet.from_list("en", [ SubtitleLine(10000, 22000, "boots", {}), SubtitleLine(23000, 29000, "cats", {}) ]) _add(subs.to_xml()) self.assertEqual(_get_tip_subs(), [ SubtitleLine(10000, 22000, "boots", {'new_paragraph': True}), SubtitleLine(23000, 29000, "cats", {'new_paragraph': False}) ]) # Passing nonsense should TypeError out. self.assertRaises(TypeError, lambda: _add(1)) # Make sure all the versions are there. sl = SubtitleLanguage.objects.get(video=self.video, language_code='en') self.assertEqual(sl.subtitleversion_set.full().count(), 5)
def empty_line(self): return SubtitleLine(None, None, None, None)