コード例 #1
0
ファイル: PSC.php プロジェクト: podlove/podlove-timeline
 public static function parse($chapters_string)
 {
     // remove UTF8 BOM if it exists
     $chapters_string = str_replace("", "", $chapters_string);
     if (!is_string($chapters_string)) {
         return NULL;
     }
     if (!($chapters_string = trim($chapters_string))) {
         return NULL;
     }
     if (!($xml = self::get_simplexml($chapters_string))) {
         return NULL;
     }
     $xml->registerXPathNamespace('psc', 'http://podlove.org/simple-chapters');
     if (!($chapters_xpath = $xml->xpath("//psc:chapter"))) {
         return NULL;
     }
     $chapters = new Chapters();
     foreach ($chapters_xpath as $chapter) {
         $simplexml_attributes = (array) $chapter->attributes();
         $attributes = $simplexml_attributes['@attributes'];
         $chapters->addChapter(new Chapter(NormalPlayTime\Parser::parse($attributes['start']), isset($attributes['title']) ? $attributes['title'] : '', isset($attributes['href']) ? $attributes['href'] : '', isset($attributes['image']) ? $attributes['image'] : ''));
     }
     return $chapters;
 }
コード例 #2
0
 public function testMsStringParser()
 {
     $examples = array(" 1" => 100, "12" => 120, "123" => 123, "1234" => 123);
     foreach ($examples as $ms_string => $expected_ms) {
         $this->assertEquals($expected_ms, Parser::parse_ms_string($ms_string));
     }
 }
コード例 #3
0
ファイル: Mp4chaps.php プロジェクト: podlove/podlove-timeline
 public static function parse($chapters_string)
 {
     // remove UTF8 BOM if it exists
     $chapters_string = str_replace("", "", $chapters_string);
     $chapters_string = trim($chapters_string);
     if (!strlen($chapters_string)) {
         return NULL;
     }
     $chapters = new Chapters();
     $invalid_lines = 0;
     foreach (preg_split("/((\r?\n)|(\r\n?))/", $chapters_string) as $line) {
         $valid = preg_match('/^([\\d.:]+)(.*)$/', trim($line), $matches);
         if (!$valid) {
             $invalid_lines++;
             continue;
         }
         $time_string = $matches[1];
         $title = $matches[2];
         $timestamp_milliseconds = NormalPlayTime\Parser::parse($time_string);
         if ($timestamp_milliseconds === false) {
             continue;
         }
         $link = '';
         $title = preg_replace_callback('/\\s?<[^>]+>\\s?/', function ($matches) use(&$link) {
             $link = trim($matches[0], ' < >');
             return ' ';
         }, $title);
         $chapters->addChapter(new Chapter($timestamp_milliseconds, trim($title), $link));
     }
     return $invalid_lines <= count($chapters) ? $chapters : NULL;
 }
コード例 #4
0
 /**
  * Extract time segments from duration string.
  *
  * - verifies validity
  * - extracts hours, minutes, seconds, milliseconds
  */
 private function normalize()
 {
     if ($milliseconds = \Podlove\NormalPlayTime\Parser::parse($this->duration, 'ms')) {
         $this->hours = floor($milliseconds / 1000 / 60 / 60);
         $this->minutes = floor($milliseconds / 1000 / 60) % 60;
         $this->seconds = floor($milliseconds / 1000) % 60;
         $this->milliseconds = $milliseconds % 1000;
     } else {
         $this->valid = false;
     }
 }
コード例 #5
0
ファイル: JSON.php プロジェクト: podlove/podlove-timeline
 public static function parse($chapters_string)
 {
     // remove UTF8 BOM if it exists
     $chapters_string = str_replace("", "", $chapters_string);
     $chapters = new Chapters();
     $json = json_decode(trim($chapters_string));
     if (!$json) {
         return $chapters;
     }
     foreach ($json as $chapter) {
         $chapters->addChapter(new Chapter(NormalPlayTime\Parser::parse($chapter->start), $chapter->title, $chapter->href, $chapter->image));
     }
     return $chapters;
 }
コード例 #6
0
 /**
  * The total duration in milliseconds
  *
  * 0,1,2,…
  * 
  * @accessor
  */
 public function totalMilliseconds()
 {
     return \Podlove\NormalPlayTime\Parser::parse($this->duration, 'ms');
 }
コード例 #7
0
 public static function duration_to_seconds($timestring)
 {
     return \Podlove\NormalPlayTime\Parser::parse($timestring, 's');
 }