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

spotify-desktop-remote

v0.2.3

Published

Control your Spotify Desktop app with a simple HTTP interface or Socket.io

Downloads

7

Readme

Spotify Desktop Remote

Control your Spotify Desktop app from a simple HTTP interface or with Socket.IO.

# Play a track:
curl http://localhost:3001/play/spotify:track:0FutrWIUM5Mg3434asiwkp

# Seek to the halfway mark of the song:
curl http://localhost:3001/seek/0.5

# Set the player volume:
curl http://localhost:3001/volume/0.8

# Play a playlist:
curl http://localhost:3001/play/spotify:album:2YJFLMyzzZ2k4mhfPSiOj2

# Pause the player:
curl http://localhost:3001/pause

# Stop the player:
curl http://localhost:3001/stop
// Keep everything in sync:
socket.on('player.change', function (playerStatus) {
  console.log('The current player status is', playerStatus);
});

// Play a track:
socket.emit('play', {uri: 'spotify:track:0FutrWIUM5Mg3434asiwkp'});

// Seek to the halfway mark of the song:
socket.emit('seek', 0.5);

// Set the player volume:
socket.emit('volume', 0.8);

// Play a playlist:
socket.emit('play', {uri: 'spotify:album:2YJFLMyzzZ2k4mhfPSiOj2'});

// Pause the player:
socket.emit('pause');

// Stop the player:
socket.emit('stop');

See the API reference for more details.

Requirements

Installation

There are two parts to the app:

  1. The HTTP Server that forwards commands to Spotify (src/server.coffee)
  2. The Spotify Webapp (runs inside Spotify Desktop) that accepts commands from the server via Websockets (src/main.coffee and index.html)
# OS X/Linux users:
cd ~/Spotify

# Windows users:
# cd ~/My\ Documents/Spotify

git clone https://github.com/namuol/spotify-desktop-remote.git
cd spotify-desktop-remote

# Start the server on port 3001:
npm start

# Or run it on a different port:
# PORT=3002 npm start

# Finally, run spotify and open the app:
spotify -uri spotify:app:spotify-desktop-remote

# NOTE: You can also run the app by entering
# "spotify:app:spotify-desktop-remote" into Spotify's search bar.

# Now you can control the Spotify Desktop app by hitting the server:
curl http://localhost:3001/play/spotify:track:0FutrWIUM5Mg3434asiwkp
curl http://localhost:3001/volume/1

API

Responses

All GET operations and the player.change socket event return a JSON object representing the current status of the player:

{
  loading: false,
  playing: true,
  position: 19450,
  duration: 212400,
  index: 0,
  repeat: false,
  shuffle: false,
  volume: 0.849988579750061,
  context: null,
  contexts: [{
    index: 0,
    descriptor: {
      type: "set"
    }
  }],
  track: {
    artists: [{
      name: "Rick Astley",
      uri: "spotify:artist:0gxyHStUsqpMadRV0Di1Qt"
    }],
    disc: 1,
    duration: 212000,
    image: "spotify:image:938dfdd57d4fe8a864f6148ffb9676395d012720",
    images: [
      [
        64,
        "spotify:image:9b87c26f500947d28838ebb2e33c120f6b9a6b1b"
      ],
      [
        300,
        "spotify:image:938dfdd57d4fe8a864f6148ffb9676395d012720"
      ],
      [
        600,
        "spotify:image:d6e92c8891f16c1126c6d58f47da81873a17e993"
      ]
    ],
    name: "Never Gonna Give You Up",
    number: 1,
    playable: true,
    popularity: 65,
    starred: false,
    explicit: false,
    availability: "premium",
    album: {
      uri: "spotify:album:3vGtqTr5he9uQfusQWJ0oC"
    },
    local: false,
    advertisement: false,
    placeholder: false,
    uri: "spotify:track:0FutrWIUM5Mg3434asiwkp"
  }
}

Socket.io

In order to use socket.io, include the following in your <head>:

<script type='application/javascript' src="http://localhost:3001/socket.io/socket.io.js"></script>

Then somewhere after that you can connect:

var socket = io.connect();
socket.on('player.change', function (playerStatus) {
  console.log('The current player status is', playerStatus);
});

socket.on('player.change', callback(playerStatus))

socket only

Subscribe to this event to be notified whenever anything about the player changes.

To poll for the status (with sockets or GET), see sync.

socket.on('player.change', function (playerStatus) {
  console.log('The current volume level is', playerStatus.volume)
});

Parameters:

callback(playerStatus) socket only A callback function that accepts a single argument as the player's current status.

/sync

socket.emit('sync', callback(playerStatus))

Perform no action; simply used to retrieve the current status of the player.

curl http://localhost:3001/sync
socket.emit('sync', function (playerStatus) {
  console.log('The current volume level is', playerStatus.volume);
});

