diff options
author | Robin Appelman <icewind1991@gmail.com> | 2011-08-01 00:32:44 +0200 |
---|---|---|
committer | Robin Appelman <icewind1991@gmail.com> | 2011-08-01 00:32:44 +0200 |
commit | cbf8f822de35748e079df695dd322ada32d02f69 (patch) | |
tree | 5b29d072cc692e340f300dbd17d2aa81bd700193 /apps/media | |
parent | f88b47745911f06a844fbc3f35a347c679f0339c (diff) | |
download | nextcloud-server-cbf8f822de35748e079df695dd322ada32d02f69.tar.gz nextcloud-server-cbf8f822de35748e079df695dd322ada32d02f69.zip |
automatically scan songs that are played from the filebrowser
Diffstat (limited to 'apps/media')
-rw-r--r-- | apps/media/ajax/api.php | 13 | ||||
-rw-r--r-- | apps/media/js/player.js | 7 | ||||
-rw-r--r-- | apps/media/lib_scanner.php | 4 |
3 files changed, 20 insertions, 4 deletions
diff --git a/apps/media/ajax/api.php b/apps/media/ajax/api.php index b8883166732..e0183ff05de 100644 --- a/apps/media/ajax/api.php +++ b/apps/media/ajax/api.php @@ -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(); diff --git a/apps/media/js/player.js b/apps/media/js/player.js index ebb8044598c..1243f20b8ed 100644 --- a/apps/media/js/player.js +++ b/apps/media/js/player.js @@ -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); }, diff --git a/apps/media/lib_scanner.php b/apps/media/lib_scanner.php index 4d0b38f820a..ab38d76294b 100644 --- a/apps/media/lib_scanner.php +++ b/apps/media/lib_scanner.php @@ -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; } }
\ No newline at end of file |