scanner.js 1.1 KB

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