Handle MP3: Use getID3() for validation, Fuzzy MP3 Detection + ID3 Reader

This commit is contained in:
velocity37 2012-09-23 16:09:28 -07:00 committed by Shish
parent afd75f1134
commit 44bcf6f322

View file

@ -26,7 +26,20 @@ class MP3FileHandler extends DataHandlerExtension {
$image->filesize = $metadata['size'];
$image->hash = $metadata['hash'];
$image->filename = $metadata['filename'];
//Cheat by using the filename to store artist/title if available
require_once('lib/getid3/getid3/getid3.php');
$getID3 = new getID3;
$ThisFileInfo = $getID3->analyze($filename, TRUE);
if (isset($ThisFileInfo['tags']['id3v2']['artist'][0]) && isset($ThisFileInfo['tags']['id3v2']['title'][0])) {
$image->filename = $ThisFileInfo['tags']['id3v2']['artist'][0]." - ".$ThisFileInfo['tags']['id3v2']['title'][0].".mp3";
} else if (isset($ThisFileInfo['tags']['id3v1']['artist'][0]) && isset($ThisFileInfo['tags']['id3v1']['title'][0])) {
$image->filename = $ThisFileInfo['tags']['id3v1']['artist'][0]." - ".$ThisFileInfo['tags']['id3v1']['title'][0].".mp3";
} else {
$image->filename = $metadata['filename'];
}
$image->ext = $metadata['extension'];
$image->tag_array = Tag::explode($metadata['tags']);
$image->source = $metadata['source'];
@ -35,8 +48,15 @@ class MP3FileHandler extends DataHandlerExtension {
}
protected function check_contents($file) {
// FIXME: mp3 magic header?
return (file_exists($file));
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;
}
}
return FALSE;
}
}
?>