From 1ddacd4454c4a2d1b9962a86da14b6571d20879e Mon Sep 17 00:00:00 2001 From: Colin Powell Date: Thu, 17 Oct 2024 22:51:10 -0400 Subject: [PATCH] [scrobbles] Improve webhook logging --- vrobbler/apps/scrobbles/scrobblers.py | 25 +++++-------------------- vrobbler/apps/scrobbles/views.py | 24 +++++++++++++++++++----- 2 files changed, 24 insertions(+), 25 deletions(-) diff --git a/vrobbler/apps/scrobbles/scrobblers.py b/vrobbler/apps/scrobbles/scrobblers.py index c66dad4..68d72b0 100644 --- a/vrobbler/apps/scrobbles/scrobblers.py +++ b/vrobbler/apps/scrobbles/scrobblers.py @@ -41,11 +41,8 @@ def mopidy_scrobble_media(post_data: dict, user_id: int) -> Scrobble: if "podcast" in post_data.get("mopidy_uri", ""): media_type = Scrobble.MediaType.PODCAST_EPISODE - if settings.DUMP_REQUEST_DATA: - print("MOPIDY_DATA: ", post_data) - logger.info( - "[scrobblers] webhook mopidy scrobble request received", + "[mopidy_webhook] called", extra={ "user_id": user_id, "post_data": post_data, @@ -83,18 +80,6 @@ def jellyfin_scrobble_media( if post_data.pop("ItemType", "") in JELLYFIN_AUDIO_ITEM_TYPES: media_type = Scrobble.MediaType.TRACK - if settings.DUMP_REQUEST_DATA: - print("JELLYFIN_DATA: ", post_data) - - logger.info( - "[jellyfin_scrobble_media] called", - extra={ - "user_id": user_id, - "post_data": post_data, - "media_type": media_type, - }, - ) - null_position_on_progress = ( post_data.get("PlaybackPosition") == "00:00:00" and post_data.get("NotificationType") == "PlaybackProgress" @@ -265,7 +250,7 @@ def manual_scrobble_board_game(bggeek_id: str, user_id: int): "source": "Vrobbler", } logger.info( - "[webhook] board game scrobble request received", + "[vrobbler-scrobble] board game scrobble request received", extra={ "boardgame_id": boardgame.id, "user_id": user_id, @@ -420,7 +405,7 @@ def manual_scrobble_task(url: str, user_id: int): "log": {"description": description, "source_id": source_id}, } logger.info( - "[webhook] webpage scrobble request received", + "[vrobbler-scrobble] webpage scrobble request received", extra={ "task_id": task.id, "user_id": user_id, @@ -442,7 +427,7 @@ def manual_scrobble_webpage(url: str, user_id: int): "source": "Vrobbler", } logger.info( - "[webhook] webpage scrobble request received", + "[vrobbler-scrobble] webpage scrobble request received", extra={ "webpage_id": webpage.id, "user_id": user_id, @@ -492,7 +477,7 @@ def gpslogger_scrobble_location(data_dict: dict, user_id: int) -> Scrobble: scrobble.save(update_fields=["log", "playback_position_seconds"]) logger.info( - "[webhook] gpslogger scrobble request received", + "[gpslogger_webhook] gpslogger scrobble request received", extra={ "scrobble_id": scrobble.id, "provider": provider, diff --git a/vrobbler/apps/scrobbles/views.py b/vrobbler/apps/scrobbles/views.py index 9500971..1059c5e 100644 --- a/vrobbler/apps/scrobbles/views.py +++ b/vrobbler/apps/scrobbles/views.py @@ -322,7 +322,10 @@ def jellyfin_webhook(request): post_data = request.data logger.info( "[jellyfin_webhook] called", - extra={"post_data": post_data}, + extra={ + "post_data": post_data, + "user_id": request.user.id, + }, ) in_progress = post_data.get("NotificationType", "") == "PlaybackProgress" @@ -357,6 +360,14 @@ def mopidy_webhook(request): except TypeError: data_dict = request.data + logger.info( + "[mopidy_webhook] called", + extra={ + "post_data": data_dict, + "user_id": request.user.id, + }, + ) + scrobble = mopidy_scrobble_media(data_dict, request.user.id) if not scrobble: @@ -374,10 +385,13 @@ def gps_webhook(request): except TypeError: data_dict = request.data - # For making things easier to build new input processors - if getattr(settings, "DUMP_REQUEST_DATA", False): - json_data = json.dumps(data_dict, indent=4) - logger.debug(f"{json_data}") + logger.info( + "[geolocation_webhook] called", + extra={ + "post_data": data_dict, + "user_id": 1, + } + ) # TODO Fix this so we have to authenticate! user_id = 1