plapperkasten
Manage a headless media device.
What?!
Turn a Raspberry Pi with only buttons and speakers attached into a jukebox playing local music.
In a typical setup you might have a couple of buttons wired to a raspberry pi's GPIO pins, some speakers attached to the audio jack and a RFID reader plugged into one of the USB ports.
This is based on the idea of the PhonieBox ("original" software, more information on awesomeopensource.com) but written from scratch and not as feature-rich - yet!
plapperkasten has started as a small script to learn the workings of a Raspberry Pi box and to avoid the great but intimidatingly complex RPi-Jukebox-RFID. As the project has grown more complex and mature I've decided to release it into the wild - so here it is.
Features
- Easy setup: install the python package from PyPi (with
pip install plapperkasten) or configure the whole machine using plapperkasten-setup. This will guide you from the download of the OS all the way to a functioning device includingSSH, setting up an isolated python environment, configuring sound, users, etc. - Nearly everything is a plugin: Theres a plugin for controlling the sound using
ALSAand one forPipeWire. Need to output toJACKorPulseAudio? Write your own plugin by lending from the existing plugins. - Completely written in Python 3:
- Does not run as a super user:
plapperkastenis geared towards interacting with hardware buttons, sound and the like without needing special privileges. This needs some configuration of your OS but plapperkasten-setup is there to help you - or if you want it your way to give you some hints.
Setup
Please see https://github.com/randomchars42/plapperkasten-setup for detailed instructions and an easy installer.
Web interface
The web server listens on port 8080. Its hostname setting is the address
to bind on the device running Plapperkasten. For access from other devices on
your local network, add this to ~/.config/plapperkasten/config.yaml:
plugins:
server:
hostname: '0.0.0.0'
port: 8080
Then open http://plapperkasten1:8080, or use the
Pi's current name or IP address. Keep hostname: '127.0.0.1' for access only
from the device itself. A hostname that resolves to another computer cannot
be used as the bind address.
If the configured address or hostname is not available during boot, the web server retries once per second for up to 60 seconds while the network starts.
The interface uses system fonts and controls with a minimum font size of 16px to avoid the usual iPhone input-focus zoom. Buttons have at least 44px touch targets, playlist titles wrap onto multiple lines, and percentage controls use a compact grid. The layout adapts to phone widths without a frontend framework or additional dependencies. Normal browser zoom remains available.
Spotify favorites
The Spotify tab can play a pasted Spotify playlist or album link and save named favorites. Saved favorites have Play and Remove buttons. Saving or removing a favorite does not interrupt playback. Saving the same name again updates its link. The existing player buttons, GPIO buttons and volume controls work with the selected playback source, including Spotify.
Spotify playback uses Spotify Soloist, which must run separately on the same Pi. Plapperkasten does not need your Spotify API key, a Web API app, or an additional OAuth login.
-
Download Soloist for the Pi's architecture from the official downloads page and make its
soloistexecutable available onPATH(or configure its full path below). Each user needs Spotify Premium and their own Soloist API key. -
Start Soloist as the same Linux user that runs Plapperkasten and its PipeWire session, using a private environment variable containing the key:
soloist --device-name "Plapperkasten" --api-key "$SOLOIST_API_KEY" --ws 127.0.0.1:9090
In the Spotify app on the same network, select Plapperkasten once to pair it. Soloist keeps that session in its data directory for future starts. Confirm
soloist ctl status --ws 127.0.0.1:9090reports a logged-in session. Soloist uses the default audio output; running in the same PipeWire session allows Plapperkasten's existing volume/output controls to apply. -
Add this to
~/.config/plapperkasten/config.yaml, merging it with any existingpluginssection, then restart Plapperkasten:plugins: spotify: enabled: true executable: 'soloist' # or an absolute path to the executable endpoint: '127.0.0.1:9090'
-
Open the existing web interface, select Spotify, and paste a full
https://open.spotify.com/playlist/...orhttps://open.spotify.com/album/...share link. Choose Play on Plapperkasten, or enter a name and choose Save favorite. Spotify URI values (spotify:playlist:...andspotify:album:...) also work. Shortspotify.linkURLs must first be opened in a browser to obtain their full link.
Favorites are stored in ~/.config/plapperkasten/spotify_favorites.yaml by
default. Set plugins.spotify.filename_favorites to change the filename; a
relative path is resolved against core.paths.user_directory. The file is a
YAML mapping of names to playlist or album URIs and may also be edited while the server
is running. Changes made in the browser survive service restarts.
The page reports Soloist's confirmed playback status, current track and connection errors. Selecting a local playlist or scanning an MPD card pauses Spotify and hands the controls back to MPD. Selecting Spotify stops MPD. Stop pauses Spotify and resets the current track to its beginning. Playlist positions are not stored separately for each favorite.
Keep Soloist's WebSocket listener on 127.0.0.1; browsers use Plapperkasten's
HTTP server rather than connecting to Soloist directly. Keep the API key out of
the web page, favorites file and source repository. For unattended startup,
an example user service is provided in examples/soloist.service.
Put the key in a private ~/.config/soloist/soloist.env file (mode 600) as
SOLOIST_API_KEY=your-key, adjust the service's executable path, and install it
under ~/.config/systemd/user/. Enable it with
systemctl --user enable --now soloist.service. Keep the same Soloist data
directory when switching from a manual run to the service, and stop the manual
process first.
To switch the Spotify account used for playback, stop soloist.service, then
run Soloist as the same Linux user with the same data directory and --pair.
Keep the existing API key. In the Spotify app, sign in to the account that
should play on the box, connect to the same network, and select Plapperkasten
in the device picker. Pair mode replaces the stored Spotify Connect session and
exits after pairing; start soloist.service again afterward. The API key and
playback account are separate. See Spotify's
authentication guide.
To share one volume between Spotify's phone slider, the box buttons, and RFID
playback on a native PipeWire setup, install
examples/soloist-pipewire.conf as
~/.config/pipewire/client.conf.d/60-plapperkasten-spotify-volume.conf for the
user running Soloist. Then enable plugins.spotify.shared_volume: true and set
plugins.spotify.interval_poll: 1. Restart Soloist and Plapperkasten at a low
output volume. The PipeWire rule holds Spotify's stream at unity gain while
Plapperkasten synchronizes its phone slider with the shared output mixer;
Spotify volume changes also respect plugins.soundpwwp.max and changes to the
web maximum. Enable this only with that rule and the soundpwwp backend.
The box and web minus/plus buttons use plugins.soundpwwp.step (5 percentage
points by default). Web presets are also available every 5 percentage points.
The Spotify tab always shows the loaded queue near the top, including while playback is paused. Browse the current track and upcoming tracks, or expand playback history. The queue scrolls independently to keep favorites and the playlist form accessible. A text filter matches titles and artists. Play track starts a listed track individually on the box; it does not jump to that position within the original playlist. Queue updates use the existing Soloist CLI and require no additional authorization.
This shows the queue supplied by Spotify, which may be only part of a playlist.
Plapperkasten requests up to 1,000 upcoming tracks by default; set
plugins.spotify.queue_limit to change the requested limit (maximum 5,000).
Spotify currently documents metadata for up to 80 upcoming tracks, so a larger
request does not guarantee a complete playlist. Queue snapshots refresh every 10 seconds and when
the current track changes. Set plugins.spotify.interval_queue to adjust that
interval. Browsing an arbitrary playlist before it is loaded is not supported.
For the same data in a shell, use
soloist ctl queue 1000 --json --ws 127.0.0.1:9090.
Soloist builds expire after 90 days, so update the executable from Spotify regularly and restart its service. The binary and API key are not distributed with Plapperkasten. See Spotify's setup and CLI reference for installation, pairing and updates.
Held volume buttons
The PipeWire output starts at 30% before the ready sound. Set
plugins.soundpwwp.startup_volume to choose another startup level; the maximum
volume still caps it. Startup waits for the volume backend to finish and
confirm its setting before playing the sound.
The standard volume pins (13 and 24) repeat every 100 ms while held. Other
buttons keep the 300 ms repeat interval. Adjust plugins.inputgpiod.press_pulse_intervals
in your configuration if your volume buttons use different pins, or override
the values to change the repeat speed. For example:
plugins:
inputgpiod:
press_pulse_intervals: {13: 0.1, 24: 0.1}
PipeWire volume steps use one capped wpctl command when supported; older
WirePlumber versions retain the read-and-set behavior. Feedback sounds are
coalesced during rapid input to avoid a backlog of delayed beeps.
Bookworm and Trixie
The GPIO extra requires gpiodmonitor 1.4, which supports the distro libgpiod
1.x and 2.x bindings without changing button configuration. Use a fresh
virtual environment with --system-site-packages under the distro Python.
See the setup instructions
for selecting the matching WirePlumber volume configuration and power-off hook.
Development
Style
Docstrings are formatted according to the Google Style Guide.
All other formatting tries to adhere to PEP8 and is enforced by YAPF.
Log entries use lazy evaluation, i.e., logger.debug('start %s', name), start with a lower-case letter and do not end with a full stop.
Raised errors on the other hand use f-strings (if necessary) and contain whole sentences, i.e. ValueError(f'{variable} did not match XXXX.').
Linting / Checking
Code should be checked by pylint and mypy.
Paths
All path representations should be pathlib.Path-objects instead of strings.
Logging
Logging uses a wrapper (plapperkasten.plklogging) around the logging module to cover logging from multiple processes.
Import a logger using:
from plapperkasten.plklogging import plklogging
logger: plklogging.PlkLogger = plklogging.get_logger(__name__)
# your code here
Setup for development
Requirements
Python >= 3.10as it uses typehinting features only available beginning with 3.10.
Semi-optional
libgpiodwithpython3-libgpiodandgpiodmonitor>=1.1.3if you plan to use theinputgpiod-plugin. Alternatively you may implement the functionality usingRPi.GPIOor any library of your choice - but beware: you're gooing to need super user privileges!
Recommendations
-
pyenv to setup a python version withput messing up your system.
-
pipenv to create a virtual environment with a defined python version.
Example setup using pipenv
git clone git@github.com:randomchars42/plapperkasten.git
cd plapperkasten
# consider adding this to your .bashrc / equivalent for your shell:
# `export PIPENV_VENV_IN_PROJECT=1`
# this leads to a folder `.venv` being created at the project root
# otherwise you might need to tweak the `[tool.mypy]`` path in
# `pyproject.toml` (depending on your editor setup).
# setup a virtual environment with set python version
# set the version to >= 3.10
pipenv --python 3.10
# install development dependencies
pipenv install --dev
# activate venv
pipenv shell
Web controls and status
The web interface shows the last RFID card ID and whether auto shutdown is active or paused. Status updates automatically every second. Card IDs retain leading zeros, and unassigned cards are shown without triggering an action. The last ID is kept in memory until the service restarts; selecting a playlist in the web interface does not count as reading a card.
Use Pause auto shutdown to keep the box running while idle. The pause lasts until Resume auto shutdown is pressed or the service restarts. Resuming starts a fresh configured idle timeout once the box is idle. Manual shutdown still works while auto shutdown is paused.
GET /api/status returns last_rfid_card (a string, or null before the first
read) and autoshutdown_paused (a boolean, or null until the auto shutdown
plugin reports its state). The built-in events rfid_read,
autoshutdown_pause, autoshutdown_resume and autoshutdown_status are routed
automatically, including with existing core.events.passthrough settings.
Plapperkasten logic in a nutshell
plapperkasten is a simple platform for plugins that can talk to each other to control a jukebox. There is a plugin recieving input from buttons (src/plapperkasten/plugins/inputgpiod), one recieving input from RFID readers (src/plapperkasten/plugins/inputdevinputevent), one for controlling an MPD client (src/plapperkasten/plugins/mpdclient) and so forth.
A good place to get to know the overall logic is src/plapperkasten/plapperkasten.py. This is the main entry point into the programme.
It will in turn:
- start a process for logging
- load the configuration files
- gather all plugins from
src/plapperkasten/pluginsand~/.config/plapperkasten/plugins(or wherever~/.config/plapperkasten/config.yamlpoints it to) - start a process for each plugin (that is not blacklisted in
~/.config/plapperkasten/config.yaml) - the plugins register for events they might process
- trigger
on_before_run()for each pluggin - wait for the plugins to send events to process, translate or re-emit so that other plugins can react to them
- or wait for all plugins to exit (either by themselves or because of a
terminateevent) - if a
shutdownevent has been emitted,plapperkastenwill try to shutdown the host (here's how to stop it during development)
Examplary flow of events
In a typical setup you might have a couple of buttons wired to a raspberry pi's GPIO pins, some speakers attached to the audio jack and a RFID reader plugged into one of the USB ports.
An RFID token has been recognised
inputdevinputeventlistens to the attached RFID reader and reads a token.inputdevinputeventsends anrawevent with the payload0123456789(the value read from the token) toplapperkastenvia its pipeplapperkastenrecieves the event, looks it up in~/.config/plapperkasten/events.mapand sees it maps to aload_sourceevent with the payloaduse=Mpdclient,key=Music/Folder/Band/Album.plapperkastenemitsload_sourceto those who listenmpdclientlistens toload_sourceand makes mpd or mopidy (whichever you run on the system) add the folderMusic/Folder/Band/Albumto a new playlist and start playing it
A button is pressed
inputgpiodlistens to the gpio pins and recieves a signal from pin 12.inputgpiodsends an event12_shorttoplapperkastenvia its pipeplapperkastenrecieves the event, looks it up in~/.config/plapperkasten/events.mapand sees it maps to avolume_increaseeventplapperkastenemitsvolume_increaseto those who listenpwwp(short for PipeWire / Wireplumber) listens tovolume_increaseand callswpctl set-volume @DEFAULT_AUDIO_SINK@ 1%+pwwpsends an eventbeeptoplapperkastenplapperkastenknows from its config that it should pass those events through, so it re-emits the event to whom it may concernsoundeffectslistens to thebeepand produces a beep
Core files
src/plapperkasten/settings/config.yamlcontains default settings - user changes should not go here~/.config/plapperkasten/config.yamlmay contain any of the settings fromsrc/plapperkasten/settings/config.yamland overwrite themsrc/plapperkasten/settings/events.mapcould contain default event mappings but is empty - user changes should not go here~/.config/plapperkasten/events.mapmay contain events defined by the user (seesrc/plapperkasten/keymap.pyfor a description of the form)
Creating a plugin
A good place to start is to copy the "example" plugin and to take off from there. You will find it in src/plugins/example.
Each plugin lives in its own process. This has some severe implications:
- You need to use the logging functionality provided by
plapperkasten.plkloggingsee logging above. - The class is initialised in the main process, this is where it might access data from the configuration or other parts of the programme. It may only store immutable information or fresh copies (as returned by
plapperkasten.config) or else the multiprocessing hell will be upon you. - If you need to do something (like fetching configuration values or registering for events) on initialisation before the plugin's process was started use
on_init. - If you need to do something as soon as the new process has started use
on_before_run. - If you need to do something every X seconds use
on_tickand setself._tick_intervalto X inon_init. - If you need to respond to an event, register for it and write an
on_EVENTmethod, e.g., placeregister_for('my_event')inon_initand writeon_my_eventto handle the event. - If you need total controll - you usually don't - overwrite
run, as insrc/plapperkasten/plugins/inputgpiod/inputgpiod.py. - If you need to tidy up after you put the code in
on_after_run. - If you want to prevent
plapperkastenfrom shutting down after a period of idleness usesend_busy. - If you want
plapperkastento think it might restart its "idle" countdown usesend_idle(but the countdown will only commence if all plugins are idle). - If you want to send an event to
plapperkastenusesend_to_main.
Preventing shutdown during development
To avoid shutdown during development set debug in ~/.config/plapperkasten/config.yaml to true.
Metadata
Release files for plapperkasten 0.8.20
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| plapperkasten-0.8.20.tar.gz | 3.2 MB | Without provenance | Details for plapperkasten-0.8.20.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| plapperkasten-0.8.20-py3-none-any.whl | Python 3 | none | any | Details for plapperkasten-0.8.20-py3-none-any.whl |
Total release size: 6.5 MB
Release files / plapperkasten-0.8.20.tar.gz
| Download URL | plapperkasten-0.8.20.tar.gz |
|---|---|
| Size | 3.2 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
473a74cdb4662dcbd1bff00cbfc9bdd96fbf50782729c7cc065faf5a60f62640
|
|
BLAKE2b-256 checksum How to use checksums |
9f3047882d8ba44921d14f755bdcab54a577ec06e5f7661e52651ce0306727a8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.8
|
Release files / plapperkasten-0.8.20-py3-none-any.whl
| Download URL | plapperkasten-0.8.20-py3-none-any.whl |
|---|---|
| Size | 3.2 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c7a659e2464b4209787ac70d396f0f9f230e913ba7302399f674a74c7c330f13
|
|
BLAKE2b-256 checksum How to use checksums |
c0ac990cbdd81e3f57193e6013b0aba7d9586b01bbc591ee44a2a97bbb0d90a4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.8
|
Security for plapperkasten 0.8.20
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.