Subversion Repositories HomeAutomation

Rev

Blame | Last modification | View Log | SVN | RSS feed

  1.  
  2. function Spotify(callback)
  3. {
  4.     this.myCallback = callback;
  5.    
  6.     if (this.myInterval == null)
  7.     {
  8.         var self = this;
  9.    
  10.         this.myInterval = new Interval(function() { self.timerUpdate() }, 10000);
  11.     }
  12.    
  13.     this.myInterval.start();
  14. }
  15.  
  16. Spotify.prototype.myArtist = null;
  17. Spotify.prototype.myTrack = null;
  18. Spotify.prototype.myCallback = null;
  19. Spotify.prototype.myInterval = null;
  20.  
  21. Spotify.prototype.playpause = function()
  22. {
  23.     var output = system("spotify_cmd.exe playpause");
  24.     this.timerUpdate()
  25. }
  26.  
  27. Spotify.prototype.next = function()
  28. {
  29.     var output = system("spotify_cmd.exe next");
  30.     this.timerUpdate()
  31. }
  32.  
  33. Spotify.prototype.previous = function()
  34. {
  35.     var output = system("spotify_cmd.exe prev");
  36.     this.timerUpdate()
  37. }
  38.  
  39. Spotify.prototype.stop = function()
  40. {
  41.     var output = system("spotify_cmd.exe stop");
  42.     this.timerUpdate()
  43. }
  44.  
  45. Spotify.prototype.getStatus = function()
  46. {
  47.     if (this.myArtist != null)
  48.     {
  49.         return { "status" : "playing", "artist" : this.myArtist, "track" : this.myTrack };
  50.     }
  51.    
  52.     return { "status" : "paused" };
  53. }
  54.  
  55. Spotify.prototype.timerUpdate = function()
  56. {
  57.     var output = system("spotify_cmd.exe status");
  58.    
  59.     var lines = output.split("\n");
  60.    
  61.     var artist = null;
  62.     var track = null;
  63.    
  64.     if (lines[0] == "OK")
  65.     {
  66.         artist = lines[1];
  67.         track = lines[2];
  68.     }
  69.    
  70.     if (artist != this.myArtist && track != this.myTrack)
  71.     {
  72.         this.myArtist = artist;
  73.         this.myTrack = track;
  74.        
  75.         this.myCallback();
  76.     }
  77. }
  78.  
  79.