From 8057987d739bbbc6a3c0333c03015ffc592f9a8a Mon Sep 17 00:00:00 2001 From: Natkeeran <natkeeran@gmail.com> Date: Fri, 1 Nov 2019 14:49:53 -0400 Subject: [PATCH 1/3] videojs --- .../islandora_videojs.info.yml | 7 +++ .../islandora_videojs.module | 56 +++++++++++++++++++ .../templates/videojs.html.twig | 23 ++++++++ 3 files changed, 86 insertions(+) create mode 100644 modules/islandora_videojs/islandora_videojs.info.yml create mode 100644 modules/islandora_videojs/islandora_videojs.module create mode 100644 modules/islandora_videojs/templates/videojs.html.twig diff --git a/modules/islandora_videojs/islandora_videojs.info.yml b/modules/islandora_videojs/islandora_videojs.info.yml new file mode 100644 index 00000000..f5f41547 --- /dev/null +++ b/modules/islandora_videojs/islandora_videojs.info.yml @@ -0,0 +1,7 @@ +name: 'Islandora Videojs' +description: 'Islandora Videojs overrides' +type: module +package: Islandora +core: 8.x +dependencies: + - islandora diff --git a/modules/islandora_videojs/islandora_videojs.module b/modules/islandora_videojs/islandora_videojs.module new file mode 100644 index 00000000..6e6a40d7 --- /dev/null +++ b/modules/islandora_videojs/islandora_videojs.module @@ -0,0 +1,56 @@ +<?php + +/** + * @file + * Contains islandora_videojs.module. + * + * This file is part of the Islandora Project. + * + * (c) Islandora Foundation + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Drupal\Core\Routing\RouteMatchInterface; + +/** + * Implements hook_help(). + */ +function islandora_videojs_help($route_name, RouteMatchInterface $route_match) { + switch ($route_name) { + // Main module help for the islandora module. + case 'help.page.islandora_videojs': + $output = ''; + $output .= '<h3>' . t('About') . '</h3>'; + $output .= '<p>' . t('Islandora Videojs overrides.') . '</p>'; + $output .= '<p>' . t('Customizes videojs.') . '</p>'; + return $output; + + default: + } +} + + +function islandora_videojs_theme_registry_alter(&$theme_registry) { + $module_path = drupal_get_path('module', 'islandora_videojs'); + + // Use the templates in my module's template folder. + $theme_registry['videojs'] = $theme_registry['videojs']; + $theme_registry['videojs']['path'] = $module_path . '/templates'; + $theme_registry['videojs']['template'] = 'videojs'; +} + + +function islandora_videojs_theme($existing, $type, $theme, $path) { + return array( + 'videojs' => array( + 'variables' => array('items' => NULL, 'player_attributes' => NULL, 'testvar' => 'testvalue'), + 'base hook' => 'videojs' + ), + ); +} + + + + diff --git a/modules/islandora_videojs/templates/videojs.html.twig b/modules/islandora_videojs/templates/videojs.html.twig new file mode 100644 index 00000000..0c9b0375 --- /dev/null +++ b/modules/islandora_videojs/templates/videojs.html.twig @@ -0,0 +1,23 @@ +{# +/** + * @file + * Default theme implementation to display a formatted video field. + * + * Available variables: + * - items: A collection of videos. + * - player_attributes: Player options including the following: + * - width: The width of the video (if known). + * - height: The height of the video (if known). + * - autoplay: Autoplay on or off + * + * @ingroup themeable + */ +#} +<h3>Videojs Test {{ testvar }} </h3> +<video data-setup="{}" class="video-js vjs-default-skin" preload="{{ player_attributes.preload }}" {{ player_attributes.controls ? 'controls' : '' }} style="width:{{ player_attributes.width }}px;height:{{ player_attributes.height }}px;" {{ player_attributes.autoplay ? 'autoplay' : '' }} {{ player_attributes.loop ? 'loop' : '' }} {{ player_attributes.muted ? 'muted' : '' }}> + {% for user in items %} + <source src="{{ user }}"/> + {% endfor %} +<track srclang="en" label="English" kind="captions" src="http://localhost:8000/_flysystem/fedora/2019-02/MEDIATRACK_en.vtt" default /> + +</video> From c34d0601dae5fe0699efb5bdfd9ff049e7e7da91 Mon Sep 17 00:00:00 2001 From: Natkeeran <natkeeran@gmail.com> Date: Mon, 4 Nov 2019 16:50:48 -0500 Subject: [PATCH 2/3] support vtts --- .../islandora_videojs.module | 50 ++++++++++++++++++- .../templates/videojs.html.twig | 9 ++-- 2 files changed, 54 insertions(+), 5 deletions(-) diff --git a/modules/islandora_videojs/islandora_videojs.module b/modules/islandora_videojs/islandora_videojs.module index 6e6a40d7..10736c75 100644 --- a/modules/islandora_videojs/islandora_videojs.module +++ b/modules/islandora_videojs/islandora_videojs.module @@ -31,7 +31,6 @@ function islandora_videojs_help($route_name, RouteMatchInterface $route_match) { } } - function islandora_videojs_theme_registry_alter(&$theme_registry) { $module_path = drupal_get_path('module', 'islandora_videojs'); @@ -43,14 +42,61 @@ function islandora_videojs_theme_registry_alter(&$theme_registry) { function islandora_videojs_theme($existing, $type, $theme, $path) { + $transcript_urls = get_transcript_urls(); return array( 'videojs' => array( - 'variables' => array('items' => NULL, 'player_attributes' => NULL, 'testvar' => 'testvalue'), + 'variables' => array('items' => NULL, 'player_attributes' => NULL, 'mimes' => NULL, 'transcript_urls' => $transcript_urls), 'base hook' => 'videojs' ), ); } +function get_transcript_urls() { + // Get the nid + $node = \Drupal::routeMatch()->getParameter('node'); + $nid = NULL; + if ($node instanceof \Drupal\node\NodeInterface) { + $nid = $node->id(); + } + + $transcript_urls = array(); + + if ($nid != NULL) { + // media url + global $base_url; + $media_url = $base_url. '/node/' . $nid . '/media'; + + try { + $media_client = new \GuzzleHttp\Client(); + $media_response = $media_client->request('GET', $media_url, [ + 'http_errors' => false, + 'auth' => ['admin', 'islandora'], + 'query' => ['_format' => 'json'] + ]); + $code = $media_response->getStatusCode(); + + if ($code = 200) { + + // Loop through media to find the transcripts + $media_list = (string) $media_response->getBody(); + $media_list = json_decode($media_list, true); + foreach ($media_list as $media) { + if ($media['field_media_use'][0]['url'] == "/taxonomy/term/20") { + $file_url = $media['field_media_file'][0]['url']; + $transcript_urls[] = $file_url; + } + } + } + } + catch (\Exception $e) { + \Drupal::logger('islandora_videojs')->notice("Error in getting transcripts: " . $e->getMessage()); + } + + } + + return $transcript_urls; +} + diff --git a/modules/islandora_videojs/templates/videojs.html.twig b/modules/islandora_videojs/templates/videojs.html.twig index 0c9b0375..57abbbda 100644 --- a/modules/islandora_videojs/templates/videojs.html.twig +++ b/modules/islandora_videojs/templates/videojs.html.twig @@ -13,11 +13,14 @@ * @ingroup themeable */ #} -<h3>Videojs Test {{ testvar }} </h3> +<h3>Videojs Test </h3> <video data-setup="{}" class="video-js vjs-default-skin" preload="{{ player_attributes.preload }}" {{ player_attributes.controls ? 'controls' : '' }} style="width:{{ player_attributes.width }}px;height:{{ player_attributes.height }}px;" {{ player_attributes.autoplay ? 'autoplay' : '' }} {{ player_attributes.loop ? 'loop' : '' }} {{ player_attributes.muted ? 'muted' : '' }}> {% for user in items %} - <source src="{{ user }}"/> + <source src="{{ user }}" type="{{ mimes[ loop.index - 1 ] }}"/> + {% endfor %} + + {% for transcript_url in transcript_urls %} + <track srclang="en" label="English" kind="captions" src="{{ transcript_url }}" default /> {% endfor %} -<track srclang="en" label="English" kind="captions" src="http://localhost:8000/_flysystem/fedora/2019-02/MEDIATRACK_en.vtt" default /> </video> From ddc18ff6b28fba465310e93fe999efc9484b77da Mon Sep 17 00:00:00 2001 From: Natkeeran <natkeeran@gmail.com> Date: Wed, 6 Nov 2019 11:55:53 -0500 Subject: [PATCH 3/3] add some comments --- modules/islandora_videojs/islandora_videojs.module | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/modules/islandora_videojs/islandora_videojs.module b/modules/islandora_videojs/islandora_videojs.module index 10736c75..6bacaf22 100644 --- a/modules/islandora_videojs/islandora_videojs.module +++ b/modules/islandora_videojs/islandora_videojs.module @@ -41,6 +41,9 @@ function islandora_videojs_theme_registry_alter(&$theme_registry) { } +/** +* videojs theme override +*/ function islandora_videojs_theme($existing, $type, $theme, $path) { $transcript_urls = get_transcript_urls(); return array( @@ -51,7 +54,9 @@ function islandora_videojs_theme($existing, $type, $theme, $path) { ); } - +/** +* returns the urls of the transcript of a repository item +*/ function get_transcript_urls() { // Get the nid $node = \Drupal::routeMatch()->getParameter('node');