Parameters:

callback(playerStatus) socket only A callback function that accepts a single argument as the player's current status.

/play

socket.emit('play')

Play the current track.

curl http://localhost:3001/play
socket.emit('play');

/play/:track_uri/:ms?/:duration?

socket.emit('play', {uri[, ms, duration]})

Play a specific track with a given URI.

curl http://localhost:3001/play/spotify:track:0FutrWIUM5Mg3434asiwkp

# Play the first 30 seconds:
curl http://localhost:3001/play/spotify:track:0FutrWIUM5Mg3434asiwkp/0/30000

# Play the first 30 seconds starting one minute into the song:
curl http://localhost:3001/play/spotify:track:0FutrWIUM5Mg3434asiwkp/60000/30000
socket.emit('play', {uri: 'spotify:track:0FutrWIUM5Mg3434asiwkp'});

// Play the first 30 seconds:
socket.emit('play', {
  uri: 'spotify:track:0FutrWIUM5Mg3434asiwkp',
  ms: 0,
  duration: 30000
});

// Play the first 30 seconds starting one minute into the song:
socket.emit('play', {
  uri: 'spotify:track:0FutrWIUM5Mg3434asiwkp',
  ms: 60000,
  duration: 30000
});

Parameters:

track_uri / uri A spotify track URI.

Example: spotify:track:0FutrWIUM5Mg3434asiwkp

ms optional Number of milliseconds to begin playing the track at.

duration optional Number of milliseconds to play the song for before stopping.

/play/:playlist_uri/:index?/:ms?/:duration?

socket.emit('play', {uri[, index, ms, duration]})

Play a specific album or user playlist with a given URI.

curl http://localhost:3001/play/spotify:album:2YJFLMyzzZ2k4mhfPSiOj2
curl http://localhost:3001/play/spotify:user:spotify:playlist:4BKT5olNFqLB1FAa8OtC8k

# Start at the third track in the playlist:
curl http://localhost:3001/play/spotify:user:spotify:playlist:4BKT5olNFqLB1FAa8OtC8k/3

# Start a minute into the third track in the playlist:
curl http://localhost:3001/play/spotify:user:spotify:playlist:4BKT5olNFqLB1FAa8OtC8k/3/60000

# Start a minute into the third track in the playlist and play the first 30 seconds:
curl http://localhost:3001/play/spotify:user:spotify:playlist:4BKT5olNFqLB1FAa8OtC8k/3/60000/30000
socket.emit('play', {uri: 'spotify:album:2YJFLMyzzZ2k4mhfPSiOj2'});
socket.emit('play', {uri: 'spotify:user:spotify:playlist:4BKT5olNFqLB1FAa8OtC8'});

// Start at the third track in the playlist:
socket.emit('play', {
  uri: 'spotify:user:spotify:playlist:4BKT5olNFqLB1FAa8OtC8k',
  index: 3
});

// Start a minute into the third track in the playlist:
socket.emit('play', {
  uri: 'spotify:user:spotify:playlist:4BKT5olNFqLB1FAa8OtC8k',
  index: 3,
  ms: 60000
});

// Start a minute into the third track in the playlist and play the first 30 seconds:
socket.emit('play', {
  uri: 'spotify:user:spotify:playlist:4BKT5olNFqLB1FAa8OtC8k',
  index: 3,
  ms: 60000,
  duration: 30000
});

Parameters:

playlist_uri / uri A spotify playlist URI (an album or user playlist).

Example: spotify:album:2YJFLMyzzZ2k4mhfPSiOj2

Example: spotify:user:spotify:playlist:4BKT5olNFqLB1FAa8OtC8k

index optional The track number to play (starting at zero).

ms optional Number of milliseconds to begin playing the track at.

duration optional Number of milliseconds to play the song for before stopping.

/pause

socket.emit('pause')

Pause the player.

curl http://localhost:3001/pause
socket.emit('pause');

/stop

socket.emit('stop')

Stop the player.

curl http://localhost:3001/stop
socket.emit('pause');

/volume/:volume

socket.emit('volume', volume)

Set the player volume level.

curl http://localhost:3001/volume/1
curl http://localhost:3001/volume/0
curl http://localhost:3001/volume/0.5
socket.emit('volume', 1);
socket.emit('volume', 0);
socket.emit('volume', 0.5);

Parameters:

volume A number representing the volume level, between 0 and 1.

/seek/:amount

socket.emit('seek', amount)

Set the playhead's position.

curl http://localhost:3001/seek/0
curl http://localhost:3001/seek/0.5
socket.emit('seek', 0);
socket.emit('seek', 0.5);

Parameters:

amount A number representing the position of the seek bar, between 0 and 1.

License

MIT


Analytics