From 614da5eef580316a3a2c3003c6918d4d74d26a44 Mon Sep 17 00:00:00 2001 From: Brandon Weigel Date: Mon, 13 Sep 2021 22:07:34 +0000 Subject: [PATCH 1/5] Add subtitle/transcript capability --- README.md | 5 ++++- includes/admin.form.inc | 7 ++++++- islandora_videojs.install | 1 + islandora_videojs.module | 9 +++++++++ theme/islandora-videojs.tpl.php | 3 +++ 5 files changed, 23 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a264938..056813a 100644 --- a/README.md +++ b/README.md @@ -26,11 +26,14 @@ For example, at **Administration » Islandora » Solution pack configuration » ![Solution Pack Configuration](https://user-images.githubusercontent.com/2738244/40234143-b0c31ea6-5a73-11e8-9e3b-8133917d496c.png) Configure Video.js at **Administration » Islandora » Islandora Viewers » Video.js** (_admin/islandora/islandora_viewers/videojs_). -Three options are available: +Four options are available: * "Videojs-contrib-hls library" to enable HTTP Live Streaming (a streaming format native to mobile phones). * "Center play button" to put the play button in the center of the player, rather than the top left corner. * "Responsive player" to make the Video.js player responsive but requires you use a responsive theme. +* "Transcript/Subtitle DSID" sets the datastream ID containing a WebVTT transcript. + +To use transcripts, on the object in question, add a custom datastream using the configured DSID (default TRANSCRIPT) and upload a WebVTT file. ![Configuration](https://user-images.githubusercontent.com/1943338/32968854-2575fc40-cbb9-11e7-9e85-66fec561a24c.png) diff --git a/includes/admin.form.inc b/includes/admin.form.inc index 84d8ce0..8bbb720 100644 --- a/includes/admin.form.inc +++ b/includes/admin.form.inc @@ -29,7 +29,12 @@ function islandora_videojs_admin($form, &$form_state) { '#description' => t('Make the videojs player responsive (requires a responsive theme)'), '#default_value' => variable_get('islandora_videojs_responsive', FALSE), ); - + $form['islandora_videojs_transcript_dsid'] = array( + '#type' => 'textfield', + '#title' => t('Transcript/Subtitle DSID'), + '#description' => t('Datastream ID used for transcript/subtitle datastreams.'), + '#default_value' => 'TRANSCRIPT', + ); return system_settings_form($form); } diff --git a/islandora_videojs.install b/islandora_videojs.install index 9642268..2edfc8e 100644 --- a/islandora_videojs.install +++ b/islandora_videojs.install @@ -12,6 +12,7 @@ function islandora_videojs_uninstall() { 'islandora_videojs_hls_library', 'islandora_videojs_center_play_button', 'islandora_videojs_responsive', + 'islandora_videojs_transcript_dsid', ); array_walk($variables, 'variable_del'); } diff --git a/islandora_videojs.module b/islandora_videojs.module index 7f912ec..fc12adc 100644 --- a/islandora_videojs.module +++ b/islandora_videojs.module @@ -75,6 +75,15 @@ function template_preprocess_islandora_videojs(array &$variables) { if (variable_get('islandora_videojs_responsive', TRUE)) { drupal_add_css(drupal_get_path('module', 'islandora_videojs') . '/css/videojs_responsive.css', array('group' => CSS_DEFAULT, 'every_page' => FALSE)); } + $object = islandora_object_load($variables['params']['pid']); + $variables['transcript'] = FALSE; + $transcript_dsid = variable_get('islandora_videojs_transcript_dsid', 'TRANSCRIPT'); + if ($object[$transcript_dsid]) { + $variables['transcript'] = TRUE; + $variables['transcript_path'] = "/islandora/object/{$object->id}/datastream/" . $transcript_dsid . "/view"; + preg_match('/Language: (.*)/', $object[$transcript_dsid]->content, $matches); + $variables['transcript_language'] = (!empty($matches) ? $matches[1] : "English"); + } } /** diff --git a/theme/islandora-videojs.tpl.php b/theme/islandora-videojs.tpl.php index ab78a6d..490a41a 100644 --- a/theme/islandora-videojs.tpl.php +++ b/theme/islandora-videojs.tpl.php @@ -15,6 +15,9 @@ '> + + +
From 36b679142d871f0535c5557b191d4a98f3a13bab Mon Sep 17 00:00:00 2001 From: Brandon Weigel Date: Tue, 21 Sep 2021 22:01:09 +0000 Subject: [PATCH 2/5] Adam's suggestion to improve the URL creation --- islandora_videojs.module | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/islandora_videojs.module b/islandora_videojs.module index fc12adc..becb355 100644 --- a/islandora_videojs.module +++ b/islandora_videojs.module @@ -80,7 +80,7 @@ function template_preprocess_islandora_videojs(array &$variables) { $transcript_dsid = variable_get('islandora_videojs_transcript_dsid', 'TRANSCRIPT'); if ($object[$transcript_dsid]) { $variables['transcript'] = TRUE; - $variables['transcript_path'] = "/islandora/object/{$object->id}/datastream/" . $transcript_dsid . "/view"; + $variables['transcript_path'] = url("islandora/object/{$object->id}/datastream/{$transcript_dsid}/view"); preg_match('/Language: (.*)/', $object[$transcript_dsid]->content, $matches); $variables['transcript_language'] = (!empty($matches) ? $matches[1] : "English"); } From e0122a72ec11bb4648eeb18730c55be6aa68a35c Mon Sep 17 00:00:00 2001 From: Brandon Weigel Date: Wed, 22 Sep 2021 16:25:23 +0000 Subject: [PATCH 3/5] Fix dsid config saving --- includes/admin.form.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/admin.form.inc b/includes/admin.form.inc index 8bbb720..4b799e7 100644 --- a/includes/admin.form.inc +++ b/includes/admin.form.inc @@ -33,7 +33,7 @@ function islandora_videojs_admin($form, &$form_state) { '#type' => 'textfield', '#title' => t('Transcript/Subtitle DSID'), '#description' => t('Datastream ID used for transcript/subtitle datastreams.'), - '#default_value' => 'TRANSCRIPT', + '#default_value' => variable_get('islandora_videojs_transcript_dsid', 'TRANSCRIPT'), ); return system_settings_form($form); } From b951cd5a0fa6d15fd6d4bf7923b0ed9f1056d3e4 Mon Sep 17 00:00:00 2001 From: Brandon Weigel Date: Wed, 22 Sep 2021 17:11:16 +0000 Subject: [PATCH 4/5] Secure languages variable --- islandora_videojs.module | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/islandora_videojs.module b/islandora_videojs.module index becb355..679bb7b 100644 --- a/islandora_videojs.module +++ b/islandora_videojs.module @@ -82,7 +82,7 @@ function template_preprocess_islandora_videojs(array &$variables) { $variables['transcript'] = TRUE; $variables['transcript_path'] = url("islandora/object/{$object->id}/datastream/{$transcript_dsid}/view"); preg_match('/Language: (.*)/', $object[$transcript_dsid]->content, $matches); - $variables['transcript_language'] = (!empty($matches) ? $matches[1] : "English"); + $variables['transcript_language'] = (!empty($matches) ? check_plain($matches[1]) : "English"); } } From aa3b872d2123837a8b50fea61b88f1a4320284f5 Mon Sep 17 00:00:00 2001 From: Brandon Weigel Date: Thu, 23 Sep 2021 17:04:45 +0000 Subject: [PATCH 5/5] Check DSID restriction on transcript DS --- islandora_videojs.module | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/islandora_videojs.module b/islandora_videojs.module index 679bb7b..55bd1ce 100644 --- a/islandora_videojs.module +++ b/islandora_videojs.module @@ -78,7 +78,7 @@ function template_preprocess_islandora_videojs(array &$variables) { $object = islandora_object_load($variables['params']['pid']); $variables['transcript'] = FALSE; $transcript_dsid = variable_get('islandora_videojs_transcript_dsid', 'TRANSCRIPT'); - if ($object[$transcript_dsid]) { + if ($object[$transcript_dsid] && islandora_datastream_access(ISLANDORA_VIEW_OBJECTS, $object[$transcript_dsid])) { $variables['transcript'] = TRUE; $variables['transcript_path'] = url("islandora/object/{$object->id}/datastream/{$transcript_dsid}/view"); preg_match('/Language: (.*)/', $object[$transcript_dsid]->content, $matches);