Coder Social home page Coder Social logo

npstatus's Introduction

NowPlaying

WebSocket API for getting the currently playing song on Spotify.

Production instance at https://spotify.antti.codes/

Todo

  • Create ToS & Privacy Policy
  • Do whatever the Spotify terms ask for
  • Apply for extended quota mode to allow others to sign up
    • For now you can ask me I guess...

Documentation

Authentication

Open the website and login with Spotify.

Rest API

The REST API provides a single endpoint /api/np/:id which is meant for occasional data fetching and is therefore heavily ratelimited.

Websocket

Communication happens in JSON. op being the opcode and d being any data associated with the message. Example implementation can be found on my very own website.

The protocol

  1. Connect to wss://spotify.antti.codes/
  2. Server responds with opcode 1 and heartbeat_interval which is interval in milliseconds to send the heartbeat (opcode 3) in
{
  "op": 1,
  "d": {
    "heartbeat_interval": 15000
  }
}
{
  "op": 3
}
  1. You respond with opcode 2 and user id string as data
{
  "op": 2,
  "d": "qgfht3wu1vo4ajn8skj9ugxem"
}
  1. Server starts sending opcode 0 with the users now playing status
{
  "op": 0,
  "d": {
    "is_playing": false
  }
}
{
  "op": 0,
  "d": {
    "is_playing": true,
    "song": "Song name",
    "album": "Album name",
    "artist": "Artist name(s)",
    "album_art": "Album art url",
    "track_id": "Track id",
    "total": 223, // Total track length (seconds)
    "start": 1695837181 // Play start unix timestamp (seconds)
}

The server might also send opcode 4 with a message indicating an error. After sending opcode 4 the server will close the connection.

{
  "op": 4,
  "d": "No heartbeat received"
}

npstatus's People

Contributors

chicken avatar

Stargazers

 avatar  avatar

Watchers

 avatar

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.