bashfm scrobbler for mpv cli in termux
title: «bashfm scrobbler for mpv cli in termux» date: «2026-05-11 01:26»
The script (bashfm.py) is a persistent background scrobbler that connects to an mpv instance via a Unix‑domain socket and sends playback data to Last.fm. Here’s what it does:
· Authentication – logs into Last.fm once using the mobile‑session API and stores the session key. · Socket connection – continuously tries to connect to mpv’s IPC socket (mpv-socket). If the socket disappears (mpv stopped), it automatically reconnects when mpv is restarted. · Metadata monitoring – observes the metadata property of mpv. When a new track is detected (artist + title + album changes), it sends a “Now Playing” notification to Last.fm and records the track’s start time and duration. · Scrobble logic – scrobbles a track when: · A new track begins (the previous track is then scrobbled, if it played long enough). · The socket disconnects cleanly (mpv stopped, so the final track is scrobbled). · A background checker thread (every 5 seconds) notices the current track has played for at least half its duration or 4 minutes – this ensures even the last track of a session is scrobbled without waiting for a track change. · Human‑readable output – displays a clean, single‑line log: Session key: …, ▶ Artist – Title, Scrobbled: Artist – Title ✅. · Verbose / debug mode – with –verbose it prints all raw JSON from mpv and the Last.fm API, and optionally writes everything to a log file.
In short, the script turns any mpv instance (with an IPC socket) into a fully automatic, always‑running scrobbler that handles track changes, restarts, and single‑file sessions without missing a beat.