TheDJ has uploaded a new change for review.

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

Change subject: Repair start/end times for videos.
......................................................................

Repair start/end times for videos.

We were using mediafragments, but in a h:m:s format instead of
hh:mm:ss. Our style is no longer working in modern browsers.
Milliseconds never worked either and should also be fixed. Updated the
testcases to take these into account.

Also re enable it for videojs, where it now also works.

Change-Id: I19fd74ff2a86ddcf9f620ac65ebcb715939d92e6
---
M TimedMediaHandler_body.php
M TimedMediaTransformOutput.php
M tests/phpunit/TestTimeParsing.php
3 files changed, 14 insertions(+), 10 deletions(-)


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

diff --git a/TimedMediaHandler_body.php b/TimedMediaHandler_body.php
index d513351..241be47 100644
--- a/TimedMediaHandler_body.php
+++ b/TimedMediaHandler_body.php
@@ -300,10 +300,11 @@
                }
                $hours = floor( $time / 3600 );
                $min = floor( ( $time / 60 ) % 60 );
-               $sec = ( $time % 60 );
-               $ms = ( $time - round( $time, 3 ) != 0 ) ? '.' .( $time - 
round( $time, 3 ) ) : '';
+               $sec = floor( $time % 60 );
+               $ms = round( $time, 3 ) * 1000 % 1000;
+               $ms = ( $ms != 0 ) ? '.' . $ms : '';
 
-               return "{$hours}:{$min}:{$sec}{$ms}";
+               return sprintf( '%02d:%02d:%02d%s', $hours, $min, $sec, $ms );
        }
 
        /**
diff --git a/TimedMediaTransformOutput.php b/TimedMediaTransformOutput.php
index 011aaa5..1ad9fbf 100644
--- a/TimedMediaTransformOutput.php
+++ b/TimedMediaTransformOutput.php
@@ -501,10 +501,8 @@
                        // At a minimum this should return the source video 
file.
                        $this->sources = WebVideoTranscode::getSources( 
$this->file );
                        // Check if we have "start or end" times and append the 
temporal url fragment hash
-                       if ( $wgTmhWebPlayer !== 'videojs' ) {
-                               foreach ( $this->sources as &$source ) {
-                                       $source['src'] .= 
$this->getTemporalUrlHash();
-                               }
+                       foreach ( $this->sources as &$source ) {
+                               $source['src'] .= $this->getTemporalUrlHash();
                        }
                }
                return $this->sources;
diff --git a/tests/phpunit/TestTimeParsing.php 
b/tests/phpunit/TestTimeParsing.php
index 4891a80..fc8c947 100644
--- a/tests/phpunit/TestTimeParsing.php
+++ b/tests/phpunit/TestTimeParsing.php
@@ -13,9 +13,10 @@
        */
        function testSeconds2NptFormat() {
                // Some time conversions:
-               $this->assertEquals( TimedMediaHandler::seconds2npt( 100 ), 
'0:1:40' );
-               $this->assertEquals( TimedMediaHandler::seconds2npt( 0 ), 
'0:0:0' );
-               $this->assertEquals( TimedMediaHandler::seconds2npt( 3601 ), 
'1:0:1' );
+               $this->assertEquals( TimedMediaHandler::seconds2npt( 100 ), 
'00:01:40' );
+               $this->assertEquals( TimedMediaHandler::seconds2npt( 0 ), 
'00:00:00' );
+               $this->assertEquals( TimedMediaHandler::seconds2npt( 3601 ), 
'01:00:01' );
+               $this->assertEquals( TimedMediaHandler::seconds2npt( 3601.5 ), 
'01:00:01.500' );
 
                // Test failures:
                $this->assertEquals( TimedMediaHandler::seconds2npt( 'foo' ), 
false );
@@ -28,7 +29,11 @@
        function testParseTimeString() {
                // Some time conversions:
                $this->assertEquals( TimedMediaHandler::parseTimeString( 100 ), 
100 );
+               $this->assertEquals( TimedMediaHandler::parseTimeString( 100.5 
), 100.5 );
+               $this->assertEquals( TimedMediaHandler::parseTimeString( 
'01:00' ), 60 );
                $this->assertEquals( TimedMediaHandler::parseTimeString( 
'1:0:0' ), 3600 );
+               $this->assertEquals( TimedMediaHandler::parseTimeString( 
'01:00:00' ), 3600 );
+               $this->assertEquals( TimedMediaHandler::parseTimeString( 
'01:00:00.532' ), 3600.532 );
                $this->assertEquals( TimedMediaHandler::parseTimeString( -1 ), 
0 );
                // Test longer than duration check ( should return time -1 )
                $this->assertEquals( TimedMediaHandler::parseTimeString( 10, 9 
), 8 );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I19fd74ff2a86ddcf9f620ac65ebcb715939d92e6
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