2011-07-22 08:30:52 +04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ownCloud - media plugin
|
|
|
|
*
|
|
|
|
* @author Robin Appelman
|
|
|
|
* @copyright 2010 Robin Appelman icewind1991@gmail.com
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 3 of the License, or any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
$_POST=$_GET; //debug
|
2012-04-27 00:00:37 +04:00
|
|
|
require_once('../inc.php');
|
2012-04-17 21:31:29 +04:00
|
|
|
|
2011-10-01 01:05:10 +04:00
|
|
|
OC_JSON::checkAppEnabled('media');
|
2012-04-27 00:00:37 +04:00
|
|
|
require_once(OC::$APPSROOT . '/apps/media/lib_collection.php');
|
2011-07-22 08:30:52 +04:00
|
|
|
|
|
|
|
$user=isset($_POST['user'])?$_POST['user']:'';
|
|
|
|
$pass=isset($_POST['pass'])?$_POST['pass']:'';
|
2012-05-01 21:04:20 +04:00
|
|
|
if(OCP\User::checkPassword($user,$pass)){
|
2011-07-29 23:36:03 +04:00
|
|
|
OC_Util::setupFS($user);
|
2011-07-22 08:30:52 +04:00
|
|
|
OC_MEDIA_COLLECTION::$uid=$user;
|
|
|
|
}else{
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(isset($_POST['play']) and $_POST['play']=='true'){
|
|
|
|
if(!isset($_POST['song'])){
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
$song=OC_MEDIA_COLLECTION::getSong($_POST['song']);
|
2011-07-29 23:36:03 +04:00
|
|
|
$ftype=OC_Filesystem::getMimeType( $song['song_path'] );
|
2011-07-22 08:30:52 +04:00
|
|
|
header('Content-Type:'.$ftype);
|
2012-02-14 02:48:05 +04:00
|
|
|
OC_Response::disableCaching();
|
2011-07-29 23:36:03 +04:00
|
|
|
header('Content-Length: '.OC_Filesystem::filesize($song['song_path']));
|
2011-07-22 08:30:52 +04:00
|
|
|
|
2011-07-29 23:36:03 +04:00
|
|
|
OC_Filesystem::readfile($song['song_path']);
|
2011-07-22 08:30:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
$artist=isset($_POST['artist'])?'%'.$_POST['artist'].'%':'';
|
|
|
|
$album=isset($_POST['album'])?'%'.$_POST['album'].'%':'';
|
|
|
|
$song=isset($_POST['song'])?$_POST['song']:'';
|
|
|
|
|
|
|
|
$artist=OC_MEDIA_COLLECTION::getArtistId($artist);
|
|
|
|
$album=OC_MEDIA_COLLECTION::getAlbumId($album,$artist);
|
|
|
|
|
|
|
|
$songs=OC_MEDIA_COLLECTION::getSongs($artist,$album,$song);
|
|
|
|
|
2012-05-02 01:19:39 +04:00
|
|
|
$baseUrl=OC_Util::getServerURL().OCP\Util::linkTo('media','tomahawk.php');
|
2011-07-22 08:30:52 +04:00
|
|
|
|
|
|
|
$results=array();
|
|
|
|
foreach($songs as $song) {
|
|
|
|
$results[] = (Object) array(
|
|
|
|
'artist' => OC_MEDIA_COLLECTION::getArtistName($song['song_artist']),
|
|
|
|
'album' => OC_MEDIA_COLLECTION::getAlbumName($song['song_album']),
|
|
|
|
'track' => $song['song_name'],
|
|
|
|
'source' => 'ownCloud',
|
2011-07-29 23:36:03 +04:00
|
|
|
'mimetype' => OC_Filesystem::getMimeType($song['song_path']),
|
2011-07-22 08:30:52 +04:00
|
|
|
'extension' => substr($song['song_path'],strrpos($song['song_path'],'.')),
|
|
|
|
'url' => $baseUrl.'?play=true&song='.$song['song_id'],
|
|
|
|
'bitrate' => round($song['song_id']/$song['song_length'],0),
|
|
|
|
'duration' => round($song['song_length'],0),
|
|
|
|
'size' => $song['song_size'],
|
|
|
|
'score' => (float)1.0
|
|
|
|
);
|
|
|
|
}
|
2011-09-24 00:22:59 +04:00
|
|
|
OC_JSON::encodedPrint($results);
|
|
|
|
?>
|