Index: trunk/extensions/OggHandler/OggHandler_body.php |
— | — | @@ -23,11 +23,13 @@ |
24 | 24 | 'ogg_noplayer' => 'noplayer', |
25 | 25 | 'ogg_noicon' => 'noicon', |
26 | 26 | 'ogg_thumbtime' => 'thumbtime', |
| 27 | + 'ogg_starttime' => 'start', |
| 28 | + 'ogg_endtime' => 'end', |
27 | 29 | ); |
28 | 30 | } |
29 | 31 | |
30 | | - function validateParam( $name, $value ) { |
31 | | - if ( $name == 'thumbtime' ) { |
| 32 | + function validateParam( $name, $value ) { |
| 33 | + if ( $name == 'thumbtime' || $name == 'start' || $name == 'end' ) { |
32 | 34 | if ( $this->parseTimeString( $value ) === false ) { |
33 | 35 | return false; |
34 | 36 | } |
— | — | @@ -72,19 +74,28 @@ |
73 | 75 | } |
74 | 76 | return array(); |
75 | 77 | } |
76 | | - |
77 | | - function normaliseParams( $image, &$params ) { |
78 | | - if ( isset( $params['thumbtime'] ) ) { |
79 | | - $length = $this->getLength( $image ); |
80 | | - $time = $this->parseTimeString( $params['thumbtime'] ); |
81 | | - if ( $time === false ) { |
82 | | - return false; |
83 | | - } elseif ( $time > $length - 1 ) { |
84 | | - $params['thumbtime'] = $length - 1; |
85 | | - } elseif ( $time <= 0 ) { |
86 | | - $params['thumbtime'] = 0; |
| 78 | + |
| 79 | + function normaliseParams( $image, &$params ) { |
| 80 | + $timeParam = array('thumbtime', 'start', 'end'); |
| 81 | + //parse time values if endtime or thumbtime can't be more than length -1 |
| 82 | + foreach($timeParam as $pn){ |
| 83 | + if ( isset( $params[$pn] ) ) { |
| 84 | + $length = $this->getLength( $image ); |
| 85 | + $time = $this->parseTimeString( $params[$pn] ); |
| 86 | + if ( $time === false ) { |
| 87 | + return false; |
| 88 | + } elseif ( $time > $length - 1 ) { |
| 89 | + $params[$pn] = $length - 1; |
| 90 | + } elseif ( $time <= 0 ) { |
| 91 | + $params[$pn] = 0; |
| 92 | + } |
87 | 93 | } |
88 | 94 | } |
| 95 | + //make sure start time is not > than end time |
| 96 | + if(isset($params['start']) && isset($params['end']) ){ |
| 97 | + if($params['start'] > $params['end']) |
| 98 | + return false; |
| 99 | + } |
89 | 100 | |
90 | 101 | return true; |
91 | 102 | } |
— | — | @@ -171,7 +182,7 @@ |
172 | 183 | } |
173 | 184 | |
174 | 185 | function doTransform( $file, $dstPath, $dstUrl, $params, $flags = 0 ) { |
175 | | - global $wgFFmpegLocation; |
| 186 | + global $wgFFmpegLocation, $wgEnableTemporalOggUrls; |
176 | 187 | |
177 | 188 | $width = $params['width']; |
178 | 189 | $srcWidth = $file->getWidth(); |
— | — | @@ -182,6 +193,14 @@ |
183 | 194 | $noPlayer = isset( $params['noplayer'] ); |
184 | 195 | $noIcon = isset( $params['noicon'] ); |
185 | 196 | |
| 197 | + $oggAppendReq = ''; |
| 198 | + //add temporal request parameter if $wgEnableTemporalOggUrls is on: |
| 199 | + if($wgEnableTemporalOggUrls && isset( $params['start'] ) ){ |
| 200 | + $oggAppendReq .= '?t=' . seconds2npt( $params['start'] ); |
| 201 | + if(isset( $params['end'] ) && $params['end'] ) |
| 202 | + $oggAppendReq.='/'. seconds2npt( $params['end'] ); |
| 203 | + } |
| 204 | + |
186 | 205 | if ( !$noPlayer ) { |
187 | 206 | // Hack for miscellaneous callers |
188 | 207 | global $wgOut; |
— | — | @@ -207,7 +226,7 @@ |
208 | 227 | } else { |
209 | 228 | $width = $params['width']; |
210 | 229 | } |
211 | | - return new OggAudioDisplay( $file, $file->getURL(), $width, $height, $length, $dstPath, $noIcon, $offset ); |
| 230 | + return new OggAudioDisplay( $file, $file->getURL().$oggAppendReq, $width, $height, $length, $dstPath, $noIcon, $offset ); |
212 | 231 | } |
213 | 232 | |
214 | 233 | // Video thumbnail only |
— | — | @@ -216,16 +235,16 @@ |
217 | 236 | } |
218 | 237 | |
219 | 238 | if ( $flags & self::TRANSFORM_LATER ) { |
220 | | - return new OggVideoDisplay( $file, $file->getURL(), $dstUrl, $width, $height, $length, $dstPath, $noIcon, $offset); |
| 239 | + return new OggVideoDisplay( $file, $file->getURL().$oggAppendReq, $dstUrl, $width, $height, $length, $dstPath, $noIcon, $offset); |
221 | 240 | } |
222 | 241 | |
223 | | - $thumbTime = false; |
| 242 | + $thumbtime = false; |
224 | 243 | if ( isset( $params['thumbtime'] ) ) { |
225 | | - $thumbTime = $this->parseTimeString( $params['thumbtime'], $length ); |
| 244 | + $thumbtime = $this->parseTimeString( $params['thumbtime'], $length ); |
226 | 245 | } |
227 | | - if ( $thumbTime === false ) { |
| 246 | + if ( $thumbtime === false ) { |
228 | 247 | # Seek to midpoint by default, it tends to be more interesting than the start |
229 | | - $thumbTime = $length / 2; |
| 248 | + $thumbtime = $length / 2; |
230 | 249 | } |
231 | 250 | |
232 | 251 | wfMkdirParents( dirname( $dstPath ) ); |
— | — | @@ -281,7 +300,7 @@ |
282 | 301 | return new MediaTransformError( 'thumbnail_error', $width, $height, implode( "\n", $lines ) ); |
283 | 302 | } |
284 | 303 | } |
285 | | - return new OggVideoDisplay( $file, $file->getURL(), $dstUrl, $width, $height, $length, $dstPath ); |
| 304 | + return new OggVideoDisplay( $file, $file->getURL() . $oggAppendReq, $dstUrl, $width, $height, $length, $dstPath ); |
286 | 305 | } |
287 | 306 | |
288 | 307 | function canRender( $file ) { return true; } |
— | — | @@ -710,5 +729,61 @@ |
711 | 730 | parent::__construct( $file, $videoUrl, false, $width, $height, $length, false, $path, $noIcon, $offset ); |
712 | 731 | } |
713 | 732 | } |
| 733 | +/*utility functions*/ |
| 734 | +/* |
| 735 | + * takes seconds duration and return hh:mm:ss time |
| 736 | + */ |
| 737 | +if(!function_exists('seconds2npt')){ |
| 738 | + function seconds2npt( $seconds, $short = false ) { |
| 739 | + $dur = time_duration_2array( $seconds ); |
| 740 | + if( ! $dur ) |
| 741 | + return null; |
| 742 | + // be sure to output leading zeros (for min,sec): |
| 743 | + if ( $dur['hours'] == 0 && $short == true ) { |
| 744 | + return sprintf( "%2d:%02d", $dur['minutes'], $dur['seconds'] ); |
| 745 | + } else { |
| 746 | + return sprintf( "%d:%02d:%02d", $dur['hours'], $dur['minutes'], $dur['seconds'] ); |
| 747 | + } |
| 748 | + } |
| 749 | +} |
| 750 | +/* |
| 751 | + * converts seconds to time unit array |
| 752 | + */ |
| 753 | +if(!function_exists('time_duration_2array')){ |
| 754 | + function time_duration_2array ( $seconds, $periods = null ) { |
| 755 | + // Define time periods |
| 756 | + if ( !is_array( $periods ) ) { |
| 757 | + $periods = array ( |
| 758 | + 'years' => 31556926, |
| 759 | + 'months' => 2629743, |
| 760 | + 'weeks' => 604800, |
| 761 | + 'days' => 86400, |
| 762 | + 'hours' => 3600, |
| 763 | + 'minutes' => 60, |
| 764 | + 'seconds' => 1 |
| 765 | + ); |
| 766 | + } |
| 767 | + |
| 768 | + // Loop |
| 769 | + $seconds = (float) $seconds; |
| 770 | + foreach ( $periods as $period => $value ) { |
| 771 | + $count = floor( $seconds / $value ); |
| 772 | + if ( $count == 0 ) { |
| 773 | + // must include hours minutes and seconds even if they are 0 |
| 774 | + if ( $period == 'hours' || $period == 'minutes' || $period == 'seconds' ) { |
| 775 | + $values[$period] = 0; |
| 776 | + } |
| 777 | + continue; |
| 778 | + } |
| 779 | + $values[$period] = sprintf( "%02d", $count ); |
| 780 | + $seconds = $seconds % $value; |
| 781 | + } |
| 782 | + // Return |
| 783 | + if ( empty( $values ) ) { |
| 784 | + $values = null; |
| 785 | + } |
| 786 | + return $values; |
| 787 | + } |
| 788 | +} |
714 | 789 | |
715 | 790 | ?> |
Index: trunk/extensions/OggHandler/OggHandler.i18n.php |
— | — | @@ -4,7 +4,9 @@ |
5 | 5 | 'en' => array( |
6 | 6 | 'ogg_noplayer' => array( 0, 'noplayer' ), |
7 | 7 | 'ogg_noicon' => array( 0, 'noicon' ), |
8 | | - 'ogg_thumbtime' => array( 0, 'thumbtime=$1' ), |
| 8 | + 'ogg_thumbtime' => array( 0, 'thumbtime=$1' ), |
| 9 | + 'ogg_starttime' => array( 0, 'start=$1'), |
| 10 | + 'ogg_endtime' => array( 0, 'end=$1'), |
9 | 11 | ), |
10 | 12 | ); |
11 | 13 | |