]> source.dussan.org Git - nextcloud-server.git/commitdiff
automatically scan songs that are played from the filebrowser
authorRobin Appelman <icewind1991@gmail.com>
Sun, 31 Jul 2011 22:32:44 +0000 (00:32 +0200)
committerRobin Appelman <icewind1991@gmail.com>
Sun, 31 Jul 2011 22:32:44 +0000 (00:32 +0200)
apps/media/ajax/api.php
apps/media/js/player.js
apps/media/lib_scanner.php

index b8883166732c844bd8258360d85f25c0348bc33f..e0183ff05de8f7cab45c210699c8e3d5c647f132 100644 (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();
                        
index ebb8044598c21b6c2f1ce063a0c47552bb619e84..1243f20b8ed5d972bc7d0eee580fe9e2c635b67f 100644 (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);
        },
index 4d0b38f820ac7f47ec831a6045a3b6b103b2d209..ab38d76294b094c97566614c2967f3b1430f664c 100644 (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;
        }
 }
\ No newline at end of file