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
|
|
|
|
*/
|
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
class MP3FileHandler extends DataHandlerExtension
|
|
|
|
{
|
|
|
|
protected function create_thumb(string $hash): bool
|
|
|
|
{
|
|
|
|
copy("ext/handle_mp3/thumb.jpg", warehouse_path("thumbs", $hash));
|
|
|
|
return true;
|
|
|
|
}
|
2007-12-06 11:53:43 +00:00
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
protected function supported_ext(string $ext): bool
|
|
|
|
{
|
|
|
|
$exts = ["mp3"];
|
|
|
|
return in_array(strtolower($ext), $exts);
|
|
|
|
}
|
2008-04-08 15:41:11 +00:00
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
protected function create_image_from_data(string $filename, array $metadata)
|
|
|
|
{
|
|
|
|
$image = new Image();
|
2007-12-06 11:53:43 +00:00
|
|
|
|
2019-05-28 16:59:38 +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
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
$image->filesize = $metadata['size'];
|
|
|
|
$image->hash = $metadata['hash'];
|
2017-03-10 19:12:01 +00:00
|
|
|
|
2019-05-28 16:59:38 +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'];
|
2017-03-10 19:12:01 +00:00
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
$image->ext = $metadata['extension'];
|
|
|
|
$image->tag_array = is_array($metadata['tags']) ? $metadata['tags'] : Tag::explode($metadata['tags']);
|
|
|
|
$image->source = $metadata['source'];
|
2007-12-06 11:53:43 +00:00
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
return $image;
|
|
|
|
}
|
2007-12-06 11:53:43 +00:00
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
protected function check_contents(string $tmpname): bool
|
|
|
|
{
|
|
|
|
$success = false;
|
2017-03-10 17:05:15 +00:00
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
if (file_exists($tmpname)) {
|
|
|
|
$mimeType = getMimeType($tmpname);
|
2017-03-10 17:05:15 +00:00
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
$success = ($mimeType == 'audio/mpeg');
|
|
|
|
}
|
2017-03-10 17:05:15 +00:00
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
return $success;
|
|
|
|
}
|
2007-12-06 11:53:43 +00:00
|
|
|
}
|