mp3.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /**
  3. * @author Georg Ehrke <georg@owncloud.com>
  4. * @author Georg Ehrke <georg@ownCloud.com>
  5. * @author Joas Schilling <nickvergessen@owncloud.com>
  6. * @author Morris Jobke <hey@morrisjobke.de>
  7. * @author Thomas Tanghus <thomas@tanghus.net>
  8. *
  9. * @copyright Copyright (c) 2015, ownCloud, Inc.
  10. * @license AGPL-3.0
  11. *
  12. * This code is free software: you can redistribute it and/or modify
  13. * it under the terms of the GNU Affero General Public License, version 3,
  14. * as published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License, version 3,
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>
  23. *
  24. */
  25. namespace OC\Preview;
  26. class MP3 extends Provider {
  27. /**
  28. * {@inheritDoc}
  29. */
  30. public function getMimeType() {
  31. return '/audio\/mpeg/';
  32. }
  33. /**
  34. * {@inheritDoc}
  35. */
  36. public function getThumbnail($path, $maxX, $maxY, $scalingup, $fileview) {
  37. $getID3 = new \getID3();
  38. $tmpPath = $fileview->toTmpFile($path);
  39. $tags = $getID3->analyze($tmpPath);
  40. \getid3_lib::CopyTagsToComments($tags);
  41. if(isset($tags['id3v2']['APIC'][0]['data'])) {
  42. $picture = @$tags['id3v2']['APIC'][0]['data'];
  43. unlink($tmpPath);
  44. $image = new \OC_Image();
  45. $image->loadFromData($picture);
  46. return $image->valid() ? $image : $this->getNoCoverThumbnail();
  47. }
  48. return $this->getNoCoverThumbnail();
  49. }
  50. /**
  51. * Generates a default image when the file has no cover
  52. *
  53. * @return bool|\OCP\IImage false if the default image is missing or invalid
  54. */
  55. private function getNoCoverThumbnail() {
  56. $icon = \OC::$SERVERROOT . '/core/img/filetypes/audio.png';
  57. if(!file_exists($icon)) {
  58. return false;
  59. }
  60. $image = new \OC_Image();
  61. $image->loadFromFile($icon);
  62. return $image->valid() ? $image : false;
  63. }
  64. }