Skip to content

Commit

Permalink
feat: mpdstats: adds config option for remaining time threshold to
Browse files Browse the repository at this point in the history
determine if track was played.
  • Loading branch information
5061726b6572 committed Mar 5, 2025
1 parent 1f93867 commit 69e1127
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
7 changes: 5 additions & 2 deletions beetsplug/mpdstats.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ def __init__(self, lib, log):

self.do_rating = mpd_config["rating"].get(bool)
self.rating_mix = mpd_config["rating_mix"].get(float)
self.time_threshold = 10.0 # TODO: maybe add config option?
self.time_threshold = mpd_config[
"maximum_remaining_seconds_allowed_for_track_to_be_considered_played"
].get(float)

self.now_playing = None
self.mpd = MPDClientWrapper(log)
Expand Down Expand Up @@ -272,7 +274,7 @@ def on_play(self, status):
# after natural song start.
diff = abs(time.time() - self.now_playing["started"])

if diff <= self.time_threshold:
if diff <= 10.0:
return

if self.now_playing["path"] == path and played == 0:
Expand Down Expand Up @@ -336,6 +338,7 @@ def __init__(self):
"host": os.environ.get("MPD_HOST", "localhost"),
"port": int(os.environ.get("MPD_PORT", 6600)),
"password": "",
"maximum_remaining_seconds_allowed_for_track_to_be_considered_played": 10,

Check failure on line 341 in beetsplug/mpdstats.py

View workflow job for this annotation

GitHub Actions / Check linting

beetsplug/mpdstats.py:341:89: E501 Line too long (90 > 88)
}
)
mpd_config["password"].redact = True
Expand Down
4 changes: 4 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ New features:
when fetching lyrics.
* :doc:`plugins/lyrics`: Rewrite lyrics translation functionality to use Azure
AI Translator API and add relevant instructions to the documentation.
* :doc:`plugins/mpdstats`: Add new configuration option,
``maximum_remaining_seconds_allowed_for_track_to_be_considered_played``, to allow
configuring the maximum number of seconds remaining on a track for it to be
counted as played instead of skipped.

Bug fixes:

Expand Down
2 changes: 2 additions & 0 deletions docs/plugins/mpdstats.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ configuration file. The available options are:
Default: ``yes``.
- **rating_mix**: Tune the way rating is calculated (see below).
Default: 0.75.
- **maximum_remaining_seconds_allowed_for_track_to_be_considered_played**: Maximum number of seconds remaining in the track for it to be considered played. If remaining time is greater than this value skip count will be incremented instead of play count.
Default: 10

A Word on Ratings
-----------------
Expand Down

0 comments on commit 69e1127

Please sign in to comment.