Skip to content

Commit

Permalink
feat: replace id3parser with mp3info
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
  • Loading branch information
kesselb committed Jun 28, 2023
1 parent fbc63fe commit 3757f39
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
17 changes: 6 additions & 11 deletions lib/private/Preview/MP3.php
Expand Up @@ -28,11 +28,10 @@
*/
namespace OC\Preview;

use ID3Parser\ID3Parser;

use OCP\Files\File;
use OCP\IImage;
use Psr\Log\LoggerInterface;
use wapmorgan\Mp3Info\Mp3Info;

class MP3 extends ProviderV2 {
/**
Expand All @@ -46,11 +45,12 @@ public function getMimeType(): string {
* {@inheritDoc}
*/
public function getThumbnail(File $file, int $maxX, int $maxY): ?IImage {
$getID3 = new ID3Parser();

$tmpPath = $this->getLocalFile($file);

try {
$tags = $getID3->analyze($tmpPath);
$audio = new Mp3Info($tmpPath, true);
/** @var string|null|false $picture */
$picture = $audio->getCover();
} catch (\Throwable $e) {
\OC::$server->get(LoggerInterface::class)->info($e->getMessage(), [
'exception' => $e,
Expand All @@ -61,12 +61,7 @@ public function getThumbnail(File $file, int $maxX, int $maxY): ?IImage {
$this->cleanTmpFiles();
}

$picture = isset($tags['id3v2']['APIC'][0]['data']) ? $tags['id3v2']['APIC'][0]['data'] : null;
if (is_null($picture) && isset($tags['id3v2']['PIC'][0]['data'])) {
$picture = $tags['id3v2']['PIC'][0]['data'];
}

if (!is_null($picture)) {
if (is_string($picture)) {
$image = new \OCP\Image();
$image->loadFromData($picture);

Expand Down

0 comments on commit 3757f39

Please sign in to comment.