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();
},
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);
},
* @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)) {
}else{
$songs=0;
}
-// OC_DB::commit();
return $songs;
}
$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;
}
}
\ No newline at end of file