2011-07-22 04:30:52 +00: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/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
header('Content-type: text/html; charset=UTF-8') ;
|
|
|
|
|
2012-05-03 10:23:29 +00:00
|
|
|
OCP\JSON::checkAppEnabled('media');
|
2012-04-23 18:01:48 +00:00
|
|
|
require_once(OC::$APPSROOT . '/apps/media/lib_collection.php');
|
|
|
|
require_once(OC::$APPSROOT . '/apps/media/lib_scanner.php');
|
2011-07-22 04:30:52 +00:00
|
|
|
|
|
|
|
error_reporting(E_ALL); //no script error reporting because of getID3
|
|
|
|
|
|
|
|
$arguments=$_POST;
|
2011-07-22 17:37:00 +00:00
|
|
|
|
2011-07-22 04:30:52 +00:00
|
|
|
if(!isset($_POST['action']) and isset($_GET['action'])){
|
|
|
|
$arguments=$_GET;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach($arguments as &$argument){
|
|
|
|
$argument=stripslashes($argument);
|
|
|
|
}
|
2011-07-22 17:37:00 +00:00
|
|
|
@ob_clean();
|
2011-07-22 04:30:52 +00:00
|
|
|
if(!isset($arguments['artist'])){
|
|
|
|
$arguments['artist']=0;
|
|
|
|
}
|
|
|
|
if(!isset($arguments['album'])){
|
|
|
|
$arguments['album']=0;
|
|
|
|
}
|
|
|
|
if(!isset($arguments['search'])){
|
|
|
|
$arguments['search']='';
|
|
|
|
}
|
2012-05-01 16:50:31 +00:00
|
|
|
OC_MEDIA_COLLECTION::$uid=OCP\USER::getUser();
|
2011-07-22 04:30:52 +00:00
|
|
|
if($arguments['action']){
|
|
|
|
switch($arguments['action']){
|
|
|
|
case 'delete':
|
|
|
|
$path=$arguments['path'];
|
|
|
|
OC_MEDIA_COLLECTION::deleteSongByPath($path);
|
2012-05-02 13:54:34 +00:00
|
|
|
$paths=explode(PATH_SEPARATOR,OCP\Config::getUserValue(OCP\USER::getUser(),'media','paths',''));
|
2011-07-22 04:30:52 +00:00
|
|
|
if(array_search($path,$paths)!==false){
|
|
|
|
unset($paths[array_search($path,$paths)]);
|
2012-05-02 13:54:34 +00:00
|
|
|
OCP\Config::setUserValue(OCP\USER::getUser(),'media','paths',implode(PATH_SEPARATOR,$paths));
|
2011-07-22 04:30:52 +00:00
|
|
|
}
|
|
|
|
case 'get_collection':
|
2011-08-21 13:28:20 +00:00
|
|
|
$data=array();
|
|
|
|
$data['artists']=OC_MEDIA_COLLECTION::getArtists();
|
|
|
|
$data['albums']=OC_MEDIA_COLLECTION::getAlbums();
|
|
|
|
$data['songs']=OC_MEDIA_COLLECTION::getSongs();
|
2012-05-03 10:23:29 +00:00
|
|
|
OCP\JSON::encodedPrint($data);
|
2011-07-22 04:30:52 +00:00
|
|
|
break;
|
|
|
|
case 'scan':
|
2012-05-03 11:06:08 +00:00
|
|
|
OCP\DB::beginTransaction();
|
2011-07-22 04:30:52 +00:00
|
|
|
set_time_limit(0); //recursive scan can take a while
|
2012-02-08 16:30:16 +00:00
|
|
|
$eventSource=new OC_EventSource();
|
|
|
|
OC_MEDIA_SCANNER::scanCollection($eventSource);
|
|
|
|
$eventSource->close();
|
2012-05-03 11:06:08 +00:00
|
|
|
OCP\DB::commit();
|
2011-07-22 04:30:52 +00:00
|
|
|
break;
|
|
|
|
case 'scanFile':
|
|
|
|
echo (OC_MEDIA_SCANNER::scanFile($arguments['path']))?'true':'false';
|
|
|
|
break;
|
|
|
|
case 'get_artists':
|
2012-05-03 10:23:29 +00:00
|
|
|
OCP\JSON::encodedPrint(OC_MEDIA_COLLECTION::getArtists($arguments['search']));
|
2011-07-22 04:30:52 +00:00
|
|
|
break;
|
|
|
|
case 'get_albums':
|
2012-05-03 10:23:29 +00:00
|
|
|
OCP\JSON::encodedPrint(OC_MEDIA_COLLECTION::getAlbums($arguments['artist'],$arguments['search']));
|
2011-07-22 04:30:52 +00:00
|
|
|
break;
|
|
|
|
case 'get_songs':
|
2012-05-03 10:23:29 +00:00
|
|
|
OCP\JSON::encodedPrint(OC_MEDIA_COLLECTION::getSongs($arguments['artist'],$arguments['album'],$arguments['search']));
|
2011-07-22 04:30:52 +00:00
|
|
|
break;
|
2011-07-31 22:32:44 +00:00
|
|
|
case 'get_path_info':
|
2011-08-01 21:53:01 +00:00
|
|
|
if(OC_Filesystem::file_exists($arguments['path'])){
|
|
|
|
$songId=OC_MEDIA_COLLECTION::getSongByPath($arguments['path']);
|
|
|
|
if($songId==0){
|
|
|
|
unset($_SESSION['collection']);
|
|
|
|
$songId= OC_MEDIA_SCANNER::scanFile($arguments['path']);
|
|
|
|
}
|
|
|
|
if($songId>0){
|
|
|
|
$song=OC_MEDIA_COLLECTION::getSong($songId);
|
|
|
|
$song['artist']=OC_MEDIA_COLLECTION::getArtistName($song['song_artist']);
|
|
|
|
$song['album']=OC_MEDIA_COLLECTION::getAlbumName($song['song_album']);
|
2012-05-03 10:23:29 +00:00
|
|
|
OCP\JSON::encodedPrint($song);
|
2011-08-01 21:53:01 +00:00
|
|
|
}
|
2011-07-31 22:32:44 +00:00
|
|
|
}
|
|
|
|
break;
|
2011-07-22 04:30:52 +00:00
|
|
|
case 'play':
|
2011-10-16 22:24:07 +00:00
|
|
|
@ob_end_clean();
|
2011-07-22 04:30:52 +00:00
|
|
|
|
2011-07-29 19:36:03 +00:00
|
|
|
$ftype=OC_Filesystem::getMimeType( $arguments['path'] );
|
2011-07-22 04:30:52 +00:00
|
|
|
|
2011-07-28 18:59:36 +00:00
|
|
|
$songId=OC_MEDIA_COLLECTION::getSongByPath($arguments['path']);
|
|
|
|
OC_MEDIA_COLLECTION::registerPlay($songId);
|
|
|
|
|
2011-07-22 04:30:52 +00:00
|
|
|
header('Content-Type:'.$ftype);
|
2012-05-03 08:46:27 +00:00
|
|
|
OCP\Response::enableCaching(3600 * 24); // 24 hour
|
2011-08-01 14:43:02 +00:00
|
|
|
header('Accept-Ranges: bytes');
|
2011-07-29 19:36:03 +00:00
|
|
|
header('Content-Length: '.OC_Filesystem::filesize($arguments['path']));
|
2012-02-13 22:48:05 +00:00
|
|
|
$mtime = OC_Filesystem::filemtime($arguments['path']);
|
2012-05-03 08:46:27 +00:00
|
|
|
OCP\Response::setLastModifiedHeader($mtime);
|
2011-07-22 04:30:52 +00:00
|
|
|
|
2011-07-29 19:36:03 +00:00
|
|
|
OC_Filesystem::readfile($arguments['path']);
|
2011-07-22 04:30:52 +00:00
|
|
|
exit;
|
2011-08-01 21:53:01 +00:00
|
|
|
case 'find_music':
|
2012-02-26 02:42:15 +00:00
|
|
|
$music=OC_FileCache::searchByMime('audio');
|
|
|
|
$ogg=OC_FileCache::searchByMime('application','ogg');
|
|
|
|
$music=array_merge($music,$ogg);
|
2012-05-03 10:23:29 +00:00
|
|
|
OCP\JSON::encodedPrint($music);
|
2011-08-01 21:53:01 +00:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
}
|
2012-04-23 18:01:48 +00:00
|
|
|
?>
|