From 84e86c4930b51f0da0a24a9b577da0c2aa77fc79 Mon Sep 17 00:00:00 2001 From: Daku Date: Fri, 10 Mar 2017 17:05:15 +0000 Subject: [PATCH] use mime_content_type instead of getID3 + use proper MP4 mimetype --- ext/handle_mp3/main.php | 22 ++++++++--------- ext/handle_video/main.php | 50 ++++++++++++++++----------------------- 2 files changed, 31 insertions(+), 41 deletions(-) diff --git a/ext/handle_mp3/main.php b/ext/handle_mp3/main.php index 3ccd2871..64aa7d45 100644 --- a/ext/handle_mp3/main.php +++ b/ext/handle_mp3/main.php @@ -30,13 +30,11 @@ class MP3FileHandler extends DataHandlerExtension { * @return Image|null */ protected function create_image_from_data($filename, $metadata) { - global $config; - $image = new Image(); - // FIXME: need more flash format specs :| - $image->width = 0; - $image->height = 0; + //NOTE: No need to set width/height as we don't use it. + $image->width = 1; + $image->height = 1; $image->filesize = $metadata['size']; $image->hash = $metadata['hash']; @@ -66,15 +64,15 @@ class MP3FileHandler extends DataHandlerExtension { * @return bool */ protected function check_contents($file) { + $success = FALSE; + if (file_exists($file)) { - require_once('lib/getid3/getid3/getid3.php'); - $getID3 = new getID3; - $ThisFileInfo = $getID3->analyze($file, TRUE); - if (isset($ThisFileInfo['fileformat']) && $ThisFileInfo['fileformat'] == "mp3") { - return TRUE; - } + $mimeType = mime_content_type($file); + + $success = ($mimeType == 'audio/mpeg'); } - return FALSE; + + return $success; } } diff --git a/ext/handle_video/main.php b/ext/handle_video/main.php index c84f6016..4edbcc32 100644 --- a/ext/handle_video/main.php +++ b/ext/handle_video/main.php @@ -12,8 +12,6 @@ * OGV, WEBM: HTML5
* MP4's flash fallback is forced with a bit of Javascript as some browsers won't fallback if they can't play H.264. * In the future, it may be necessary to change the user agent checks to reflect the current state of H.264 support.

- * Made possible by:
- * getID3() - Gets media information with PHP (no bulky FFMPEG API required).
*/ class VideoFileHandler extends DataHandlerExtension { @@ -145,31 +143,25 @@ class VideoFileHandler extends DataHandlerExtension { * @return Image */ protected function create_image_from_data($filename, $metadata) { - $image = new Image(); - require_once('lib/getid3/getid3/getid3.php'); - $getID3 = new getID3; - $ThisFileInfo = $getID3->analyze($filename); + //NOTE: No need to set width/height as we don't use it. + $image->width = 1; + $image->height = 1; - if (isset($ThisFileInfo['video']['resolution_x']) && isset($ThisFileInfo['video']['resolution_y'])) { - $image->width = $ThisFileInfo['video']['resolution_x']; - $image->height = $ThisFileInfo['video']['resolution_y']; - } else { - $image->width = 0; - $image->height = 0; - } - - switch ($ThisFileInfo['mime_type']) { + switch (mime_content_type($filename)) { case "video/webm": $image->ext = "webm"; break; - case "video/quicktime": + case "video/mp4": $image->ext = "mp4"; break; - case "application/ogg": + case "video/ogg": $image->ext = "ogv"; break; + case "video/flv": + $image->ext = "flv"; + break; case "video/x-flv": $image->ext = "flv"; break; @@ -189,20 +181,20 @@ class VideoFileHandler extends DataHandlerExtension { * @return bool */ protected function check_contents($file) { + $success = FALSE; if (file_exists($file)) { - require_once('lib/getid3/getid3/getid3.php'); - $getID3 = new getID3; - $ThisFileInfo = $getID3->analyze($file); - if (isset($ThisFileInfo['mime_type']) && ( - $ThisFileInfo['mime_type'] == "video/webm" || - $ThisFileInfo['mime_type'] == "video/quicktime" || - $ThisFileInfo['mime_type'] == "application/ogg" || - $ThisFileInfo['mime_type'] == 'video/x-flv') - ) { - return TRUE; - } + $mimeType = mime_content_type($file); + + $success = in_array($mimeType, [ + 'video/webm', + 'video/mp4', + 'video/ogg', + 'video/flv', + 'video/x-flv' + ]); } - return FALSE; + + return $success; } }