Esempio n. 1
0
 spotify.getStatus(function(err, status) {
   if (err) {
      console.log(err);
      return;
   }
   if (status.running) {
     const diff = status.server_time - remote.time;
     const syncTime = remote.position + diff;
     if (status.track && status.track.track_resource && status.track.track_resource.uri !== remote.uri) {
       if (remote.playing) {
         spotify.play(remote.uri + '#' + parseTime(syncTime), function(err, res) {
           if (err) {
             console.log('play', err);
             return;
           }
           console.log('play', res);
         })
       } else {
         spotify.pause(function(err, res) {
           if (err) {
             console.log('pause', err);
             return;
           }
           console.log('pause', res);
         })
       }
     } else if (syncTime < remote.duration) {
       if (remote.playing) {
         if (Math.abs(syncTime - status.playing_position) > 6) {
           spotify.play(remote.uri + '#' + parseTime(syncTime), function(err, res) {
             if (err) {
               console.log('jump', err);
               return;
             }
             console.log('jump', res);
           })
         }
       } else {
         spotify.pause(function(err, res) {
           if (err) {
             console.log('pause', err);
             return;
           }
           console.log('pause', res);
         })
       }
     }
   } else {
     event.sender.send('local-status-error', status);
   }
 });
Esempio n. 2
0
 ipcMain.on('getLocalSpotifyStatus', function(event, rid) {
   spotify.getStatus(function(err, status) {
     if (err) {
       console.log(err);
       return;
     }
     if (status.running) {
       var parseJSON = {};
       parseJSON.playing = status.playing ? true : false;
       parseJSON.position = status.playing_position ? Math.floor(status.playing_position) : 0;
       parseJSON.duration = status.track ? status.track.length : 0;
       parseJSON.uri = status.track ? status.track.track_resource ? status.track.track_resource.uri : "" : "";
       parseJSON.time = status.server_time ? status.server_time : 0;
       event.sender.send('local-status-running', parseJSON, rid);
     } else {
       event.sender.send('local-status-error', status);
     }
     console.log('status', status);
   });
 });
Esempio n. 3
0
var nodeSpotifyWebHelper = require('node-spotify-webhelper');
var spotify = new nodeSpotifyWebHelper.SpotifyWebHelper({port: '4371'});

// get the name of the song which is currently playing
spotify.getStatus(function (err, res) {
  if (err) {
    return console.error(err);
  }

  var song = res.track.artist_resource.name + ' - ' + res.track.track_resource.name;
  console.log(song.substring(0, 32));
});