automatically scan songs that are played from the filebrowser

This commit is contained in:
Robin Appelman 2011-08-01 00:32:44 +02:00
parent f88b477459
commit cbf8f822de
3 changed files with 20 additions and 4 deletions

View File

@ -107,6 +107,19 @@ if($arguments['action']){
case 'get_songs':
echo json_encode(OC_MEDIA_COLLECTION::getSongs($arguments['artist'],$arguments['album'],$arguments['search']));
break;
case 'get_path_info':
$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']);
echo json_encode($song);
}
break;
case 'play':
ob_end_clean();

View File

@ -96,7 +96,12 @@ var PlayList={
},
addFile:function(path){
var type=musicTypeFromFile(path);
var item={name:'unknown',artist:'unknown',album:'unknwon',type:type};//todo get song data
var item={name:'unknown',artist:'unknown',album:'unknwon',type:type};
$.getJSON(OC.filePath('media','ajax','api.php')+'?action=get_path_info&path='+encodeURIComponent(path),function(song){
item.name=song.song_name;
item.artist=song.artist;
item.album=song.album;
});
item[type]=PlayList.urlBase+encodeURIComponent(path);
PlayList.items.push(item);
},

View File

@ -38,7 +38,6 @@ class OC_MEDIA_SCANNER{
* @return int the number of songs found
*/
public static function scanFolder($path){
// OC_DB::beginTransaction();
if (OC_Filesystem::is_dir($path)) {
$songs=0;
if ($dh = OC_Filesystem::opendir($path)) {
@ -62,7 +61,6 @@ class OC_MEDIA_SCANNER{
}else{
$songs=0;
}
// OC_DB::commit();
return $songs;
}
@ -141,6 +139,6 @@ class OC_MEDIA_SCANNER{
$albumId=self::$albums[$artist.'/'.$album];
}
$songId=OC_MEDIA_COLLECTION::addSong($title,$path,$artistId,$albumId,$length,$track,$size);
return !($title=='unkown' && $artist=='unkown' && $album=='unkown');
return (!($title=='unkown' && $artist=='unkown' && $album=='unkown'))?$songId:0;
}
}