TheDJ has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/287406

Change subject: Add a timedtext param to videoinfo API
......................................................................

Add a timedtext param to videoinfo API

Similar to the derivatives endpoint, this option adds an array of
timed text based subtitles, captions, audio descriptions, chapters
etc, for a specific audio or video file.

This will eventually be the new endpoint for InstantCommons
situations, where clients currently interpret this information all on
their own, making it difficult to introduce changes.

The fields returned are src, type, kind, srclang, dir, provider, title
and label. Most of these are also provided as attributes or data
attributes on <track> elements.

Moved the spot where HTML element specific prefixes are added.

Bug: T122736
Change-Id: I4227b88ae94e3cfcfd62fb7fe221190d7fe33f71
---
M ApiQueryVideoInfo.php
M TimedMediaTransformOutput.php
M handlers/TextHandler/TextHandler.php
M i18n/en.json
M i18n/qqq.json
5 files changed, 33 insertions(+), 8 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/TimedMediaHandler 
refs/changes/06/287406/1

diff --git a/ApiQueryVideoInfo.php b/ApiQueryVideoInfo.php
index 974d2af..c44c914 100644
--- a/ApiQueryVideoInfo.php
+++ b/ApiQueryVideoInfo.php
@@ -32,12 +32,23 @@
                                $vals['derivatives'] = [];
                        }
                }
+               if ( isset( $prop['timedtext'] ) ) {
+                       if ( $file->getHandler() && $file->getHandler() 
instanceof TimedMediaHandler ) {
+                               $handler = new TextHandler( $file );
+                               $vals['timedtext'] = $handler->getTracks();
+                               $result->setIndexedTagName( $vals['timedtext'], 
"timedtext" );
+                       } else {
+                               // Non-TMH file, no timedtext.
+                               $vals['timedtext'] = [];
+                       }
+               }
                return $vals;
        }
 
        public static function getPropertyMessages( $filter = [] ) {
                $pm = parent::getPropertyMessages( $filter );
                $pm['derivatives'] = 
'apihelp-query+videoinfo-paramvalue-prop-derivatives';
+               $pm['timedtext'] = 
'apihelp-query+videoinfo-paramvalue-prop-timedtext';
                return array_diff_key( $pm, array_flip( $filter ) );
        }
 
@@ -46,7 +57,7 @@
         */
        protected function getExamplesMessages() {
                return [
-                       'action=query&titles=File:Folgers.ogv&prop=videoinfo'
+                       
'action=query&titles=File:Folgers.ogv&prop=videoinfo&viprop=derivatives'
                                => 'apihelp-query+videoinfo-example-1',
                ];
        }
diff --git a/TimedMediaTransformOutput.php b/TimedMediaTransformOutput.php
index 37d6658..0b0172e 100644
--- a/TimedMediaTransformOutput.php
+++ b/TimedMediaTransformOutput.php
@@ -327,6 +327,19 @@
                                }
                        }
                }
+               $mediaTracks = $this->getTextHandler()->getTracks();
+               foreach ( $mediaTracks as &$track ) {
+                       foreach ( $track as $attr => $val ) {
+                               if ( $attr === 'title' || $attr === 'provider' 
) {
+                                       $source[ 'data-mw' . $attr ] = $val;
+                                       unset( $source[ $attr ] );
+                               } else if ( $attr 'dir' ) {
+                                       $source[ 'data-' . $attr ] = $val;
+                                       unset( $source[ $attr ] );
+                               }
+                       }
+               }
+
 
                $width = $sizeOverride ? $sizeOverride[0] : 
$this->getPlayerWidth();
                if ( $this->fillwindow ) {
@@ -341,8 +354,7 @@
                        self::htmlTagSet( 'source', $mediaSources ) .
 
                        // Timed text:
-                       self::htmlTagSet( 'track',
-                               $this->file ? 
$this->getTextHandler()->getTracks() : null ) .
+                       self::htmlTagSet( 'track', $mediaTracks ) .
 
                        // Fallback text displayed for browsers without js and 
without video tag support:
                        /// XXX note we may want to replace this with an image 
and download link play button
diff --git a/handlers/TextHandler/TextHandler.php 
b/handlers/TextHandler/TextHandler.php
index ba61e14..c277310 100644
--- a/handlers/TextHandler/TextHandler.php
+++ b/handlers/TextHandler/TextHandler.php
@@ -263,15 +263,15 @@
                                }
                                $namespacePrefix = "TimedText:";
                                $textTracks[] = [
-                                       'kind' => 'subtitles',
-                                       'data-mwtitle' => $namespacePrefix . 
$subTitle->getDBkey(),
-                                       'data-mwprovider' => $providerName,
-                                       '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'], $contentType ),
+                                       'kind' => 'subtitles',
+                                       'type' => $contentType,
+                                       'title' => $namespacePrefix . 
$subTitle->getDBkey(),
+                                       'provider' => $providerName,
                                        'srclang' =>  $languageKey,
-                                       'data-dir' => Language::factory( 
$languageKey )->getDir(),
+                                       'dir' => Language::factory( 
$languageKey )->getDir(),
                                        'label' => wfMessage( 
'timedmedia-subtitle-language',
                                                $langNames[ $languageKey ],
                                                $languageKey )->text()
diff --git a/i18n/en.json b/i18n/en.json
index 70ec2bd..9d0e179 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -170,6 +170,7 @@
        "apihelp-query+videoinfo-description": "Extends imageinfo to include 
video source (derivatives) information",
        "apihelp-query+videoinfo-example-1": "Fetch information about 
[[:File:Folgers.ogv]]",
        "apihelp-query+videoinfo-paramvalue-prop-derivatives": "Adds an array 
of the different format and quality versions of an audio or video file that are 
available.",
+       "apihelp-query+videoinfo-paramvalue-prop-timedtext": "Adds an array of 
the subtitles, captions and descriptions of an audio or video file that are 
available.",
        "apihelp-transcodereset-description": "Users with the 'transcode-reset' 
right can reset and re-run a transcode job.",
        "apihelp-transcodereset-param-title": "The media file title.",
        "apihelp-transcodereset-param-transcodekey": "The transcode key you 
wish to reset. Fetch from 
[[Special:ApiHelp/query+transcodestatus|action=query&prop=transcodestatus]].",
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 01f7187..9f75f32 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -188,6 +188,7 @@
        "apihelp-query+videoinfo-description": 
"{{doc-apihelp-description|query+videoinfo}}",
        "apihelp-query+videoinfo-example-1": 
"{{doc-apihelp-example|query+videoinfo}}",
        "apihelp-query+videoinfo-paramvalue-prop-derivatives": 
"{{doc-apihelp-example|query+videoinfo}}",
+       "apihelp-query+videoinfo-paramvalue-prop-timedtext": 
"{{doc-apihelp-example|query+videoinfo}}",
        "apihelp-transcodereset-description": 
"{{doc-apihelp-description|transcodereset}}",
        "apihelp-transcodereset-param-title": 
"{{doc-apihelp-param|transcodereset|title}}",
        "apihelp-transcodereset-param-transcodekey": 
"{{doc-apihelp-param|transcodereset|transcodekey}}",

-- 
To view, visit https://gerrit.wikimedia.org/r/287406
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I4227b88ae94e3cfcfd62fb7fe221190d7fe33f71
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/TimedMediaHandler
Gerrit-Branch: master
Gerrit-Owner: TheDJ <hartman.w...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to