This repository has been archived on 2024-09-05. You can view files and clone it, but cannot push or open issues or pull requests.
shimmie2/ext/handle_mp3/main.php

69 lines
1.4 KiB
PHP
Raw Normal View History

<?php
2009-08-20 22:37:17 +00:00
/*
* Name: Handle MP3
* Author: Shish <webmaster@shishnet.org>
* Description: Handle MP3 files
*/
2009-07-16 19:20:53 +00:00
class MP3FileHandler extends DataHandlerExtension {
/**
* @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));
return true;
}
/**
* @param string $ext
* @return bool
*/
2009-07-16 19:20:53 +00:00
protected function supported_ext($ext) {
$exts = array("mp3");
2009-06-05 19:53:00 +00:00
return in_array(strtolower($ext), $exts);
}
/**
* @param string $filename
2015-09-27 11:38:48 +00:00
* @param mixed[] $metadata
* @return Image|null
*/
2009-07-16 19:20:53 +00:00
protected function create_image_from_data($filename, $metadata) {
$image = new Image();
//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
$image->filesize = $metadata['size'];
$image->hash = $metadata['hash'];
//Filename is renamed to "artist - title.mp3" when the user requests download by using the download attribute & jsmediatags.js
$image->filename = $metadata['filename'];
$image->ext = $metadata['extension'];
$image->tag_array = $metadata['tags'];
$image->source = $metadata['source'];
return $image;
}
/**
* @param $file
* @return bool
*/
2009-07-16 19:20:53 +00:00
protected function check_contents($file) {
$success = FALSE;
if (file_exists($file)) {
$mimeType = mime_content_type($file);
$success = ($mimeType == 'audio/mpeg');
}
return $success;
}
}