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

homebridge-rusty-spotify

v0.4.5

Published

[Spotify](https://www.spotify.com) plugin for [Homebridge](https://github.com/homebridge/homebridge) written in Rust. The plugin requires a Spotify Premium account.

Downloads

8

Readme

homebridge-rusty-spotify

Spotify plugin for Homebridge written in Rust. The plugin requires a Spotify Premium account.

Installation and Setup

  1. Install Homebridge: sudo npm install -g homebridge
  2. Install the plugin: sudo npm install -g homebridge-rusty-spotify
  3. Register the plugin as app in the Spotify Developer Dashboard
    1. Login
    2. Select "Create a client ID"
    3. Provide a name and description in the pop-up; click "Next"
    4. Copy the "Client ID" and "Client Secret" which will be required in the following configuration step
    5. Click "Edit Settings"
    6. Add http://localhost/callback as "Redirect URI" and save
  4. Configure the plugin using the generated client ID and client secret (see Configuration)

Configuration

The generate_config script can be used to generate the config. It requires for the client_id, client_secret and Spotify username needs to be set since those are required to authenticate to the Spotify Web API.

Running the script will open a web browser asking to authenticate to Spotify which is required to retrieve the refresh_token.

$ ./generate_config --help
usage: generate_config [-h] [--client_id CLIENT_ID]
                       [--client_secret CLIENT_SECRET]
                       [--redirect_uri REDIRECT_URI] [--username USERNAME]

Script to retrieve an access and refresh token for using the Spotify API

optional arguments:
  -h, --help            show this help message and exit
  --client_id CLIENT_ID, --client-id CLIENT_ID
                        Spotify client ID
  --client_secret CLIENT_SECRET, --client-secret CLIENT_SECRET
                        Spotify client secret
  --redirect_uri REDIRECT_URI, --redirect-uri REDIRECT_URI
                        Redirect URI
  --username USERNAME   Spotify username


$ ./generate_config --client_id=<client_id> --client_secret=<client_secret> --username=<username>
  {
    "platform": "Spotify",
    "name": "Spotify",
    "service_type": "light",    // "light" or "speaker"; Speaker is not supported by HomeKit
    "client_id": "<client_id>",
    "client_secret": "<client_secret>",
    "refresh_token": "<refresh_token>"
  }

The generated config needs to copied to the Homebridge config file (e.g. ~/.homebridge/config.json). For example:

//...
"platforms": [
  {
    "platform": "Spotify",
    "name": "Spotify",
    "service_type": "light",    // "light" or "speaker"; Speaker is not supported by HomeKit
    "client_id": "<client_id>",
    "client_secret": "<client_secret>",
    "refresh_token": "<refresh_token>",
  }
]
//...

service_type specifies whether Spotify devices should use the Lightbulb or Speaker service. If service_type is not specified, "light" will be used by default. HomeKit currently does not support Speaker services and will show "This accessory is not certified and may not work reliably with HomeKit".

Usage

Add the plugin in the Home app. The plugin will automatically discover available Spotify devices and add them as accessories. Turning a Spotify accessory on will resume playing music on the device, turning off the accessory will pause the music. The accessory also allows to change the playback volume.

Accessories get refreshed every 10 seconds (or as specified in the configuration file).

Development

  1. Install the Rust toolchain, wasm-pack, cargo-generate and npm by following this guide
  2. Clone the repository
  3. Run make
    • This will create a pkg/ directory containing all the generated nodejs files
  4. Copy the generated files to a device/directory that can be discovered by Homebridge
  5. Switch to the directory and run npm install to install all required dependencies
  6. Run Homebridge in debug mode and specify the directory with the plugin files: DEBUG=* homebridge -D -P /path/to/plugin/homebridge-rusty-spotify

A blog post about writing plugins for Homebridge and specifically this plugin has been published here.