diff --git a/conf/mime.conf b/conf/mime.conf index c2e03b775de1a2f2b93dce41f9eaa7d3414fe93f..56b72a42cfe140323c726bc89e30a6a46a51a3a3 100644 --- a/conf/mime.conf +++ b/conf/mime.conf @@ -15,6 +15,7 @@ wav audio/wav webm video/webm ogv video/ogg mp4 video/mp4 +vtt text/vtt tgz !application/octet-stream tar !application/x-gtar diff --git a/inc/media.php b/inc/media.php index e19cfa1032324d56360f8129d69cfaaaa5ceb585..1284660612238036124208676005d5a47dfb61fd 100644 --- a/inc/media.php +++ b/inc/media.php @@ -2460,4 +2460,39 @@ function media_supportedav($mime, $type=NULL){ return in_array($mime, $supportedAv); } +/** + * Return track media files with the same base name + * but extensions that indicate kind and lang. + * ie for foo.webm search foo.sub.lang.vtt, foo.cap.lang.vtt... + * + * @param string $src - ID of media file + * @return array - array(mediaID => array( kind, srclang )) + * + * @author Schplurtz le Déboulonné <Schplurtz@laposte.net> + */ +function media_trackfiles($src){ + $kinds=array( + 'sub' => 'subtitles', + 'cap' => 'captions', + 'des' => 'descriptions', + 'cha' => 'chapters', + 'met' => 'metadata' + ); + + $files = array(); + $re='/\\.(sub|cap|des|cha|met)\\.([^.]+)\\.vtt$/'; + $baseid=pathinfo($src, PATHINFO_FILENAME); + $pattern=mediaFN($baseid).'.*.*.vtt'; + $list=glob($pattern); + foreach($list as $track) { + if(preg_match($re, $track, $matches)){ + $files[$baseid.'.'.$matches[1].'.'.$matches[2].'.vtt']=array( + $kinds[$matches[1]], + $matches[2], + ); + } + } + return $files; +} + /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ diff --git a/inc/parser/xhtml.php b/inc/parser/xhtml.php index 727c82dca385e8c7d4ae61d2d5a9e0596f077ea0..393ec8d10f6ec37ce4c2d0553aab784f3394f0ba 100644 --- a/inc/parser/xhtml.php +++ b/inc/parser/xhtml.php @@ -1783,6 +1783,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer { * Embed video(s) in HTML * * @author Anika Henke <anika@selfthinker.org> + * @author Schplurtz le Déboulonné <Schplurtz@laposte.net> * * @param string $src - ID of video to embed * @param int $width - width of the video in pixels @@ -1800,6 +1801,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer { $posterUrl = ''; $files = array(); + $tracks = array(); $isExternal = media_isexternal($src); if ($isExternal) { @@ -1811,6 +1813,7 @@ class Doku_Renderer_xhtml extends Doku_Renderer { $extensions = array('webm', 'ogv', 'mp4'); $files = media_alternativefiles($src, $extensions); $poster = media_alternativefiles($src, array('jpg', 'png')); + $tracks = media_trackfiles($src); if(!empty($poster)) { $posterUrl = ml(reset($poster), '', true, '&'); } @@ -1839,6 +1842,14 @@ class Doku_Renderer_xhtml extends Doku_Renderer { $fallback .= $this->$linkType($file, $title, null, null, null, $cache = null, $linking = 'linkonly', $return = true); } + // output each track if any + foreach( $tracks as $trackid => $info ) { + list( $kind, $srclang ) = array_map( 'hsc', $info ); + $out .= "<track kind=\"$kind\" srclang=\"$srclang\" "; + $out .= "label=\"$srclang\" "; + $out .= 'src="'.ml($trackid, '', true).'">'.NL; + } + // finish $out .= $fallback; $out .= '</video>'.NL;