Skip to content

Fix MPD client crashes, improve track handling, and update docs - #10

Merged
dbeley merged 19 commits into
mainfrom
fix/review-findings
Aug 3, 2026
Merged

Fix MPD client crashes, improve track handling, and update docs#10
dbeley merged 19 commits into
mainfrom
fix/review-findings

Conversation

@dbeley

@dbeley dbeley commented Aug 2, 2026

Copy link
Copy Markdown
Owner

No description provided.

dbeley added 19 commits August 2, 2026 10:27
MPD returns the track tag as a string (e.g. "10" or "3/10"), not a
list. Indexing [0] truncated track 10 to 1. Use the raw tag instead.
mpdscrobble_restart() reconnected to the default localhost:6600,
ignoring the host/port from the config file. Remember them at connect
time and reuse them on restart.
loop() is an infinite loop that only returns by raising, so the
"MPD Client crashed" restart logic in main() was unreachable dead
code: the process died on the first MPD failure. Wrap loop() in
try/except and fix the backoff, which reset to 10s every iteration
instead of doubling. Cap the delay at 10 minutes.
close() sends the protocol close command, which raises on a socket
already dead from a crash. In the recovery path that exception would
kill the daemon. disconnect() is already guarded, so fall back to it
when close() fails.
loop() fetched mpdscrobble_currentsong() twice per iteration. If the
track changed between the two fetches, the previous track was never
compared against the cache and its scrobble was silently lost. Reuse
the single fetched value as the cache for the next iteration.
A track title like "She = Me" produced three split parts and crashed
with 'too many values to unpack'. Split once, strip whitespace, and
skip separator-less lines, mirroring mpdscribble's C reader.
The completion check used >, so a track played to exactly 40% was never
scrobbled, contradicting the documented "at least a 40% completion".
The sdist only contained the python package, so pip installs and
sdist-based packages (e.g. the AUR build) were missing the example
config, the systemd service and the mpdscribble_history.py script the
README points users to.
.envrc sourced venv/bin/activate while shell.nix creates .venv, so the
activation failed under direnv. The pre-commit config pinned
python3.13, which is not present in the nix shell (python3.14); the
hooks errored before running.
Comparing a track with anything else (e.g. a cached None or a string)
raised AttributeError. Return NotImplemented so Python falls back to
identity comparison.
logger.error(e) dropped the stack trace, so a silently failing network
was impossible to diagnose. logger.exception logs the full traceback
and identifies which network failed.
main() created and connected an MPD client it never used. Remove it
along with the now-unneeded host/port config parsing.
time.mktime(datetime.now().timetuple()) is exactly int(time.time());
the datetime round-trip only obscured it.
…ce scrobblers

- mpd-python2 -> python-mpd2
- -c/--config -> -c/--config_file
- replace setup.py and pipenv install methods with pip install -e .
- document the [mpdscrobble] section options, including use_album_artist
- document the history script usage and numbered service sections
setup.py was a no-op stub since the pyproject.toml migration; Pipfile
and Pipfile.lock were abandoned in favor of pyproject as well. The
README no longer references either.
The version was duplicated in pyproject.toml and __init__.py and had
already drifted apart in the past. setuptools now reads it from
__init__.py via [tool.setuptools.dynamic].
Import sorting, collections.abc.Sequence, implicit open() mode,
f-strings, generator args for all(), and inline the hardcoded
listenbrainz URL instead of a pointless .format() call.
ruff is a single fast linter and formatter, superseding both black and
flake8. Its config now lives in pyproject.toml ([tool.ruff]); the
pre-commit hooks, nix shell and CI run ruff check + ruff format. The
.github and shell.nix keep the same guarantees as before.
@dbeley
dbeley merged commit 0b89f86 into main Aug 3, 2026
10 checks passed
@dbeley
dbeley deleted the fix/review-findings branch August 3, 2026 09:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant