Completed
Push — master ( c38f87...350aa8 )
by Lukas
27s
created

MP3::getNoCoverThumbnail()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 7
nc 3
nop 0
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * @copyright Copyright (c) 2016, ownCloud, Inc.
4
 *
5
 * @author Georg Ehrke <[email protected]>
6
 * @author Hendrik Leppelsack <[email protected]>
7
 * @author Joas Schilling <[email protected]>
8
 * @author Lukas Reschke <[email protected]>
9
 * @author Olivier Paroz <[email protected]>
10
 * @author Thomas Tanghus <[email protected]>
11
 *
12
 * @license AGPL-3.0
13
 *
14
 * This code is free software: you can redistribute it and/or modify
15
 * it under the terms of the GNU Affero General Public License, version 3,
16
 * as published by the Free Software Foundation.
17
 *
18
 * This program is distributed in the hope that it will be useful,
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
 * GNU Affero General Public License for more details.
22
 *
23
 * You should have received a copy of the GNU Affero General Public License, version 3,
24
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
25
 *
26
 */
27
namespace OC\Preview;
28
29
use ID3Parser\ID3Parser;
30
31
class MP3 extends Provider {
32
	/**
33
	 * {@inheritDoc}
34
	 */
35
	public function getMimeType() {
36
		return '/audio\/mpeg/';
37
	}
38
39
	/**
40
	 * {@inheritDoc}
41
	 */
42
	public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
43
		$getID3 = new ID3Parser();
44
45
		$tmpPath = $fileview->toTmpFile($path);
46
		$tags = $getID3->analyze($tmpPath);
47
		unlink($tmpPath);
48
		$picture = isset($tags['id3v2']['APIC'][0]['data']) ? $tags['id3v2']['APIC'][0]['data'] : null;
49
		if(is_null($picture) && isset($tags['id3v2']['PIC'][0]['data'])) {
50
			$picture = $tags['id3v2']['PIC'][0]['data'];
51
		}
52
53
		if(!is_null($picture)) {
54
			$image = new \OC_Image();
55
			$image->loadFromData($picture);
56
57
			if ($image->valid()) {
58
				$image->scaleDownToFit($maxX, $maxY);
59
60
				return $image;
61
			}
62
		}
63
64
		return false;
65
	}
66
}
67