From cc3ab62abe1ebede541989c314999940b4a05cf0 Mon Sep 17 00:00:00 2001 From: Ross Stewart Date: Mon, 8 Sep 2025 13:07:20 +0100 Subject: [PATCH] - Added scrobbling functionality, tracks will now be scrobbled if you have enabled the feature on your Navidrome instance - Resolves #52 - Resolves #33 --- skill/app.py | 6 ++++++ skill/asknavidrome/subsonic_api.py | 13 +++++++++++++ 2 files changed, 19 insertions(+) diff --git a/skill/app.py b/skill/app.py index 8942dc1..d5118eb 100755 --- a/skill/app.py +++ b/skill/app.py @@ -1,3 +1,4 @@ +from datetime import datetime from flask import Flask, render_template import logging from multiprocessing import Process @@ -845,6 +846,11 @@ class PlaybackFinishedHandler(AbstractRequestHandler): def handle(self, handler_input: HandlerInput) -> Response: logger.debug('In PlaybackFinishedHandler') + + # Generate a timestamp in milliseconds for scrobbling + timestamp_ms = datetime.now().timestamp() + current_track = play_queue.get_current_track() + connection.scrobble(current_track.id, timestamp_ms) play_queue.get_next_track() return handler_input.response_builder.response diff --git a/skill/asknavidrome/subsonic_api.py b/skill/asknavidrome/subsonic_api.py index 8790ce9..adf0d71 100644 --- a/skill/asknavidrome/subsonic_api.py +++ b/skill/asknavidrome/subsonic_api.py @@ -63,6 +63,19 @@ class SubsonicConnection: self.logger.error('Failed to connect to Navidrome') return self.conn.ping() + + def scrobble(self, track_id: str, time: int) -> None: + """Scrobble the given track + + :param str track_id: The ID of the track to scrobble + :param int time: UNIX timestamp of track play time + :return: None + """ + self.logger.debug('In function scrobble()') + + self.conn.scrobble(track_id, True, time) + + return None def search_playlist(self, term: str) -> Union[str, None]: """Search the media server for the given playlist