51 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			51 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						|
/*
 | 
						|
 * Name: Handle MP3
 | 
						|
 * Author: Shish <webmaster@shishnet.org>
 | 
						|
 * Description: Handle MP3 files
 | 
						|
 */
 | 
						|
 | 
						|
class MP3FileHandler extends DataHandlerExtension {
 | 
						|
	protected function create_thumb(string $hash): bool {
 | 
						|
		copy("ext/handle_mp3/thumb.jpg", warehouse_path("thumbs", $hash));
 | 
						|
		return true;
 | 
						|
	}
 | 
						|
 | 
						|
	protected function supported_ext(string $ext): bool {
 | 
						|
		$exts = array("mp3");
 | 
						|
		return in_array(strtolower($ext), $exts);
 | 
						|
	}
 | 
						|
 | 
						|
	protected function create_image_from_data(string $filename, array $metadata) {
 | 
						|
		$image = new Image();
 | 
						|
 | 
						|
		//NOTE: No need to set width/height as we don't use it.
 | 
						|
		$image->width  = 1;
 | 
						|
		$image->height = 1;
 | 
						|
 | 
						|
		$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 = is_array($metadata['tags']) ? $metadata['tags'] : Tag::explode($metadata['tags']);
 | 
						|
		$image->source    = $metadata['source'];
 | 
						|
 | 
						|
		return $image;
 | 
						|
	}
 | 
						|
 | 
						|
	protected function check_contents(string $tmpname): bool {
 | 
						|
		$success = FALSE;
 | 
						|
 | 
						|
		if (file_exists($tmpname)) {
 | 
						|
			$mimeType = mime_content_type($tmpname);
 | 
						|
 | 
						|
			$success = ($mimeType == 'audio/mpeg');
 | 
						|
		}
 | 
						|
 | 
						|
		return $success;
 | 
						|
	}
 | 
						|
}
 |