private function get_chapters_object() { global $wpdb; // Get all posible assets with a chapter file format $chapter_assets = Model\EpisodeAsset::find_all_by_sql("SELECT ea.*, ft.mime_type\n\t\t\t FROM {$wpdb->prefix}podlove_episodeasset AS ea\n\t\t\t INNER JOIN {$wpdb->prefix}podlove_filetype AS ft ON ft.id = ea.file_type_id\n\t\t\t WHERE ft.type = 'chapters'\n\t\t\t ORDER BY position ASC"); // Get IDs $chapter_assets_id_to_mimetype = array(); foreach ($chapter_assets as $chapter_asset) { $chapter_assets_id_to_mimetype[$chapter_asset->id] = $chapter_asset->mime_type; } // Try to find attached chapter file to this episode $chapter_assets_ids = implode(',', array_keys($chapter_assets_id_to_mimetype)); $chapters_file = Model\MediaFile::find_one_by_where(sprintf("episode_id = %d\n\t\t\t AND episode_asset_id IN (%s)\n\t\t\t ORDER BY FIELD(episode_asset_id, %s)", $this->episode->id, $chapter_assets_ids, $chapter_assets_ids)); // Fallback to manual entry if no file was attached if (null === $chapters_file) { return Parser\Mp4chaps::parse($this->episode->chapters); } // Get mimetype for attached chapter file $mime_type = $chapter_assets_id_to_mimetype[$chapters_file->episode_asset_id]; // Get chapters object for mine type switch ($mime_type) { case 'application/xml': $contents = $this->get_raw_chapters_string($chapters_file); $chapters = Parser\PSC::parse($contents); break; case 'application/json': $contents = $this->get_raw_chapters_string($chapters_file); $chapters = Parser\JSON::parse($contents); break; case 'text/plain': $contents = $this->get_raw_chapters_string($chapters_file); switch ($contents[0]) { case '[': case '{': $chapters = Parser\JSON::parse($contents); break; case '<': $chapters = Parser\PSC::parse($contents); break; default: $chapters = Parser\Mp4chaps::parse($contents); break; } break; default: $chapters = ''; } // Apply filter return apply_filters('podlove_get_chapters_object', '' === $chapters || null === $chapters ? new Chapters() : $chapters, $mime_type, $chapters_file, $this); }
private function get_chapters_object() { if (!$this->chapters_raw) { $this->chapters_raw = $this->get_raw_chapters_string(); } if (!$this->chapters_raw) { return NULL; } $asset_assignment = Model\AssetAssignment::get_instance(); if ($asset_assignment->chapters == 'manual') { return Parser\Mp4chaps::parse($this->chapters_raw); } if (!($chapters_asset = Model\EpisodeAsset::find_one_by_id($asset_assignment->chapters))) { return NULL; } $mime_type = $chapters_asset->file_type()->mime_type; $chapters = false; switch ($mime_type) { case 'application/xml': $chapters = Parser\PSC::parse($this->chapters_raw); break; case 'application/json': $chapters = Parser\JSON::parse($this->chapters_raw); break; case 'text/plain': switch ($this->chapters_raw[0]) { case '[': case '{': $chapters = Parser\JSON::parse($this->chapters_raw); break; case '<': $chapters = Parser\PSC::parse($this->chapters_raw); break; default: $chapters = Parser\Mp4chaps::parse($this->chapters_raw); break; } break; } return $chapters; }
public function testChapterStartingWithUmlaut() { $result = Mp4chaps::parse("00:00:00.000 Intro\n00:00:19.000 Übermensch"); $this->assertEquals("Übermensch", $result[1]->get_title()); }