maybe add scrobbling for cached songs
This commit is contained in:
1 parent
b6b07e830b
commit
0856fbfbbf
2 files changed
+9
-4
No files matched your search
@@ -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
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user