A Jukebox to play music on speakers using 'CD' with NFC tag
Project description
Jukebox [gukebox]
💿 Play music on speakers using NFC tags.
🚧 At the moment:
- NFC tags - CDs must be pre-populated in a JSON file (
discstoreincluded withjukeboxmay be of help to you) - supports many music providers (Spotify, Apple Music, etc.), just add the URIs to the JSON file
- only works with Sonos speakers (there is a "dryrun" player for development), but code is designed to add new ones
- as soon as the NFC tag is removed, the music pauses, then resumes when the NFC tag is replaced
💡 Inspired by:
📋 Table of contents:
Notes
Python 3.7 is supported by Jukebox up to version 0.4.1.
Python 3.8 is supported by Jukebox up to version 0.5.4.
The ui extension is only available for Python versions 3.10 and above.
Install
Install the package from PyPI.
[!WARNING] The package name is
gukeboxwithginstead of aj(due to a name already taken).
[!NOTE] The
nfcextra is optional but required for NFC reading, check compatibility.
Recommended installation
Use pip in a virtual environment.
- If your Python version is 3.13 or newer and you want NFC support, install the system GPIO binding:
sudo apt update
sudo apt install python3-lgpio
- Create a virtual environment:
# Python < 3.13
python3 -m venv jukebox
# Python >= 3.13 for NFC: use the system Python and include system packages
python3 -m venv --system-site-packages jukebox
source jukebox/bin/activate
- Install
gukeboxinto the virtual environment:
pip install "gukebox[nfc]"
[!IMPORTANT] For NFC on Python 3.13+, use the system Python that comes with your OS. A separately installed Python 3.13+ from
uv,pyenv, Homebrew, or similar may not be able to import the systemlgpiopackage, even when using--system-site-packages. If you already upgraded to a non-system Python 3.13+, use the system Python instead or use Python 3.12 or lower.
Alternative installations
pipxcan be used with--system-site-packages.uvx/uv tool installare not recommended for NFC on Python 3.13+ because they may select a non-system interpreter.- For non-system Python 3.13+, you can still install via pip/uv/poetry/etc. but you must build the
lgpiopackage from source and it may require other system packages. - All releases can be downloaded and installed from the GitHub releases page.
Installation for development
For development read the Developer setup section.
tl;dr:
git clone https://github.com/Gudsfile/jukebox.git
uv sync
First steps
Initialize the library file with discstore or manually create it at ~/.config/jukebox/library.json.
Manage the library with the discstore
To associate an URI with an NFC tag:
discstore add tag_id --uri /path/to/media.mp3
or to pull the tag_id currently on the reader:
discstore add --from-current --uri /path/to/media.mp3
Other commands are available, use --help to see them.
Admin CLI
Use jukebox-admin for admin workflows such as settings inspection and the
admin API/UI servers.
jukebox-admin settings show
jukebox-admin settings show --effective
To use the api and ui commands, additional packages are required. You can install the package[extra] syntax regardless of the package manager you use, for example:
# Python 3.9+ required
uv tool install gukebox[api]
# Python 3.10+ required, ui includes the api extra
uv tool install gukebox[ui]
When running from this repository with uv, include the extra on the command as well:
uv run --extra api jukebox-admin api
uv run --extra ui jukebox-admin ui
discstore settings ..., discstore api, and discstore ui remain available as compatibility commands, but jukebox-admin is the preferred CLI for admin flows.
Manage the library manually
Complete your ~/.config/jukebox/library.json file with each tag id and the expected media URI.
Take a look at library.example.json and the The library file section for more information.
Usage
Start the jukebox with the jukebox command (show help message with --help)
jukebox PLAYER_TO_USE READER_TO_USE
🎉 With choosing the sonos player and nfc reader, by approaching a NFC tag stored in the library.json file, you should hear the associated music begins.
Optional Parameters
| Parameter | Description |
|---|---|
--help |
Show help message. |
--library |
Path to the library file, default: ~/.config/jukebox/library.json. |
--pause-delay SECONDS |
Grace period before pausing when the NFC tag is removed. Fractional values such as 0.5 or 0.2 are supported, with a minimum of 0.2 seconds to avoid pausing on brief missed reads. Default: 0.25 seconds. |
--pause-duration SECONDS |
Maximum duration of a pause before resetting the queue. Default: 900 seconds (15 minutes). |
--verbose |
Enable verbose logging. |
--version |
Show version. |
Readers
Dry run (dryrun)
Read a text entry.
Allows you to simulate reading an NFC tag by writting the tag id in the console.
Expected syntax: tag_id or tag_id duration_seconds.
- tag_id: the full identifier of the tag, in the format required by the system
- duration_seconds: a non-negative number of seconds used to simulate how long the tag remains in place. Fractional values are allowed.
Complete example:
your:tag:uid 2.5
NFC (nfc)
Read an NFC tag and get its UID.
This project works with an NFC reader like the PN532 and NFC tags like the NTAG2xx.
It is configured according to the Waveshare PN532 wiki.
Don't forget to enable the SPI interface using the command sudo raspi-config, then go to: Interface Options > SPI > Enable > Yes.
Players
Dry run (dryrun)
Displays the events that a real speaker would have performed (playing …, pause, etc.).
Sonos (sonos)
Play music through a Sonos speaker.
Three ways to select the speaker (mutually exclusive):
| Option | CLI flag | Environment variable | Behaviour |
|---|---|---|---|
| By IP | --sonos-host 192.168.0.x |
JUKEBOX_SONOS_HOST |
Connect directly, no discovery |
| By name | --sonos-name "Living Room" |
JUKEBOX_SONOS_NAME |
Discover, then filter by name (case-sensitive) |
| Auto | (omit both) | (omit both) | Discover, pick the first speaker alphabetically |
The library file
The library.json file is a JSON file that contains the artists, albums and tags.
It is used by the jukebox command to find the corresponding metadata for each tag.
And the discstore command help you to managed this file with a CLI, an interactive CLI, an API or an UI (see discstore --help).
By default, this file should be placed at ~/.config/jukebox/library.json. But you can use another path by creating a JUKEBOX_LIBRARY_PATH environment variable or with the --library argument.
{
"discs": {
"a:tag:uid": {
"uri": "URI of a track, an album or a playlist on many providers",
"option": { "shuffle": true }
},
"another:tag:uid": {
"uri": "uri"
},
…
}
}
The discs part is a dictionary containing NFC tag UIDs.
Each UID is associated with an URI.
URIs are the URIs of the music providers (Spotify, Apple Music, etc.) and relate to tracks, albums, playlists, etc.
metadata is an optional section where the names of the artist, album, song, or playlist are entered:
"a:tag:uid": {
"uri": "uri",
"metadata": { "artist": "artist" }
}
It is also possible to use the shuffle key to play the album in shuffle mode:
"a:tag:uid": {
"uri": "uri",
"option": { "shuffle": true }
}
To summarize, for example, if you have the following ~/.config/jukebox/library.json file:
{
"discs": {
"ta:g1:id": {
"uri": "uri1",
"metadata": { "artist": "a", "album": "a" }
},
"ta:g2:id": {
"uri": "uri2",
"metadata": { "playlist": "b" },
"option": { "shuffle": true }
}
}
}
Then, the jukebox will find the metadata for the tag ta:g2:id and will send the uri2 to the speaker so that it plays playlist "b" in random order.
Developer setup
Install
Install the project by cloning it and using uv to install the dependencies:
git clone https://github.com/Gudsfile/jukebox.git
uv sync
Add --all-extras to install dependencies for all extras (api and ui).
If needed, set JUKEBOX_SONOS_HOST (IP) or JUKEBOX_SONOS_NAME (speaker name) to select your Sonos speaker (see Players).
If neither is set, the jukebox will auto-discover a speaker on the network.
To do this you can use a .env file and uv run --env-file .env <command to run>.
A .env.example file is available, you can copy it and modify it to use it.
Create a library.json file and complete it with the desired NFC tags and CDs.
Take a look at library.example.json and the The library file section for more information.
Usage
Start the jukebox with uv and use --help to show help message
uv run jukebox PLAYER_TO_USE READER_TO_USE
Start the discstore uv and use --help to show help message
uv run discstore --help
Use jukebox-admin for admin commands:
uv run jukebox-admin settings show
For the server-backed admin commands, include the matching extra:
uv run --extra api jukebox-admin api
uv run --extra ui jukebox-admin ui
Legacy compatibility commands remain available during the transition:
uv run discstore settings show
uv run --extra api discstore api
uv run --extra ui discstore ui
Other commands are available:
| Command | Description |
|---|---|
uv run ruff format |
Format the code. |
uv run ruff check |
Check the code. |
uv run ruff check --fix |
Fix the code. |
uv run pytest |
Run the tests. |
Pre-commit
prek is configured; you can install it to automatically run validations on each commit.
uv tool install prek
prek install
Contributing
Contributions are welcome! Feel free to open an issue or a pull request.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gukebox-1.0.0.dev2.tar.gz.
File metadata
- Download URL: gukebox-1.0.0.dev2.tar.gz
- Upload date:
- Size: 57.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1f1095365d23caebf42d797b71406188ca90ea6a51875e2fddee2244eb0848b8
|
|
| MD5 |
f6601ea6a7991697428d3b323e73e9af
|
|
| BLAKE2b-256 |
f678c4e6ce2bcc344b3d3d945fb2757dba5253b932f5b6d4cb26d92389c0848e
|
File details
Details for the file gukebox-1.0.0.dev2-py3-none-any.whl.
File metadata
- Download URL: gukebox-1.0.0.dev2-py3-none-any.whl
- Upload date:
- Size: 88.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.9 {"installer":{"name":"uv","version":"0.10.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0cf077a0de5b229e258801879463ab5046076d77798fa472f3069295be0aa269
|
|
| MD5 |
4146ff4d22912077aefe7e3023317675
|
|
| BLAKE2b-256 |
9fa02ac3f6ef5c07f47133f3334ef77382cee1a0897963915b1ce41f0ddaae0d
|