You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MP3.php 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Georg Ehrke <oc.list@georgehrke.com>
  7. * @author Joas Schilling <coding@schilljs.com>
  8. * @author Lukas Reschke <lukas@statuscode.ch>
  9. * @author Olivier Paroz <github@oparoz.com>
  10. * @author Robin Appelman <robin@icewind.nl>
  11. * @author Roeland Jago Douma <roeland@famdouma.nl>
  12. * @author Thomas Tanghus <thomas@tanghus.net>
  13. *
  14. * @license AGPL-3.0
  15. *
  16. * This code is free software: you can redistribute it and/or modify
  17. * it under the terms of the GNU Affero General Public License, version 3,
  18. * as published by the Free Software Foundation.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU Affero General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU Affero General Public License, version 3,
  26. * along with this program. If not, see <http://www.gnu.org/licenses/>
  27. *
  28. */
  29. namespace OC\Preview;
  30. use ID3Parser\ID3Parser;
  31. use OCP\Files\File;
  32. use OCP\IImage;
  33. class MP3 extends ProviderV2 {
  34. /**
  35. * {@inheritDoc}
  36. */
  37. public function getMimeType(): string {
  38. return '/audio\/mpeg/';
  39. }
  40. /**
  41. * {@inheritDoc}
  42. */
  43. public function getThumbnail(File $file, int $maxX, int $maxY): ?IImage {
  44. $getID3 = new ID3Parser();
  45. $tmpPath = $this->getLocalFile($file);
  46. $tags = $getID3->analyze($tmpPath);
  47. $this->cleanTmpFiles();
  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. if (!is_null($picture)) {
  53. $image = new \OC_Image();
  54. $image->loadFromData($picture);
  55. if ($image->valid()) {
  56. $image->scaleDownToFit($maxX, $maxY);
  57. return $image;
  58. }
  59. }
  60. return null;
  61. }
  62. }