/** * Return all available metaData * @param MediaInformation $information * @return array */ public function getMetaData(MediaInformation $information) { $subdef = $information->getResource(); $record = $subdef->get_record(); $thumbnail = $record->get_thumbnail(); $request = $information->getResourceRequest(); $baseUrl = $request->getSchemeAndHttpHost() . $request->getBasePath(); $ogMetaData = []; $embedMedia = []; $oembedMetaData = []; $substitutionPath = sprintf('/assets/common/images/icons/substitution/%s.png', str_replace('/', '_', $record->getMimeType())); $resourceUrl = $information->getUrl(); $embedMedia['title'] = $record->get_title(); $embedMedia['url'] = $resourceUrl; switch ($record->getType()) { case 'video': $ogMetaData['og:type'] = 'video.other'; $ogMetaData['og:image'] = $baseUrl . $thumbnail->get_url(); $ogMetaData['og:image:width'] = $thumbnail->get_width(); $ogMetaData['og:image:height'] = $thumbnail->get_height(); $embedMedia['coverUrl'] = $baseUrl . $thumbnail->get_url(); $embedMedia['source'] = []; $embedMedia['source'][] = ['url' => $resourceUrl, 'type' => $subdef->get_mime()]; $embedMedia['dimensions'] = $this->getDimensions($subdef); $oembedMetaData['type'] = 'video'; $oembedMetaData['html'] = sprintf('<iframe width="%d" height="%d" src="%s" frameborder="0" allowfullscreen></iframe>', $embedMedia['dimensions']['width'], $embedMedia['dimensions']['height'], $this->getEmbedUrl($resourceUrl)); break; case 'flexpaper': case 'document': $ogMetaData['og:type'] = 'article'; $ogMetaData['og:image'] = $baseUrl . $thumbnail->get_url(); $ogMetaData['og:image:width'] = $thumbnail->get_width(); $ogMetaData['og:image:height'] = $thumbnail->get_height(); $oembedMetaData['type'] = 'link'; $embedMedia['dimensions'] = $this->getDimensions($subdef); break; case 'audio': $ogMetaData['og:type'] = 'music.song'; $ogMetaData['og:image'] = $baseUrl . $substitutionPath; $ogMetaData['og:image:width'] = $thumbnail->get_width(); $ogMetaData['og:image:height'] = $thumbnail->get_height(); $oembedMetaData['type'] = 'link'; $embedMedia['source'] = []; $embedMedia['source'][] = ['url' => $resourceUrl, 'type' => $subdef->get_mime()]; $embedMedia['coverUrl'] = $baseUrl . $substitutionPath; // set default dimension for player $embedMedia['dimensions'] = ['width' => 320, 'height' => 320, 'top' => 0]; break; default: $oembedMetaData['type'] = 'photo'; $ogMetaData['og:type'] = 'image'; $ogMetaData['og:image'] = (string) $record->get_preview()->get_permalink()->get_url(); $ogMetaData['og:image:width'] = $subdef->get_width(); $ogMetaData['og:image:height'] = $subdef->get_height(); $embedMedia['dimensions'] = $this->getDimensions($subdef); break; } return ['options' => ['autoplay' => false], 'oembedMetaData' => $oembedMetaData, 'ogMetaData' => $ogMetaData, 'embedMedia' => $embedMedia]; }
/** * list available video text tracks (only metadatas) * @param MediaInformation $media * @return array */ public function getAvailableVideoTextTracks(MediaInformation $media) { $record = $media->getResource()->get_record(); $videoTextTrack = []; if ($record->getType() === 'video') { $databox = $record->getDatabox(); $vttIds = []; $vttMetadata = []; // extract vtt ids and labels foreach ($databox->get_meta_structure() as $meta) { $foundParts = []; if (preg_match('/^VideoTextTrack(.*)$/iu', $meta->get_name(), $foundParts)) { $vttIds[] = $meta->get_id(); /* Available HTML5 track types: - captions - chapters - descriptions - metadata - subtitles */ $kind = ''; $setAsDefault = false; $vttFoundKind = strtolower($foundParts[1]); switch ($vttFoundKind) { case 'chapters': $setAsDefault = true; $kind = 'chapters'; break; default: $kind = 'subtitles'; } $vttMetadata[$meta->get_id()] = ['label' => empty($foundParts[1]) ? 'default' : $foundParts[1], 'srclang' => '', 'default' => $setAsDefault, 'kind' => $kind]; } } // extract vtt metadatas from ids foreach ($record->get_caption()->get_fields(null, true) as $field) { $metaStructId = $field->get_meta_struct_id(); if (!in_array($metaStructId, $vttIds)) { continue; } foreach ($field->get_values() as $value) { $videoTextTrack[] = array_merge(['src' => $this->getEmbedVttUrl($media->getUrl(), ['choice' => $metaStructId]), 'id' => $metaStructId], $vttMetadata[$metaStructId]); } } } return $videoTextTrack; }