jenkins-bot has submitted this change and it was merged.
Change subject: Allow for potentially multiple types of subtitles
......................................................................
Allow for potentially multiple types of subtitles
I've been using VTT in combination with VideoJS, and decided to make
the handling a bit more format agnostic.
Change-Id: I61964a2e06c5e8677cc8e4778ba85e6efa46bc95
---
M TimedTextPage.php
M handlers/TextHandler/TextHandler.php
2 files changed, 24 insertions(+), 13 deletions(-)
Approvals:
Brion VIBBER: Looks good to me, approved
jenkins-bot: Verified
diff --git a/TimedTextPage.php b/TimedTextPage.php
index a65f7a6..95cc01b 100644
--- a/TimedTextPage.php
+++ b/TimedTextPage.php
@@ -10,6 +10,7 @@
class TimedTextPage extends Article {
// The width of the video plane:
static private $videoWidth = 400;
+ static private $knownTimedTextExtensions = array( 'srt', 'vtt' );
public function view() {
$request = $this->getContext()->getRequest();
@@ -32,7 +33,7 @@
public function renderOutput( $out ){
// parse page title:
$titleParts = explode( '.', $this->getTitle()->getDBkey() );
- $srt = array_pop( $titleParts );
+ $timedTextExtension = array_pop( $titleParts );
$languageKey = array_pop( $titleParts );
$oldid = $this->getOldID();
@@ -53,7 +54,7 @@
$fileTitle = Title::newFromText( $this->getTitle()->getDBkey(),
NS_FILE );
$file = wfFindFile( $fileTitle );
// Check for a valid srt page, present redirect form for the
full title match:
- if( $srt !== '.srt' && $file && $file->exists() ){
+ if( !in_array( $timedTextExtension,
self::$knownTimedTextExtensions ) && $file && $file->exists() ){
if( $file->isLocal() ){
$this->doRedirectToPageForm( $fileTitle );
} else {
@@ -101,7 +102,7 @@
xml::tags( 'td', array( 'valign' =>
'top', 'width' => self::$videoWidth ),
$this->getVideoHTML(
$videoTitle )
) .
- xml::tags( 'td', array( 'valign' =>
'top' ) , $this->getSrtHTML( $languageName ) )
+ xml::tags( 'td', array( 'valign' =>
'top' ) , $this->getTimedTextHTML( $languageName ) )
)
)
);
@@ -143,8 +144,9 @@
)
)
);
+ $timedTextExtension = '.srt';
$timedTextTile = Title::newFromText(
$this->getTitle()->getDBkey() . '.'.
- 'LANG' . '.srt', NS_TIMEDTEXT )->getFullText();
+ 'LANG' . $timedTextExtension, NS_TIMEDTEXT
)->getFullText();
$out->addScript(
Html::InlineScript(
'$(function() {' .
@@ -181,13 +183,12 @@
}
/**
- * Gets the srt text
+ * Gets an HTML representation of the Timed Text
*
- * XXX We should add srt parsing and links to seek to that time in the
video
* @param $languageName string
* @return Message|string
*/
- private function getSrtHTML( $languageName ){
+ private function getTimedTextHTML( $languageName ){
if( !$this->exists() ){
return wfMessage( 'timedmedia-subtitle-no-subtitles',
$languageName );
}
diff --git a/handlers/TextHandler/TextHandler.php
b/handlers/TextHandler/TextHandler.php
index b937b76..3c229d5 100644
--- a/handlers/TextHandler/TextHandler.php
+++ b/handlers/TextHandler/TextHandler.php
@@ -245,8 +245,9 @@
$subTitle = Title::newFromText( $page['title']
) ;
$tileParts = explode( '.', $page['title'] );
if( count( $tileParts) >= 3 ){
- /*$subtitle_extension = */ array_pop(
$tileParts );
+ $timedTextExtension = array_pop(
$tileParts );
$languageKey = array_pop( $tileParts );
+ $contentType = $this->getContentType(
$timedTextExtension );
} else {
continue;
}
@@ -259,10 +260,10 @@
'kind' => 'subtitles',
'data-mwtitle' => $namespacePrefix .
$subTitle->getDBkey(),
'data-mwprovider' => $providerName,
- 'type' => 'text/x-srt',
+ 'type' => $contentType,
// @todo Should eventually add special
entry point and output proper WebVTT format:
//
http://www.whatwg.org/specs/web-apps/current-work/webvtt.html
- 'src' => $this->getFullURL(
$page['title'] ),
+ 'src' => $this->getFullURL(
$page['title'], $contentType ),
'srclang' => $languageKey,
'data-dir' => Language::factory(
$languageKey )->getDir(),
'label' =>
wfMessage('timedmedia-subtitle-language',
@@ -274,19 +275,28 @@
return $textTracks;
}
- function getFullURL( $pageTitle ){
+ function getContentType( $timedTextExtension ) {
+ if ( $timedTextExtension === 'srt' ) {
+ return 'text/x-srt';
+ } else if ( $timedTextExtension === 'vtt' ) {
+ return 'text/vtt';
+ }
+ return '';
+ }
+
+ function getFullURL( $pageTitle, $contentType ){
if( $this->file->isLocal() ) {
$subTitle = Title::newFromText( $pageTitle ) ;
return $subTitle->getFullURL( array(
'action' => 'raw',
- 'ctype' => 'text/x-srt'
+ 'ctype' => $contentType
));
//} elseif( $this->file->repo instanceof ForeignDBViaLBRepo ){
} else {
$query = 'title=' . wfUrlencode( $pageTitle ) . '&';
$query .= wfArrayToCgi( array(
'action' => 'raw',
- 'ctype' => 'text/x-srt'
+ 'ctype' => $contentType
) );
// Note: This will return false if scriptDirUrl is not
set for repo.
return $this->file->repo->makeUrl( $query );
--
To view, visit https://gerrit.wikimedia.org/r/231857
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I61964a2e06c5e8677cc8e4778ba85e6efa46bc95
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/TimedMediaHandler
Gerrit-Branch: master
Gerrit-Owner: TheDJ <[email protected]>
Gerrit-Reviewer: Brion VIBBER <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits