2013-05-29 07:13:47 -04:00
|
|
|
<?php
|
2024-05-23 03:26:56 -04:00
|
|
|
|
2013-05-09 17:59:16 -04:00
|
|
|
/**
|
2024-05-23 03:26:56 -04:00
|
|
|
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2013-05-09 17:59:16 -04:00
|
|
|
*/
|
2013-05-29 06:33:24 -04:00
|
|
|
namespace OC\Preview;
|
|
|
|
|
|
2019-06-04 09:25:25 -04:00
|
|
|
use OCP\Files\File;
|
|
|
|
|
use OCP\IImage;
|
2023-05-28 10:57:21 -04:00
|
|
|
use wapmorgan\Mp3Info\Mp3Info;
|
2024-07-03 05:49:08 -04:00
|
|
|
use function OCP\Log\logger;
|
2019-06-04 09:25:25 -04:00
|
|
|
|
|
|
|
|
class MP3 extends ProviderV2 {
|
2014-11-28 03:16:35 -05:00
|
|
|
/**
|
|
|
|
|
* {@inheritDoc}
|
|
|
|
|
*/
|
2019-06-04 09:25:25 -04:00
|
|
|
public function getMimeType(): string {
|
2013-05-09 17:59:16 -04:00
|
|
|
return '/audio\/mpeg/';
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-28 03:16:35 -05:00
|
|
|
/**
|
|
|
|
|
* {@inheritDoc}
|
|
|
|
|
*/
|
2019-06-04 09:25:25 -04:00
|
|
|
public function getThumbnail(File $file, int $maxX, int $maxY): ?IImage {
|
|
|
|
|
$tmpPath = $this->getLocalFile($file);
|
2023-05-28 10:57:21 -04:00
|
|
|
|
2023-05-27 18:30:47 -04:00
|
|
|
try {
|
2023-05-28 10:57:21 -04:00
|
|
|
$audio = new Mp3Info($tmpPath, true);
|
|
|
|
|
/** @var string|null|false $picture */
|
|
|
|
|
$picture = $audio->getCover();
|
2023-05-27 18:30:47 -04:00
|
|
|
} catch (\Throwable $e) {
|
2024-07-03 05:49:08 -04:00
|
|
|
logger('core')->info('Error while getting cover from mp3 file: ' . $e->getMessage(), [
|
|
|
|
|
'fileId' => $file->getId(),
|
|
|
|
|
'filePath' => $file->getPath(),
|
2023-05-27 18:30:47 -04:00
|
|
|
]);
|
|
|
|
|
return null;
|
|
|
|
|
} finally {
|
|
|
|
|
$this->cleanTmpFiles();
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-28 10:57:21 -04:00
|
|
|
if (is_string($picture)) {
|
2022-06-01 20:37:36 -04:00
|
|
|
$image = new \OCP\Image();
|
2013-11-12 18:36:42 -05:00
|
|
|
$image->loadFromData($picture);
|
2015-06-06 10:21:36 -04:00
|
|
|
|
|
|
|
|
if ($image->valid()) {
|
|
|
|
|
$image->scaleDownToFit($maxX, $maxY);
|
|
|
|
|
|
|
|
|
|
return $image;
|
|
|
|
|
}
|
2013-07-30 06:29:12 -04:00
|
|
|
}
|
2013-05-28 05:49:18 -04:00
|
|
|
|
2019-06-04 09:25:25 -04:00
|
|
|
return null;
|
2013-05-17 05:32:42 -04:00
|
|
|
}
|
2013-05-09 17:59:16 -04:00
|
|
|
}
|