From 0856fbfbbf657cec2c8e2a4086a9d30452f0fb31 Mon Sep 17 00:00:00 2001 From: JISAUAY Date: Wed, 10 Sep 2025 10:52:47 -0500 Subject: [PATCH] maybe add scrobbling for cached songs --- textual1/SubSonic.py | 10 ++++++---- textual1/app.py | 3 +++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/textual1/SubSonic.py b/textual1/SubSonic.py index b653a72..3ad9b09 100644 --- a/textual1/SubSonic.py +++ b/textual1/SubSonic.py @@ -374,17 +374,19 @@ class SubpyConn: https://opensubsonic.netlify.app/docs/endpoints/scrobble/ id: str - unique identifier of the media to scrobble - OPTIONAL time: int - posix time of when the song was listened to + OPTIONAL scrobble_time: int - posix time of when the song was listened to. Default: Current Time (UNIX_E) OPTIONAL submission: bool - Whether this is a "submission" or a "now playing" notification. Default: True """ - def scrobble(self, id: str, time: int | None = None, submission: bool | None = True) -> None: + def scrobble(self, id: str, scrobble_time: int | None = None, submission: bool | None = True) -> None: url = self.base_url + '/rest/scrobble?' payload = self._getBasePayload() payload['id'] = id - if time: - payload['time'] = time + if scrobble_time is None: + payload['time'] = round(time.time() * 1000) + elif scrobble_time: + payload['time'] = scrobble_time payload['submission'] = submission diff --git a/textual1/app.py b/textual1/app.py index 7cfb1a7..36b4dc0 100644 --- a/textual1/app.py +++ b/textual1/app.py @@ -533,6 +533,9 @@ class TextualSubpyPlayer(App): if CACHE and os.path.exists(audio_cache_path): with open(audio_cache_path, 'rb') as file: audio_data = io.BytesIO(file.read()) + + # If file was found in cache record scrobble + asyncio.create_task(asyncio.to_thread(conn.scrobble, song.id, submission=False)) else: # Run the blocking stream call in a separate thread r = await asyncio.to_thread(conn.stream, song.id)