#bot #fm #information #song #source #playing #sound-touch

nightly app npbot

"Now Playing" bot for publishing song information to various social networks

1 stable release

Uses old Rust 2015

1.0.0 Mar 30, 2018

#11 in #fm

AGPL-3.0

25KB
697 lines

NowPlaying bot

A "nowplaying" bot that can draw from multiple sources and send to multiple destinations

Sources

Currently, the implemented sources are:

  • Bose SoundTouch speakers
  • Last.fm

Sinks

Currently, the implemented sinks are:

  • Mastodon

Running

To run, you will need to supply a few things. You'll need a YouTube Data API key, so go to the google developer console and get one of those. It can be provided to the program through the YOUTUBE_KEY environment variable. In order to use one of the sources, you'll also need to supply some information about it. For the last.fm source, get a last.fm API key and assign it to the LASTFM_API_KEY environment variable, along with your last.fm username in the LASTFM_USERNAME environment variable. The SoundTouch source only needs the hostname of your SoundTouch speaker, in the SOUNDTOUCH_HOST environment variable.

Environment variables can be set on the command line, or in a .env file.

When the program starts, it will attempt to find a mastodon access token in the creds.json file. If the file doesn't exist, the program will prompt you on what to do to give it access to post to your mastodon account.

Adding a new source

Adding a new source is not too hard, this commit shows a good example:

https://gitlab.com/pwoolcoc/npbot/commit/4eddf89266c71677511e2cba86a69c8fe60db3ec

Basically the steps are:

  1. add a submodule to the src/source module
  2. in your new submodule, add a data structure that implements the Source trait.
  3. (optional) add a .from_env(cli_args: Opt) -> Self static method to your data structure if you want to use the detect_and_register! macro in src/main.rs.
  4. in src/main.rs, add any necessary cli arguments, and under the // Sources line in main, add the necessary code to detect and register the new source

TODO

  • tests & ci
  • use mdns to find soundtouch host, fallback to env var/cli arg
  • better story around using multiple sources?
  • moar sources
  • moar sinks

Dependencies

~25–35MB
~623K SLoC