tomahawk.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /**
  3. * ownCloud - media plugin
  4. *
  5. * @author Robin Appelman
  6. * @copyright 2010 Robin Appelman icewind1991@gmail.com
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  10. * License as published by the Free Software Foundation; either
  11. * version 3 of the License, or any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. $_POST=$_GET; //debug
  23. OCP\JSON::checkAppEnabled('media');
  24. require_once(OC::$APPSROOT . '/apps/media/lib_collection.php');
  25. $user=isset($_POST['user'])?$_POST['user']:'';
  26. $pass=isset($_POST['pass'])?$_POST['pass']:'';
  27. if(OCP\User::checkPassword($user,$pass)){
  28. OC_Util::setupFS($user);
  29. OC_MEDIA_COLLECTION::$uid=$user;
  30. }else{
  31. exit;
  32. }
  33. if(isset($_POST['play']) and $_POST['play']=='true'){
  34. if(!isset($_POST['song'])){
  35. exit;
  36. }
  37. $song=OC_MEDIA_COLLECTION::getSong($_POST['song']);
  38. $ftype=OC_Filesystem::getMimeType( $song['song_path'] );
  39. header('Content-Type:'.$ftype);
  40. OCP\Response::disableCaching();
  41. header('Content-Length: '.OC_Filesystem::filesize($song['song_path']));
  42. OC_Filesystem::readfile($song['song_path']);
  43. }
  44. $artist=isset($_POST['artist'])?'%'.$_POST['artist'].'%':'';
  45. $album=isset($_POST['album'])?'%'.$_POST['album'].'%':'';
  46. $song=isset($_POST['song'])?$_POST['song']:'';
  47. $artist=OC_MEDIA_COLLECTION::getArtistId($artist);
  48. $album=OC_MEDIA_COLLECTION::getAlbumId($album,$artist);
  49. $songs=OC_MEDIA_COLLECTION::getSongs($artist,$album,$song);
  50. $baseUrl=$baseuri;
  51. $results=array();
  52. foreach($songs as $song) {
  53. $results[] = (Object) array(
  54. 'artist' => OC_MEDIA_COLLECTION::getArtistName($song['song_artist']),
  55. 'album' => OC_MEDIA_COLLECTION::getAlbumName($song['song_album']),
  56. 'track' => $song['song_name'],
  57. 'source' => 'ownCloud',
  58. 'mimetype' => OC_Filesystem::getMimeType($song['song_path']),
  59. 'extension' => substr($song['song_path'],strrpos($song['song_path'],'.')),
  60. 'url' => $baseUrl.'?play=true&song='.$song['song_id'],
  61. 'bitrate' => round($song['song_id']/$song['song_length'],0),
  62. 'duration' => round($song['song_length'],0),
  63. 'size' => $song['song_size'],
  64. 'score' => (float)1.0
  65. );
  66. }
  67. OCP\JSON::encodedPrint($results);