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 {
|
2014-04-28 04:56:19 +00:00
|
|
|
/**
|
|
|
|
* @param string $hash
|
|
|
|
* @return bool
|
|
|
|
*/
|
2009-07-16 19:20:53 +00:00
|
|
|
protected function create_thumb($hash) {
|
2010-02-02 01:04:38 +00:00
|
|
|
copy("ext/handle_mp3/thumb.jpg", warehouse_path("thumbs", $hash));
|
2014-04-28 04:56:19 +00:00
|
|
|
return true;
|
2007-12-06 11:53:43 +00:00
|
|
|
}
|
|
|
|
|
2014-04-28 04:56:19 +00:00
|
|
|
/**
|
|
|
|
* @param string $ext
|
|
|
|
* @return bool
|
|
|
|
*/
|
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
|
|
|
}
|
|
|
|
|
2014-04-28 04:56:19 +00:00
|
|
|
/**
|
|
|
|
* @param string $filename
|
2015-09-27 11:38:48 +00:00
|
|
|
* @param mixed[] $metadata
|
2014-04-28 04:56:19 +00:00
|
|
|
* @return Image|null
|
|
|
|
*/
|
2009-07-16 19:20:53 +00:00
|
|
|
protected function create_image_from_data($filename, $metadata) {
|
2007-12-06 11:53:43 +00:00
|
|
|
$image = new Image();
|
|
|
|
|
2017-03-10 17:05:15 +00:00
|
|
|
//NOTE: No need to set width/height as we don't use it.
|
|
|
|
$image->width = 1;
|
|
|
|
$image->height = 1;
|
2009-01-04 19:18:37 +00:00
|
|
|
|
2007-12-06 11:53:43 +00:00
|
|
|
$image->filesize = $metadata['size'];
|
|
|
|
$image->hash = $metadata['hash'];
|
2017-03-10 19:12:01 +00:00
|
|
|
|
|
|
|
//Filename is renamed to "artist - title.mp3" when the user requests download by using the download attribute & jsmediatags.js
|
|
|
|
$image->filename = $metadata['filename'];
|
|
|
|
|
2007-12-06 11:53:43 +00:00
|
|
|
$image->ext = $metadata['extension'];
|
2017-05-12 07:57:50 +00:00
|
|
|
$image->tag_array = is_array($metadata['tags']) ? $metadata['tags'] : Tag::explode($metadata['tags']);
|
2007-12-06 11:53:43 +00:00
|
|
|
$image->source = $metadata['source'];
|
|
|
|
|
|
|
|
return $image;
|
|
|
|
}
|
|
|
|
|
2014-04-28 04:56:19 +00:00
|
|
|
/**
|
|
|
|
* @param $file
|
|
|
|
* @return bool
|
|
|
|
*/
|
2009-07-16 19:20:53 +00:00
|
|
|
protected function check_contents($file) {
|
2017-03-10 17:05:15 +00:00
|
|
|
$success = FALSE;
|
|
|
|
|
2012-09-23 23:09:28 +00:00
|
|
|
if (file_exists($file)) {
|
2017-03-10 17:05:15 +00:00
|
|
|
$mimeType = mime_content_type($file);
|
|
|
|
|
|
|
|
$success = ($mimeType == 'audio/mpeg');
|
2012-09-23 23:09:28 +00:00
|
|
|
}
|
2017-03-10 17:05:15 +00:00
|
|
|
|
|
|
|
return $success;
|
2007-12-06 11:53:43 +00:00
|
|
|
}
|
|
|
|
}
|
2014-04-26 02:54:51 +00:00
|
|
|
|