summaryrefslogtreecommitdiffstats
path: root/apps/media/js/scanner.js
blob: 0baa9db419a14acf451d4b6ec211e063cc7a147d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
Scanner={
	songsFound:0,
	eventSource:null,
	songsScanned:0,
	findSongs:function(ready){
		$.getJSON(OC.linkTo('media','ajax/api.php')+'?action=find_music',function(songs){
			Scanner.songsFound=songs.length;
			if(ready){
				ready(songs)
			}
		});
	},
	scanCollection:function(ready){
		$('#scanprogressbar').progressbar({
			value:0,
		});
		$('#scanprogressbar').show();
		Scanner.songsScanned=0;
		Scanner.eventSource=new OC.EventSource(OC.linkTo('media','ajax/api.php'),{action:'scan'});
		Scanner.eventSource.listen('count',function(total){
			Scanner.songsFound=total;
		});
		Scanner.eventSource.listen('scanned',function(data){
			Scanner.songsScanned=data.count;
			$('#scan span.songCount').text(Scanner.songsScanned);
			var progress=(Scanner.songsScanned/Scanner.songsFound)*100;
			$('#scanprogressbar').progressbar('value',progress)
		});
		Scanner.eventSource.listen('done',function(count){
			$('#scan input.start').show();
			$('#scan input.stop').hide();
			$('#scanprogressbar').hide();
			Collection.load(Collection.display)
			if(ready){
				ready();
			}
		});
		$('#scancount').show();
	},
	stop:function(){
		Scanner.close();
	},

}