2007-12-06 11:53:43 +00:00
|
|
|
<?php
|
2009-08-20 22:37:17 +00:00
|
|
|
/*
|
2010-01-05 10:32:39 +00:00
|
|
|
* Name: Handle MP3
|
2007-12-06 11:53:43 +00:00
|
|
|
* Author: Shish <webmaster@shishnet.org>
|
|
|
|
* Description: Handle MP3 files
|
|
|
|
*/
|
|
|
|
|
2009-07-16 19:20:53 +00:00
|
|
|
class MP3FileHandler extends DataHandlerExtension {
|
|
|
|
protected function create_thumb($hash) {
|
2010-02-02 01:04:38 +00:00
|
|
|
copy("ext/handle_mp3/thumb.jpg", warehouse_path("thumbs", $hash));
|
2007-12-06 11:53:43 +00:00
|
|
|
}
|
|
|
|
|
2009-07-16 19:20:53 +00:00
|
|
|
protected function supported_ext($ext) {
|
2008-04-08 15:41:11 +00:00
|
|
|
$exts = array("mp3");
|
2009-06-05 19:53:00 +00:00
|
|
|
return in_array(strtolower($ext), $exts);
|
2008-04-08 15:41:11 +00:00
|
|
|
}
|
|
|
|
|
2009-07-16 19:20:53 +00:00
|
|
|
protected function create_image_from_data($filename, $metadata) {
|
2007-12-06 11:53:43 +00:00
|
|
|
global $config;
|
|
|
|
|
|
|
|
$image = new Image();
|
|
|
|
|
|
|
|
// FIXME: need more flash format specs :|
|
|
|
|
$image->width = 0;
|
|
|
|
$image->height = 0;
|
2009-01-04 19:18:37 +00:00
|
|
|
|
2007-12-06 11:53:43 +00:00
|
|
|
$image->filesize = $metadata['size'];
|
|
|
|
$image->hash = $metadata['hash'];
|
2012-09-23 23:09:28 +00:00
|
|
|
|
|
|
|
//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'];
|
|
|
|
}
|
|
|
|
|
2007-12-06 11:53:43 +00:00
|
|
|
$image->ext = $metadata['extension'];
|
2009-01-24 19:05:07 +00:00
|
|
|
$image->tag_array = Tag::explode($metadata['tags']);
|
2007-12-06 11:53:43 +00:00
|
|
|
$image->source = $metadata['source'];
|
|
|
|
|
|
|
|
return $image;
|
|
|
|
}
|
|
|
|
|
2009-07-16 19:20:53 +00:00
|
|
|
protected function check_contents($file) {
|
2012-09-23 23:09:28 +00:00
|
|
|
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;
|
2007-12-06 11:53:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|