Skip to content

yams-2 - added sticker dbupdate on played #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
MY YAMS FORK
============

Wanted to update MPD's sticker db on play to keep track of how many times songs have been played.
After considering many options realised i had been using YAMS for so long and it already is watching MPD for song plays so the easiest method would be to add a couple lines to it.

YAMS
====

Expand Down
27 changes: 26 additions & 1 deletion yams/scrobble.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import requests, hashlib
import xml.etree.ElementTree as ET
from mpd import MPDClient
from mpd.base import ConnectionError
from mpd.base import ConnectionError, CommandError
import select
from pathlib import Path
import time
Expand Down Expand Up @@ -862,6 +862,31 @@ def mpd_watch_track(client, session, config):
or real_time_elapsed
>= (scrobble_threshold / 100) * song_duration
):
# Update "played" sticker db
try:
# Extract current "played" value
played = int(
client.sticker_get(
"song", song["file"], "played"
)
)
# This error could be either the song doesnt have the
# sticker or stickers arent activated in the mpd session
except CommandError:
# So if it the first, set the numer to 0
played = 0
try:
# Set the number to the last number + 1
client.sticker_set(
"song", song["file"], "played", played + 1
)
# And this handles if it was actually that the mpd
# session doesnt have the sticker db active
except CommandError:
logger.error(
"Couldn't update sticker db. MPD sticker db not active"
)

current_watched_track = ""
if len(failed_scrobbles) < 1:
# If we don't have any pending scrobbles, try to scrobble this
Expand Down