forked from alxp/islandora
-
Notifications
You must be signed in to change notification settings - Fork 118
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
Videojs #743
Open
Natkeeran
wants to merge
3
commits into
Islandora:2.x
Choose a base branch
from
digitalutsc:videojs
base: 2.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Videojs #743
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
name: 'Islandora Videojs' | ||
description: 'Islandora Videojs overrides' | ||
type: module | ||
package: Islandora | ||
core: 8.x | ||
dependencies: | ||
- islandora |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
<?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'; | ||
} | ||
|
||
|
||
/** | ||
* videojs theme override | ||
*/ | ||
function islandora_videojs_theme($existing, $type, $theme, $path) { | ||
$transcript_urls = get_transcript_urls(); | ||
return array( | ||
'videojs' => array( | ||
'variables' => array('items' => NULL, 'player_attributes' => NULL, 'mimes' => NULL, 'transcript_urls' => $transcript_urls), | ||
'base hook' => 'videojs' | ||
), | ||
); | ||
} | ||
|
||
/** | ||
* returns the urls of the transcript of a repository item | ||
*/ | ||
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; | ||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{# | ||
/** | ||
* @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 </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 }}" type="{{ mimes[ loop.index - 1 ] }}"/> | ||
{% endfor %} | ||
|
||
{% for transcript_url in transcript_urls %} | ||
<track srclang="en" label="English" kind="captions" src="{{ transcript_url }}" default /> | ||
{% endfor %} | ||
|
||
</video> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can avoid the Guzzle work by using IslandoraUtils. After you lookup the Term ID, e.g.
$transcript_term = getTermForUri('http://pcdm.org/use#Transcript');
, take your$node
from the routeMatch and use getMediaWithTerm to find your Transcript Media, e.g.$media = getMediaWithTerm($node, $transcript);
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Between
IslandoraUtils
and theMediaSourceService
you can replace huge chunks of this.