Self-Hosted Spotify on a Raspberry Pi — Part 20/B: Tagging a Music Library with Beets
Executive Summary
Managing a self-hosted music library on a Raspberry Pi requires more than simple file storage; it demands rigorous metadata normalization to ensure consistent playback across diverse clients. This guide details the implementation of Beets, a powerful music library manager, within a Dockerized homelab environment. The core challenge addressed here is the fragmentation of genre metadata—specifically the discrepancy between the genre and genres fields in MusicBrainz data—and the operational friction caused by plugin misconfigurations. We provide a production-ready docker-compose.yml for Beets, explain the critical role of the discogs plugin in resolving tagging ambiguities, and offer a strategy for unifying genre tags to prevent client-side sorting errors.
Implementation
The foundation of this setup is a Docker Compose configuration that isolates the Beets service while maintaining persistent storage for the library database and configuration. We utilize the official beetsserver/beets image, which includes the web interface and command-line tools.
version: '3.8'
services:
beets:
image: beetsserver/beets:latest
container_name: beets
restart: unless-stopped
ports:
- "8337:8337"
volumes:
# Mount the music directory for read/write access
- /srv/music:/music:rw
# Persist the Beets database and config
- ./beets_data:/config
environment:
- BEETS_CONFIG=/config/config.yaml
- BEETS_DIR=/music
networks:
- homelab_net
networks:
homelab_net:
driver: bridge
The configuration file config.yaml is where the logic resides. A common pitfall for new users is enabling plugins without understanding their dependencies. For instance, the discogs plugin is essential for high-fidelity tagging but requires an API key. Without it, Beets may fail to resolve matches, leading to the "matched nothing" scenario described in our context.
directory: /music
library: /config/musiclibrary.db
plugins:
- discogs
- embedart
- fetchart
- lastgenre
discogs:
user_token: YOUR_DISCOGS_USER_TOKEN
lastgenre:
auto: yes
fallback:
- Rock
- Electronic
mappings:
genres:
- Rock: Rock
- Alternative: Alternative Rock
- Indie: Indie Rock
The mappings section is critical for unifying genres. MusicBrainz and Discogs often use varied terminology (e.g., "Alt Rock" vs. "Alternative"). By defining these mappings, Beets normalizes tags before writing them to the files, ensuring that your media server (Plex, Jellyfin, or Navidrome) presents a clean, unified genre list.
ShVaSa Intuition
The engineering challenge here is not merely storage, but data integrity. In homelab environments, metadata inconsistency leads to "orphaned" tracks that do not appear in genre-based playlists. The genre field is typically a single string, while genres is a list. Many modern clients prioritize genres, but older ID3 taggers only write to genre. Beets acts as the normalization layer, enforcing a single source of truth.
The intuition behind enabling the discogs plugin is rooted in its community-driven database, which often contains more granular and accurate metadata than MusicBrainz for niche genres. When Beets "matches nothing," it is usually because the heuristic matching algorithm lacks the context provided by Discogs' deeper catalog. By integrating Discogs, we reduce the need for manual intervention, shifting the workflow from reactive correction to proactive normalization.
Storage and Network Topology
The following Mermaid diagram illustrates the data flow between the Beets service, the local music library, and the media server client.
graph TD
A[User CLI / Web UI] -->|Beets Commands| B(Beets Container)
B -->|Read/Write| C[(Music Library /music)]
B -->|Query| D[MusicBrainz API]
B -->|Query| E[Discogs API]
B -->|Update Tags| C
F[Media Server<br/>e.g., Jellyfin] -->|Scan Library| C
F -->|Serve| G[Client Device<br/>Phone/PC]
style B fill:#f9f,stroke:#333,stroke-width:2px
style C fill:#bbf,stroke:#333,stroke-width:2px
style D fill:#ff9,stroke:#333,stroke-width:2px
style E fill:#ff9,stroke:#333,stroke-width:2px
Operational Pitfalls and Security
- API Rate Limiting: Both MusicBrainz and Discogs enforce rate limits. If you run
beet importon a large library without throttling, you may be temporarily banned. Use the--timelimitflag in Beets to pace requests. - Backup Strategy: The
musiclibrary.dbfile is the heart of your tagging effort. It must be backed up separately from the audio files. A simple script to copy/config/musiclibrary.dbto an off-site location is essential. - Security: The Beets web interface exposes port 8337. In a production homelab, this should be proxied through Nginx or Caddy with TLS termination and basic authentication. Never expose port 8337 directly to the internet.
Glossary
- Beets: An open-source music library manager that automates metadata tagging.
- Discogs: A community-driven music database, often used as a secondary source for Beets.
- Genre Mapping: The process of standardizing varied genre tags into a unified list.
- ID3 Tags: Metadata stored within MP3 files, including title, artist, and genre.
By adhering to these practices, you ensure that your self-hosted music library is not just a collection of files, but a structured, queryable, and resilient asset.
Grounding & Source Attribution
- Original Topic: Self-Hosted Spotify on a Raspberry Pi — Part 20/B: Tagging a Music Library with Beets
- Primary Author / Dispatcher: Levente Csikor via Medium Self-Hosting
- Curated and Synthesized by: ShVaSa Lab (Sharath Japa)
- Preserved Canonical URL: https://shvasa.us/posts/self-hosted-spotify-on-a-raspberry-pi-part-20b-tagging-a-music-library-with-beets