diff --git a/classes/local/paella_transform.php b/classes/local/paella_transform.php index 49dd86e..d756bf9 100644 --- a/classes/local/paella_transform.php +++ b/classes/local/paella_transform.php @@ -255,10 +255,40 @@ private static function get_captions($publication) { foreach ($publication->media as $media) { list($type1, $type2) = explode('/', $media->flavor, 2); if ($type1 === 'captions') { - list($format, $lang) = explode('+', $type2, 2); + $lang = 'undefined'; + $format = 'vtt'; // Default standard format. + $text = 'unknown'; + // Prior to Opencast 15 or manually added subtitles in block opencast. + if (strpos($type2, 'vtt+') !== false) { + list($format, $lang) = explode('+', $type2, 2); + $text = $lang; + } else if (in_array($type2, ['delivery', 'prepared', 'preview', 'vtt']) && !empty($media->tags)) { // Opencast 15 coverage. + $tagdataarr = []; + foreach ($media->tags as $tag) { + // The safety checker. + if (!is_string($tag)) { + continue; + } + if (strpos($tag, 'lang:') === 0) { + $lang = substr($tag, strlen('lang:')); + $tagdataarr['lang'] = $lang; + } + if (strpos($tag, 'generator-type:') === 0) { + $tagdataarr['generatortype'] = substr($tag, strlen('generator-type:')); + } + if (strpos($tag, 'generator:') === 0) { + $tagdataarr['generator'] = substr($tag, strlen('generator:')); + } + if (strpos($tag, 'type:') === 0) { + $tagdataarr['type'] = substr($tag, strlen('type:')); + } + } + $text = self::prepare_caption_text($tagdataarr); + list($mimefiletype, $format) = explode('/', $media->mediatype, 2); + } $captions[] = [ 'lang' => $lang, - 'text' => $lang, + 'text' => $text, 'format' => $format, 'url' => $media->url, ]; @@ -267,6 +297,33 @@ private static function get_captions($publication) { return $captions; } + /** + * Generates the caption text in case the caption info is included in the tags (as introduced in Opencast 15) + * @param array $tagdataarr array of caption data. + * @return string the complied text for the caption. + */ + private static function prepare_caption_text($tagdataarr) { + $titlearr = []; + if (array_key_exists('lang', $tagdataarr)) { + $titlearr[] = $tagdataarr['lang']; + } + if (array_key_exists('generator', $tagdataarr)) { + $generator = ucfirst($tagdataarr['generator']); + $titlearr[] = $generator; + } + if (array_key_exists('generatortype', $tagdataarr)) { + $generatortype = $tagdataarr['generatortype'] === 'auto' ? + get_string('captions_generator_type_auto', 'mod_opencast') : + get_string('captions_generator_type_manual', 'mod_opencast'); + $titlearr[] = "($generatortype)"; + } + if (array_key_exists('type', $tagdataarr)) { + $type = ucfirst($tagdataarr['type']); + $titlearr[] = "($type)"; + } + return implode(' ', $titlearr); + } + /** * Returns the video data from Opencast in the format for the paella player. * @param int $ocinstanceid Opencast instance id diff --git a/lang/en/opencast.php b/lang/en/opencast.php index d560f16..7c67c2a 100644 --- a/lang/en/opencast.php +++ b/lang/en/opencast.php @@ -28,6 +28,9 @@ $string['allvideos'] = 'All videos'; $string['allowdownload'] = 'Allow students to download the video(s)'; +$string['captions_generator_type_auto'] = 'Auto generated'; +$string['captions_generator_type_manual'] = 'Manually generated'; + $string['date'] = 'Date'; $string['downloadvideo'] = 'Download video'; $string['duration'] = 'Duration';