mp3.php 1.27 KB
Newer Older
Georg Ehrke's avatar
Georg Ehrke committed
1
<?php
Georg Ehrke's avatar
Georg Ehrke committed
2
/**
3
4
5
6
 * Copyright (c) 2013 Georg Ehrke georg@ownCloud.com
 * This file is licensed under the Affero General Public License version 3 or
 * later.
 * See the COPYING-README file.
Georg Ehrke's avatar
Georg Ehrke committed
7
 */
Georg Ehrke's avatar
Georg Ehrke committed
8
9
namespace OC\Preview;

Georg Ehrke's avatar
Georg Ehrke committed
10
class MP3 extends Provider {
11
12
13
	/**
	 * {@inheritDoc}
	 */
Georg Ehrke's avatar
Georg Ehrke committed
14
	public function getMimeType() {
Georg Ehrke's avatar
Georg Ehrke committed
15
16
17
		return '/audio\/mpeg/';
	}

18
19
20
	/**
	 * {@inheritDoc}
	 */
Georg Ehrke's avatar
Georg Ehrke committed
21
	public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
Georg Ehrke's avatar
Georg Ehrke committed
22
		$getID3 = new \getID3();
23

Georg Ehrke's avatar
Georg Ehrke committed
24
25
26
27
28
29
30
		$tmpPath = $fileview->toTmpFile($path);

		$tags = $getID3->analyze($tmpPath);
		\getid3_lib::CopyTagsToComments($tags);
		if(isset($tags['id3v2']['APIC'][0]['data'])) {
			$picture = @$tags['id3v2']['APIC'][0]['data'];
			unlink($tmpPath);
31
32
			$image = new \OC_Image();
			$image->loadFromData($picture);
Georg Ehrke's avatar
Georg Ehrke committed
33
34
			return $image->valid() ? $image : $this->getNoCoverThumbnail();
		}
35

Georg Ehrke's avatar
Georg Ehrke committed
36
		return $this->getNoCoverThumbnail();
Georg Ehrke's avatar
Georg Ehrke committed
37
	}
Georg Ehrke's avatar
Georg Ehrke committed
38

39
40
41
	/**
	 * Generates a default image when the file has no cover
	 *
42
	 * @return bool|\OCP\IImage false if the default image is missing or invalid
43
	 */
Georg Ehrke's avatar
Georg Ehrke committed
44
	private function getNoCoverThumbnail() {
Georg Ehrke's avatar
Georg Ehrke committed
45
46
47
48
49
50
		$icon = \OC::$SERVERROOT . '/core/img/filetypes/audio.png';

		if(!file_exists($icon)) {
			return false;
		}

51
52
		$image = new \OC_Image();
		$image->loadFromFile($icon);
Georg Ehrke's avatar
Georg Ehrke committed
53
		return $image->valid() ? $image : false;
Georg Ehrke's avatar
Georg Ehrke committed
54
55
56
	}

}