mp3.php 1.07 KB
Newer Older
Georg Ehrke's avatar
Georg Ehrke committed
1
<?php
Georg Ehrke's avatar
Georg Ehrke committed
2
/**
Georg Ehrke's avatar
Georg Ehrke committed
3
 * Copyright (c) 2013 Georg Ehrke georg@ownCloud.com
Georg Ehrke's avatar
Georg Ehrke committed
4
5
6
7
 * 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
8
9
namespace OC\Preview;

Georg Ehrke's avatar
Georg Ehrke committed
10
class MP3 extends Provider {
Georg Ehrke's avatar
Georg Ehrke committed
11

Georg Ehrke's avatar
Georg Ehrke committed
12
	public function getMimeType() {
Georg Ehrke's avatar
Georg Ehrke committed
13
14
15
		return '/audio\/mpeg/';
	}

Georg Ehrke's avatar
Georg Ehrke committed
16
	public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
Georg Ehrke's avatar
Georg Ehrke committed
17
		$getID3 = new \getID3();
18

Georg Ehrke's avatar
Georg Ehrke committed
19
20
21
22
23
24
25
		$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);
26
27
			$image = new \OC_Image();
			$image->loadFromData($picture);
Georg Ehrke's avatar
Georg Ehrke committed
28
29
			return $image->valid() ? $image : $this->getNoCoverThumbnail();
		}
30

Georg Ehrke's avatar
Georg Ehrke committed
31
		return $this->getNoCoverThumbnail();
Georg Ehrke's avatar
Georg Ehrke committed
32
	}
Georg Ehrke's avatar
Georg Ehrke committed
33

Georg Ehrke's avatar
Georg Ehrke committed
34
	private function getNoCoverThumbnail() {
Georg Ehrke's avatar
Georg Ehrke committed
35
36
37
38
39
40
		$icon = \OC::$SERVERROOT . '/core/img/filetypes/audio.png';

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

41
42
		$image = new \OC_Image();
		$image->loadFromFile($icon);
Georg Ehrke's avatar
Georg Ehrke committed
43
		return $image->valid() ? $image : false;
Georg Ehrke's avatar
Georg Ehrke committed
44
45
46
	}

}