Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New subtitle support #49

Merged
merged 5 commits into from
Dec 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 59 additions & 2 deletions classes/local/paella_transform.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
];
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions lang/en/opencast.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Loading