use mime_content_type instead of getID3 + use proper MP4 mimetype

This commit is contained in:
Daku 2017-03-10 17:05:15 +00:00
parent 256d09a3ec
commit 84e86c4930
2 changed files with 31 additions and 41 deletions

View file

@ -30,13 +30,11 @@ class MP3FileHandler extends DataHandlerExtension {
* @return Image|null * @return Image|null
*/ */
protected function create_image_from_data($filename, $metadata) { protected function create_image_from_data($filename, $metadata) {
global $config;
$image = new Image(); $image = new Image();
// FIXME: need more flash format specs :| //NOTE: No need to set width/height as we don't use it.
$image->width = 0; $image->width = 1;
$image->height = 0; $image->height = 1;
$image->filesize = $metadata['size']; $image->filesize = $metadata['size'];
$image->hash = $metadata['hash']; $image->hash = $metadata['hash'];
@ -66,15 +64,15 @@ class MP3FileHandler extends DataHandlerExtension {
* @return bool * @return bool
*/ */
protected function check_contents($file) { protected function check_contents($file) {
$success = FALSE;
if (file_exists($file)) { if (file_exists($file)) {
require_once('lib/getid3/getid3/getid3.php'); $mimeType = mime_content_type($file);
$getID3 = new getID3;
$ThisFileInfo = $getID3->analyze($file, TRUE); $success = ($mimeType == 'audio/mpeg');
if (isset($ThisFileInfo['fileformat']) && $ThisFileInfo['fileformat'] == "mp3") {
return TRUE;
}
} }
return FALSE;
return $success;
} }
} }

View file

@ -12,8 +12,6 @@
* OGV, WEBM: HTML5<br> * OGV, WEBM: HTML5<br>
* MP4's flash fallback is forced with a bit of Javascript as some browsers won't fallback if they can't play H.264. * 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.<br><br> * In the future, it may be necessary to change the user agent checks to reflect the current state of H.264 support.<br><br>
* Made possible by:<br>
* <a href='http://getid3.sourceforge.net/'>getID3()</a> - Gets media information with PHP (no bulky FFMPEG API required).<br>
*/ */
class VideoFileHandler extends DataHandlerExtension { class VideoFileHandler extends DataHandlerExtension {
@ -145,31 +143,25 @@ class VideoFileHandler extends DataHandlerExtension {
* @return Image * @return Image
*/ */
protected function create_image_from_data($filename, $metadata) { protected function create_image_from_data($filename, $metadata) {
$image = new Image(); $image = new Image();
require_once('lib/getid3/getid3/getid3.php'); //NOTE: No need to set width/height as we don't use it.
$getID3 = new getID3; $image->width = 1;
$ThisFileInfo = $getID3->analyze($filename); $image->height = 1;
if (isset($ThisFileInfo['video']['resolution_x']) && isset($ThisFileInfo['video']['resolution_y'])) { switch (mime_content_type($filename)) {
$image->width = $ThisFileInfo['video']['resolution_x'];
$image->height = $ThisFileInfo['video']['resolution_y'];
} else {
$image->width = 0;
$image->height = 0;
}
switch ($ThisFileInfo['mime_type']) {
case "video/webm": case "video/webm":
$image->ext = "webm"; $image->ext = "webm";
break; break;
case "video/quicktime": case "video/mp4":
$image->ext = "mp4"; $image->ext = "mp4";
break; break;
case "application/ogg": case "video/ogg":
$image->ext = "ogv"; $image->ext = "ogv";
break; break;
case "video/flv":
$image->ext = "flv";
break;
case "video/x-flv": case "video/x-flv":
$image->ext = "flv"; $image->ext = "flv";
break; break;
@ -189,20 +181,20 @@ class VideoFileHandler extends DataHandlerExtension {
* @return bool * @return bool
*/ */
protected function check_contents($file) { protected function check_contents($file) {
$success = FALSE;
if (file_exists($file)) { if (file_exists($file)) {
require_once('lib/getid3/getid3/getid3.php'); $mimeType = mime_content_type($file);
$getID3 = new getID3;
$ThisFileInfo = $getID3->analyze($file); $success = in_array($mimeType, [
if (isset($ThisFileInfo['mime_type']) && ( 'video/webm',
$ThisFileInfo['mime_type'] == "video/webm" || 'video/mp4',
$ThisFileInfo['mime_type'] == "video/quicktime" || 'video/ogg',
$ThisFileInfo['mime_type'] == "application/ogg" || 'video/flv',
$ThisFileInfo['mime_type'] == 'video/x-flv') 'video/x-flv'
) { ]);
return TRUE;
}
} }
return FALSE;
return $success;
} }
} }