From 6ecc3be6d21ab3e2ba5550550682f3687bcc381b Mon Sep 17 00:00:00 2001 From: ferishili Date: Mon, 25 Mar 2024 16:06:08 +0100 Subject: [PATCH 1/4] fix for new subtitles, fixes #48 --- classes/local/paella_transform.php | 59 +++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 2 deletions(-) diff --git a/classes/local/paella_transform.php b/classes/local/paella_transform.php index 49dd86e..00e5c82 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', '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:') !== false) { + $lang = str_replace('lang:', '', $tag); + $tagdataarr['lang'] = $lang; + } + if (strpos($tag, 'generator-type:') !== false) { + $tagdataarr['generatortype'] = str_replace('generator-type:', '', $tag); + } + if (strpos($tag, 'generator:') !== false) { + $tagdataarr['generator'] = str_replace('generator:', '', $tag); + } + if (strpos($tag, 'type:') !== false) { + $tagdataarr['type'] = str_replace('type:', '', $tag); + } + } + $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,31 @@ 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('generator_type', $tagdataarr)) { + $generator_type = $tagdataarr['generator_type'] == 'auto' ? 'A' : 'M'; + $titlearr[] = "($generator_type)"; + } + 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 From 5474f2eba51f0e3c8d4717d1327dc6b564be62be Mon Sep 17 00:00:00 2001 From: ferishili Date: Tue, 26 Mar 2024 12:24:48 +0100 Subject: [PATCH 2/4] coding style correction --- classes/local/paella_transform.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/classes/local/paella_transform.php b/classes/local/paella_transform.php index 00e5c82..9c5b3fd 100644 --- a/classes/local/paella_transform.php +++ b/classes/local/paella_transform.php @@ -311,9 +311,9 @@ private static function prepare_caption_text($tagdataarr) { $generator = ucfirst($tagdataarr['generator']); $titlearr[] = $generator; } - if (array_key_exists('generator_type', $tagdataarr)) { - $generator_type = $tagdataarr['generator_type'] == 'auto' ? 'A' : 'M'; - $titlearr[] = "($generator_type)"; + if (array_key_exists('generatortype', $tagdataarr)) { + $generatortype = $tagdataarr['generatortype'] == 'auto' ? 'A' : 'M'; + $titlearr[] = "($generatortype)"; } if (array_key_exists('type', $tagdataarr)) { $type = ucfirst($tagdataarr['type']); From 33b6ebc37d2ec646025d97c21ad23c3985be34ca Mon Sep 17 00:00:00 2001 From: ferishili Date: Thu, 27 Jun 2024 14:24:59 +0200 Subject: [PATCH 3/4] according to suggestions --- classes/local/paella_transform.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/local/paella_transform.php b/classes/local/paella_transform.php index 9c5b3fd..ba9a85e 100644 --- a/classes/local/paella_transform.php +++ b/classes/local/paella_transform.php @@ -312,7 +312,7 @@ private static function prepare_caption_text($tagdataarr) { $titlearr[] = $generator; } if (array_key_exists('generatortype', $tagdataarr)) { - $generatortype = $tagdataarr['generatortype'] == 'auto' ? 'A' : 'M'; + $generatortype = $tagdataarr['generatortype'] === 'auto' ? 'A' : 'M'; $titlearr[] = "($generatortype)"; } if (array_key_exists('type', $tagdataarr)) { From c97548711a2e7282d4f48fe584447ba8a6f53945 Mon Sep 17 00:00:00 2001 From: ferishili Date: Wed, 17 Jul 2024 13:58:51 +0200 Subject: [PATCH 4/4] change according to request, minor improvements --- classes/local/paella_transform.php | 24 +++++++++++++----------- lang/en/opencast.php | 3 +++ 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/classes/local/paella_transform.php b/classes/local/paella_transform.php index ba9a85e..d756bf9 100644 --- a/classes/local/paella_transform.php +++ b/classes/local/paella_transform.php @@ -262,25 +262,25 @@ private static function get_captions($publication) { if (strpos($type2, 'vtt+') !== false) { list($format, $lang) = explode('+', $type2, 2); $text = $lang; - } else if (in_array($type2, ['delivery', 'prepared', 'vtt']) && !empty($media->tags)) { // Opencast 15 coverage. + } 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:') !== false) { - $lang = str_replace('lang:', '', $tag); + if (strpos($tag, 'lang:') === 0) { + $lang = substr($tag, strlen('lang:')); $tagdataarr['lang'] = $lang; } - if (strpos($tag, 'generator-type:') !== false) { - $tagdataarr['generatortype'] = str_replace('generator-type:', '', $tag); + if (strpos($tag, 'generator-type:') === 0) { + $tagdataarr['generatortype'] = substr($tag, strlen('generator-type:')); } - if (strpos($tag, 'generator:') !== false) { - $tagdataarr['generator'] = str_replace('generator:', '', $tag); + if (strpos($tag, 'generator:') === 0) { + $tagdataarr['generator'] = substr($tag, strlen('generator:')); } - if (strpos($tag, 'type:') !== false) { - $tagdataarr['type'] = str_replace('type:', '', $tag); + if (strpos($tag, 'type:') === 0) { + $tagdataarr['type'] = substr($tag, strlen('type:')); } } $text = self::prepare_caption_text($tagdataarr); @@ -312,14 +312,16 @@ private static function prepare_caption_text($tagdataarr) { $titlearr[] = $generator; } if (array_key_exists('generatortype', $tagdataarr)) { - $generatortype = $tagdataarr['generatortype'] === 'auto' ? 'A' : 'M'; + $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); + return implode(' ', $titlearr); } /** 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';