protected function _simple_captions_set() { $match = new Set(); $match->renderer(new SrtRenderer()); $caption = new Caption(); $caption->text('Text One')->start(0)->end(30.105); $match->add_caption($caption); $caption = new Caption(); $caption->text('Text Two')->start(30)->end(60.05); $match->add_caption($caption); return $match; }
public function test_shift_srt() { $match = new Set(); $match->renderer(new SrtRenderer()); $caption = new Caption(); $caption->text('Text One')->start(1.123)->end(31.228); $match->add_caption($caption); $caption = new Caption(); $caption->text('Text Two')->start(31.123)->end(61.173); $match->add_caption($caption); $captions = $this->_simple_captions_set(); $captions->fast_forward(1.123); $this->assertSame($captions->render(), $match->render()); }
public function parse() { $split_regex = "/(\\d)+[\r|\n][\r\n]?(\\d{2}:\\d{2}:\\d{2},\\d{3}) --> (\\d{2}:\\d{2}:\\d{2},\\d{3})[\r\n]{1,2}/"; $pieces = preg_split($split_regex, $this->_captions_string, -1, PREG_SPLIT_DELIM_CAPTURE); if (count($pieces) < 4) { throw new Exception("Parse Error: Split created no captions"); } $first = $pieces[0]; if (empty($pieces[0])) { array_shift($pieces); } $captions = new Set(); for ($i = 0, $j = count($pieces); $i < $j; $i += 4) { $caption = new Caption(); $caption->start(SrtHelper::string_to_time($pieces[$i + 1])); $caption->end(SrtHelper::string_to_time($pieces[$i + 2])); $caption->text(trim($pieces[$i + 3])); $captions->add_caption($caption); } $captions->renderer(new SrtRenderer()); return $captions; }