Fix MPD client crashes, improve track handling, and update docs - #10
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.