Collection.loadedListeners[i]();
}
if(data.songs.length==0){
- $('#scan input.start').val(t('media','Scan Collection'));
$('#scan input.start').click();
}
}
},
addSong:function(song){
- var artist=false
- var album=false;
- for(var i=0;i<Collection.artists.length;i++){
- if(Collection.artists[i].artist_id==song.song_artist){
- artist=Collection.artists[i];
- for(var j=0;j<artist.albums.length;j++){
- if(artist.albums[j].album_id==song.song_album){
- album=artist.albums[j];
- break;
- }
- }
- break;
- }
- }
+ var artist=Collection.findArtist(song.artist);
if(!artist){
- artist={artist_id:song.song_artist,artist_name:song.artist,albums:[]};
+ artist={name:song.artist,albums:[],songs:[]};
Collection.artists.push(artist);
- if(!Collection.parent || Collection.parent.is(":visible")){
- Collection.display();
- }
-
+ Collection.artistsById[song.song_artist]=artist;
}
+ var album=Collection.findAlbum(song.artist,song.album);
if(!album){
- album={album_id:song.song_album,album_name:song.album,album_artist:song.song_artist,songs:[]};
- artist.albums.push(album)
+ album={name:song.album,artist:song.song_artist,songs:[]};
+ artist.albums.push(album);
+ Collection.albums.push(album);
+ Collection.albumsById[song.song_album]=album;
}
- album.songs.push(song)
+ var songData={
+ name:song.song_name,
+ artist:Collection.artistsById[song.song_artist].name,
+ album:Collection.albumsById[song.song_album].name,
+ lastPlayed:song.song_lastplayed,
+ length:song.song_length,
+ path:song.song_path,
+ playCount:song.song_playcount,
+ };
+ album.songs.push(songData)
+ artist.songs.push(songData);
+ Collection.songs.push(songData);
}
}
startTime:null,
endTime:null,
stopScanning:false,
- currentIndex:-1,
+ currentIndex:0,
songs:[],
findSongs:function(ready){
$.getJSON(OC.linkTo('media','ajax/api.php')+'?action=find_music',function(songs){
Scanner.songsFound=songs.length;
Scanner.currentIndex=-1
if(ready){
+
ready(songs)
}
});
$('#scanprogressbar').progressbar({
value:0,
});
+ $('#scanprogressbar').show();
Scanner.songsChecked=0;
+ Scanner.currentIndex=0;
Scanner.songsScanned=0;
Scanner.startTime=new Date().getTime()/1000;
Scanner.findSongs(function(songs){
Scanner.songs=songs;
- Scanner.start();
+ Scanner.start(function(){
+ $('#scan input.start').show();
+ $('#scan input.stop').hide();
+ $('#scanprogressbar').hide();
+ Collection.display();
+ if(ready){
+ ready();
+ }
+ });
});
},
stop:function(){
Scanner.stopScanning=false;
$('#scancount').show();
var scanSong=function(){
- Scanner.currentIndex++;
- if(!Scanner.stopScanning && Scanner.currentIndex<Scanner.songs.length){
+ if(!Scanner.stopScanning && Scanner.currentIndex<=Scanner.songs.length){
Scanner.scanFile(Scanner.songs[Scanner.currentIndex],scanSong)
- }else{
+ }else if(!Scanner.stopScanning){
Scanner.endTime=new Date().getTime()/1000;
if(ready){
ready();
+ ready=null;//only call ready once
}
}
+ Scanner.currentIndex++;
}
scanSong();
scanSong();