maybe add scrobbling for cached songs

This commit is contained in:
JISAUAY committed 2025-09-10 10:52:47 -05:00
1 parent b6b07e830b
commit 0856fbfbbf
2 files changed
+9 -4

No files matched your search

+6 -4
View File
@@ -374,17 +374,19 @@ class SubpyConn:
https://opensubsonic.netlify.app/docs/endpoints/scrobble/ https://opensubsonic.netlify.app/docs/endpoints/scrobble/
id: str - unique identifier of the media to 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 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?' url = self.base_url + '/rest/scrobble?'
payload = self._getBasePayload() payload = self._getBasePayload()
payload['id'] = id payload['id'] = id
if time: if scrobble_time is None:
payload['time'] = time payload['time'] = round(time.time() * 1000)
elif scrobble_time:
payload['time'] = scrobble_time
payload['submission'] = submission payload['submission'] = submission
+3
View File
@@ -533,6 +533,9 @@ class TextualSubpyPlayer(App):
if CACHE and os.path.exists(audio_cache_path): if CACHE and os.path.exists(audio_cache_path):
with open(audio_cache_path, 'rb') as file: with open(audio_cache_path, 'rb') as file:
audio_data = io.BytesIO(file.read()) 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: else:
# Run the blocking stream call in a separate thread # Run the blocking stream call in a separate thread
r = await asyncio.to_thread(conn.stream, song.id) r = await asyncio.to_thread(conn.stream, song.id)