2011-08-02 01:53:01 +04:00
|
|
|
Scanner={
|
|
|
|
songsFound:0,
|
|
|
|
songsScanned:0,
|
2011-08-02 06:43:08 +04:00
|
|
|
songsChecked:0,
|
2011-08-02 01:53:01 +04:00
|
|
|
startTime:null,
|
|
|
|
endTime:null,
|
|
|
|
stopScanning:false,
|
2012-01-20 04:41:37 +04:00
|
|
|
currentIndex:0,
|
2011-08-02 01:53:01 +04:00
|
|
|
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){
|
2012-01-20 04:41:37 +04:00
|
|
|
|
2011-08-02 01:53:01 +04:00
|
|
|
ready(songs)
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
scanFile:function(path,ready){
|
|
|
|
path=encodeURIComponent(path);
|
|
|
|
$.getJSON(OC.linkTo('media','ajax/api.php')+'?action=get_path_info&path='+path,function(song){
|
2011-08-02 06:43:08 +04:00
|
|
|
Scanner.songsChecked++;
|
2011-08-02 01:53:01 +04:00
|
|
|
if(ready){
|
|
|
|
ready(song);
|
|
|
|
}
|
|
|
|
if(song){//do this after the ready call so we dont hold up the next ajax call
|
|
|
|
var artistId=song.song_artist;
|
|
|
|
Scanner.songsScanned++;
|
|
|
|
$('#scan span.songCount').text(Scanner.songsScanned);
|
2011-08-02 06:43:08 +04:00
|
|
|
var progress=(Scanner.songsChecked/Scanner.songsFound)*100;
|
2011-08-02 01:53:01 +04:00
|
|
|
$('#scanprogressbar').progressbar('value',progress)
|
|
|
|
Collection.addSong(song);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
scanCollection:function(ready){
|
|
|
|
$('#scanprogressbar').progressbar({
|
|
|
|
value:0,
|
|
|
|
});
|
2012-01-20 04:41:37 +04:00
|
|
|
$('#scanprogressbar').show();
|
2011-08-02 06:43:08 +04:00
|
|
|
Scanner.songsChecked=0;
|
2012-01-20 04:41:37 +04:00
|
|
|
Scanner.currentIndex=0;
|
2011-08-02 06:43:08 +04:00
|
|
|
Scanner.songsScanned=0;
|
2011-08-02 01:53:01 +04:00
|
|
|
Scanner.startTime=new Date().getTime()/1000;
|
|
|
|
Scanner.findSongs(function(songs){
|
|
|
|
Scanner.songs=songs;
|
2012-01-20 04:41:37 +04:00
|
|
|
Scanner.start(function(){
|
|
|
|
$('#scan input.start').show();
|
|
|
|
$('#scan input.stop').hide();
|
|
|
|
$('#scanprogressbar').hide();
|
|
|
|
Collection.display();
|
|
|
|
if(ready){
|
|
|
|
ready();
|
|
|
|
}
|
|
|
|
});
|
2011-08-02 01:53:01 +04:00
|
|
|
});
|
|
|
|
},
|
|
|
|
stop:function(){
|
|
|
|
Scanner.stopScanning=true;
|
|
|
|
},
|
|
|
|
start:function(ready){
|
|
|
|
Scanner.stopScanning=false;
|
2011-08-04 03:26:29 +04:00
|
|
|
$('#scancount').show();
|
2011-08-02 01:53:01 +04:00
|
|
|
var scanSong=function(){
|
2012-01-20 04:41:37 +04:00
|
|
|
if(!Scanner.stopScanning && Scanner.currentIndex<=Scanner.songs.length){
|
2011-08-02 01:53:01 +04:00
|
|
|
Scanner.scanFile(Scanner.songs[Scanner.currentIndex],scanSong)
|
2012-01-20 04:41:37 +04:00
|
|
|
}else if(!Scanner.stopScanning){
|
2011-08-02 01:53:01 +04:00
|
|
|
Scanner.endTime=new Date().getTime()/1000;
|
|
|
|
if(ready){
|
|
|
|
ready();
|
2012-01-20 04:41:37 +04:00
|
|
|
ready=null;//only call ready once
|
2011-08-02 01:53:01 +04:00
|
|
|
}
|
|
|
|
}
|
2012-01-20 04:41:37 +04:00
|
|
|
Scanner.currentIndex++;
|
2011-08-02 01:53:01 +04:00
|
|
|
}
|
|
|
|
scanSong();
|
2011-08-04 03:26:29 +04:00
|
|
|
scanSong();
|
2011-08-02 01:53:01 +04:00
|
|
|
},
|
|
|
|
toggle:function(){
|
|
|
|
if(Scanner.stopScanning){
|
|
|
|
Scanner.start();
|
2011-08-09 19:54:02 +04:00
|
|
|
$('#scan input.stop').val(t('media','Pause'));
|
2011-08-02 01:53:01 +04:00
|
|
|
}else{
|
|
|
|
Scanner.stop();
|
2011-08-09 19:54:02 +04:00
|
|
|
$('#scan input.stop').val(t('media','Resume'));
|
2011-08-02 01:53:01 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|