Giter Club home page Giter Club logo

spotify-port-scanner-node's Introduction

spotify-port-scanner-node

This node module will connect to Spotify desktop application using the spotilocal protocol with automatic port detection of the host. This module uses the node module node-spotify-webhelper to communicate to the host application.

How to install

To install this module via npm type

npm install -s spotify-port-scanner

To install from sources

git clone https://github.com/loretoparisi/spotify-port-scanner-node.git
cd spotify-port scanner/
npm install

Usage

See examples in examples/ folder for more examples.

Connect the client to the host Spotify application while debugging.

var SpotifySDK = require('spotify-port-scanner-node');
var client = new SpotifySDK.SpotifyClient({ debug : true });
client.connect({
  lowPort : 3000,
  highPort : 5000
})
.then(() => {
  console.log("client connected to host %s:%s", client.getHost(), client.getPort());
})
  .catch(error => {
  console.log("client error", error);  
});

As soon as the client is connected, to get the host application instance and query for the status:

  // get host status
  // get spotify application host
  var host=client.getSpotifyHost();
  host.getStatus(function (error, status) {
    if (error) {
      console.log("host error", err);
    }
    else {
        console.info("host status:", status);
    }
  });

The host protocol

This is an example of host application protocol.

The response status contains the following fields

{
    "version": 9,
    "client_version": "1.0.36.124.g1cba1920",
    "playing": true,
    "shuffle": false,
    "repeat": false,
    "play_enabled": true,
    "prev_enabled": false,
    "next_enabled": true,
    "track": {
        "track_resource": {
            "name": "Blood Host",
            "uri": "spotify:track:2Y4V0ULxOW5ETI2JhnWFlb",
            "location": {
                "og": "https://open.spotify.com/track/2Y4V0ULxOW5ETI2JhnWFlb"
            }
        },
        "artist_resource": {
            "name": "Scar The Martyr",
            "uri": "spotify:artist:1gz9Dd0N7oCymbjVePlxbq",
            "location": {
                "og": "https://open.spotify.com/artist/1gz9Dd0N7oCymbjVePlxbq"
            }
        },
        "album_resource": {
            "name": "Scar The Martyr (Deluxe)",
            "uri": "spotify:album:0ab4DBE7MXSImsTvIegnHI",
            "location": {
                "og": "https://open.spotify.com/album/0ab4DBE7MXSImsTvIegnHI"
            }
        },
        "length": 407,
        "track_type": "normal"
    },
    "context": {},
    "playing_position": 49.558,
    "server_time": 1473682947,
    "volume": 1,
    "online": true,
    "open_graph_state": {
        "private_session": false,
        "posting_disabled": false
    },
    "running": true
}

spotify-port-scanner-node's People

Contributors

loretoparisi avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Forkers

comfortme

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.