MP3.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Georg Ehrke <oc.list@georgehrke.com>
  6. * @author Joas Schilling <coding@schilljs.com>
  7. * @author Lukas Reschke <lukas@statuscode.ch>
  8. * @author Olivier Paroz <github@oparoz.com>
  9. * @author Roeland Jago Douma <roeland@famdouma.nl>
  10. * @author Thomas Tanghus <thomas@tanghus.net>
  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. use ID3Parser\ID3Parser;
  29. class MP3 extends Provider {
  30. /**
  31. * {@inheritDoc}
  32. */
  33. public function getMimeType() {
  34. return '/audio\/mpeg/';
  35. }
  36. /**
  37. * {@inheritDoc}
  38. */
  39. public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
  40. $getID3 = new ID3Parser();
  41. $tmpPath = $fileview->toTmpFile($path);
  42. $tags = $getID3->analyze($tmpPath);
  43. unlink($tmpPath);
  44. $picture = isset($tags['id3v2']['APIC'][0]['data']) ? $tags['id3v2']['APIC'][0]['data'] : null;
  45. if(is_null($picture) && isset($tags['id3v2']['PIC'][0]['data'])) {
  46. $picture = $tags['id3v2']['PIC'][0]['data'];
  47. }
  48. if(!is_null($picture)) {
  49. $image = new \OC_Image();
  50. $image->loadFromData($picture);
  51. if ($image->valid()) {
  52. $image->scaleDownToFit($maxX, $maxY);
  53. return $image;
  54. }
  55. }
  56. return false;
  57. }
  58. }