From bcd3dd1943bf8c837978469b6e91a40145e92c25 Mon Sep 17 00:00:00 2001 From: Derk-Jan Hartman Date: Wed, 28 Jul 2010 19:24:00 +0000 Subject: [PATCH] Recognize webm and matroska files. See also Bug 23888 Currently all webm files are stored as video/webm. It is not possible to detect wether this file is an audio file without using a full parser. This is why We should really move mime and mediatype accessors to the MediaHandlers. Using video/x-matroska for MKV files. There is no official mime for MKV (though the webm isn't official either, but everyone is already using it apparently). --- includes/MimeMagic.php | 21 ++++++++++++++++++++- includes/mime.info | 4 ++++ includes/mime.types | 4 ++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/includes/MimeMagic.php b/includes/MimeMagic.php index 85f02dc048..8c939e0df3 100644 --- a/includes/MimeMagic.php +++ b/includes/MimeMagic.php @@ -396,7 +396,8 @@ class MimeMagic { 'xbm', // Formats we recognize magic numbers for - 'djvu', 'ogx', 'ogg', 'ogv', 'oga', 'spx', 'mid', 'pdf', 'wmf', 'xcf', + 'djvu', 'ogx', 'ogg', 'ogv', 'oga', 'spx', + 'mid', 'pdf', 'wmf', 'xcf', 'webm', 'mkv', 'mka', // XML formats we sure hope we recognize reliably 'svg', @@ -468,6 +469,24 @@ class MimeMagic { } } + /* Look for WebM and Matroska files */ + if( strncmp( $head, pack( "C4", 0x1a, 0x45, 0xdf, 0xa3 ), 4 ) == 0 ) { + $doctype = strpos( $head, "\x42\x82" ); + if( $doctype ) { + // Next byte is datasize, then data (sizes larger than 1 byte are very stupid muxers) + $data = substr($head, $doctype+3, 8); + if( strncmp( $data, "matroska", 8 ) == 0 ) { + wfDebug( __METHOD__ . ": recognized file as video/x-matroska\n" ); + return "video/x-matroska"; + } else if ( strncmp( $data, "webm", 4 ) == 0 ) { + wfDebug( __METHOD__ . ": recognized file as video/webm\n" ); + return "video/webm"; + } + } + wfDebug( __METHOD__ . ": unknown EBML file\n" ); + return "unknown/unknown"; + } + /* * Look for PHP. Check for this before HTML/XML... Warning: this is a * heuristic, and won't match a file with a lot of non-PHP before. It diff --git a/includes/mime.info b/includes/mime.info index 610f6ecf97..4999d81f29 100644 --- a/includes/mime.info +++ b/includes/mime.info @@ -35,11 +35,15 @@ audio/ogg [AUDIO] audio/x-aiff [AUDIO] audio/x-pn-realaudio [AUDIO] audio/x-realaudio [AUDIO] +audio/webm [AUDIO] +audio/x-matroska [AUDIO] video/mpeg application/mpeg [VIDEO] video/ogg [VIDEO] video/x-sgi-video [VIDEO] video/x-flv [VIDEO] +video/webm [VIDEO] +video/x-matroska [VIDEO] application/ogg application/x-ogg audio/ogg audio/x-ogg video/ogg video/x-ogg [MULTIMEDIA] diff --git a/includes/mime.types b/includes/mime.types index b9f7e85115..4171d28dbb 100644 --- a/includes/mime.types +++ b/includes/mime.types @@ -64,7 +64,9 @@ audio/basic au snd audio/midi mid midi kar audio/mpeg mpga mp2 mp3 audio/ogg oga ogg spx +audio/webm webm audio/x-aiff aif aiff aifc +audio/x-matroska mka mkv audio/x-mpegurl m3u audio/x-ogg oga ogg spx audio/x-pn-realaudio ram rm @@ -114,7 +116,9 @@ video/mpeg mpeg mpg mpe video/ogg ogv ogm ogg video/quicktime qt mov video/vnd.mpegurl mxu +video/webm webm video/x-flv flv +video/x-matroska mkv mka video/x-msvideo avi video/x-ogg ogv ogm ogg video/x-sgi-movie movie -- 2.20.1