npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-spotify-webhelper-portscanner

v1.0.3

Published

Node.js interface for the local Spotify WebHelper API plus a Port Scanner

Downloads

8

Readme

node-spotify-webhelper-portscanner

This package is a fork and a extension of the Node Spotify Web Helper module: https://github.com/nadavbar/node-spotify-webhelper It keeps the same interface as described in the docs below and extend it to use a port scanner to detect Spotify open ports that supports Spotify local protocol.

Node.js interface for the Spotify WebHelper API, based on this great article: http://cgbystrom.com/articles/deconstructing-spotifys-builtin-http-server/

The API interacts with the SpotifyWebHelper process via HTTP. For windows, the module checks whether SpotifyWebHelper.exe is running, and try to run it if not.

API:

This module exposes the SpotifyWebHelper object, which exposes the following methods:

  • getStatus (cb : function(err, res)) - get current status information (name of song/artist which is currently playing, etc..)
  • pause (cb : function(err, res)) - pause currently playing song
  • unpause (cb : function(err, res)) - unpause currently playing song
  • play (spotifyurl : string, cb : function(err, res)) - play the given spotify url
  • Constructor (port : number (optional)) - Creates a new SpotifyWebHelper object, default port to communicate with the SpotifyWebHelper is 4370, other port can be specified when creating the object.

Examples - Get Status

var SpotifyWebHelper = require('node-spotify-webhelper');
var spotify = new SpotifyWebHelper();

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

  console.info('currently playing:',
    res.track.artist_resource.name, '-',  
    res.track.track_resource.name);
});

Examples - Port detection The following example will detect open ports for Spotify desktop applications. To detect open ports a forked and modified port scanner node module has been used: https://github.com/baalexander/node-portscanner

Each of those ports respond to the Spotify local protocol and can be used to communicate to Spotify desktop application on the same host.

var SpotifyWebHelper = require('node-spotify-webhelper-portscanner');
var spotifyClient = new SpotifyWebHelper(); // init with default port
spotifyClient.scanPorts({
  lowPort : 3000,
  highPort : 5000,
  timeout : 300
}
, function(error, ports) {
    if(!error)
      return console.log( ports );
    else return console.error(error);
});

where lowPort is the lower port number, highPort is the higher port number, timeout is the socket timeout for the port in msec.

An example of the ouput. A json containing a port number and an error field if any like:

[
  {
    "port": 4370
  },
  {
    "port": 4371,
    "error" : { "error" : "Error: socket hang up", "code" : "ECONNRESET"}
  }
]

Examples - Connect to a specific port As soon as a port is known to work, the Spotify Web Helper can be instantiated with that port to correctly communicate to Spotify running application on the same host:

var SpotifyWebHelper = require('node-spotify-webhelper-portscanner');
console.log("Connecting to Spotify on port [%d]...", openPort);
var spotifyClient = new SpotifyWebHelper( { port : openPort });
spotifyClient.getStatus(function (err, res) {
  if (err) {
    return console.error(err);
  }
  console.info('Currently Playing:',
    res.track.artist_resource.name, '-',
    res.track.track_resource.name);
});
return console.log("Spotify is listening on port [%d]", item);

});

Examples - Auto detect an open port and connect To automatically detect an open port and connect to this one, use the autoDectect option set to true.

var SpotifyWebHelper = require('../index');
var spotifyClient = new SpotifyWebHelper( { autoDectect : true }); // init with default port
spotifyClient.getStatus(function (err, res) {
  if (err) {
    console.error(err);
  }
  else if(res) {
    console.info('Currently Playing:',
      res.track.artist_resource.name, '-',
      res.track.track_resource.name);
  }
});

See examples/ folder for more examples and code.