예제 #1
0
 public function parse()
 {
     $matches = array();
     $res = preg_match($this->options['_requireStrictFileFormat'] ? self::PATTERN_STRICT : self::PATTERN_LOOSE, $this->fileContent, $matches);
     if ($res === false || $res === 0) {
         throw new \Exception($this->filename . ' is not a proper .srt file.');
     }
     $this->setLineEnding($matches[1]);
     $bom = pack('CCC', 0xef, 0xbb, 0xbf);
     $matches = explode($this->lineEnding . $this->lineEnding, trim($matches[0], $bom . $this->lineEnding));
     $subtitleOrder = 1;
     $subtitleTime = '';
     foreach ($matches as $match) {
         $subtitle = explode($this->lineEnding, $match, 3);
         $timeline = explode(' --> ', $subtitle[1]);
         $subtitleTimeStart = $timeline[0];
         $subtitleTimeEnd = $timeline[1];
         if (!$this->options['_requireStrictFileFormat']) {
             $subtitleTimeStart = $this->cleanUpTimecode($subtitleTimeStart);
             $subtitleTimeEnd = $this->cleanUpTimecode($subtitleTimeEnd);
         }
         if ($subtitle[0] != $subtitleOrder++ || !$this->validateTimelines($subtitleTimeStart, $subtitleTimeEnd, !$this->options['_requireStrictFileFormat']) || $this->options['_requireStrictFileFormat'] && !$this->validateTimelines($subtitleTime, $subtitleTimeStart, true)) {
             throw new \Exception($this->filename . " failed timeline validation. ({$subtitleTimeStart} --> {$subtitleTimeEnd})");
         }
         $subtitleTime = $subtitleTimeEnd;
         $cue = new SubripCue($timeline[0], $timeline[1], $subtitle[2]);
         $cue->setLineEnding($this->lineEnding);
         $this->addCue($cue);
     }
     return $this;
 }
예제 #2
0
 public function parse()
 {
     $matches = array();
     if ($this->softmode) {
         $res = preg_match(self::PATTERN_SOFTMODE, trim($this->fileContent), $matches);
     } else {
         $res = preg_match(self::PATTERN, $this->fileContent, $matches);
     }
     if ($res === false || $res === 0) {
         throw new \Exception($this->filename . ' is not a proper .srt file.');
     }
     $this->setLineEnding($matches[1]);
     $bom = pack('CCC', 0xef, 0xbb, 0xbf);
     $matches = explode($this->lineEnding . $this->lineEnding, trim($matches[0], $bom . $this->lineEnding));
     $subtitleOrder = 1;
     $subtitleTime = '';
     foreach ($matches as $match) {
         $subtitle = explode($this->lineEnding, $match, 3);
         $timeline = explode(' --> ', $subtitle[1]);
         $subtitleTimeStart = $timeline[0];
         $subtitleTimeEnd = $timeline[1];
         if (!$this->softmode && ($subtitle[0] != $subtitleOrder++ || !$this->validateTimelines($subtitleTime, $subtitleTimeStart, true) || !$this->validateTimelines($subtitleTimeStart, $subtitleTimeEnd))) {
             throw new \Exception($this->filename . ' is not a proper .srt file.');
         }
         $subtitleTime = $subtitleTimeEnd;
         $cue = new SubripCue($timeline[0], $timeline[1], isset($subtitle[2]) ? $subtitle[2] : '');
         $cue->setLineEnding($this->lineEnding);
         $this->addCue($cue);
     }
     return $this;
 }
예제 #3
0
 public function parse()
 {
     $matches = array();
     $res = preg_match_all(self::PATTERN, $this->fileContent, $matches);
     if (!$res || $res == 0) {
         throw new \Exception($this->filename . ' is not a proper .srt file.');
     }
     $entries_count = count($matches[1]);
     for ($i = 0; $i < $entries_count; $i++) {
         $cue = new SubripCue($matches[1][$i], $matches[2][$i], $matches[3][$i]);
         $cue->setLineEnding($this->lineEnding);
         $this->addCue($cue);
     }
     return $this;
 }
예제 #4
0
 public function parse()
 {
     $matches = array();
     $res = preg_match(self::PATTERN, $this->fileContent, $matches);
     if ($res === false || $res === 0) {
         throw new \Exception($this->filename . ' is not a proper .srt file.');
     }
     $this->setLineEnding($matches[1]);
     $bom = pack('CCC', 0xef, 0xbb, 0xbf);
     $matches = explode($this->lineEnding . $this->lineEnding, trim($matches[0], $bom . $this->lineEnding));
     $subtitleOrder = 1;
     $subtitleTime = '';
     foreach ($matches as $match) {
         $subtitle = explode($this->lineEnding, $match, 3);
         $timeline = explode(' --> ', $subtitle[1]);
         $subtitleTimeStart = $timeline[0];
         $subtitleTimeEnd = $timeline[1];
         if ($subtitle[0] != $subtitleOrder++ || !$this->validateTimelines($subtitleTime, $subtitleTimeStart, true) || !$this->validateTimelines($subtitleTimeStart, $subtitleTimeEnd)) {
             switch (true) {
                 case $subtitle[0] != $subtitleOrder - 1:
                     $errorMsg = 'Invalid subtitle order index: ' . $subtitle[0];
                     break;
                 case !$this->validateTimelines($subtitleTime, $subtitleTimeStart, true):
                     $errorMsg = 'Staring time invalid: ' . $subtitleTimeStart;
                     break;
                 case !$this->validateTimelines($subtitleTimeStart, $subtitleTimeEnd):
                     $errorMsg = 'Ending time invalid: ' . $subtitleTimeEnd;
                     break;
             }
             throw new \Exception($this->filename . ' is not a proper .srt file. (' . $errorMsg . ')');
         }
         $subtitleTime = $subtitleTimeEnd;
         $cue = new SubripCue($timeline[0], $timeline[1], $subtitle[2]);
         $cue->setLineEnding($this->lineEnding);
         $this->addCue($cue);
     }
     return $this;
 }