[scrobbles] Add action parsing to scrobble url parsing
This also elaborates on the web scrobbler endpoint, though it does not actually work at this time. But I'm tired of carrying this around in stashes, so we'll push it and fix it later.
This commit is contained in:
@ -98,8 +98,9 @@ class RecentScrobbleList(ListView):
|
|||||||
user = self.request.user
|
user = self.request.user
|
||||||
if user.is_authenticated:
|
if user.is_authenticated:
|
||||||
if scrobble_url := self.request.GET.get("scrobble_url", ""):
|
if scrobble_url := self.request.GET.get("scrobble_url", ""):
|
||||||
|
action = self.request.GET.get("action", "")
|
||||||
scrobble = manual_scrobble_from_url(
|
scrobble = manual_scrobble_from_url(
|
||||||
scrobble_url, self.request.user.id
|
scrobble_url, self.request.user.id, action
|
||||||
)
|
)
|
||||||
return HttpResponseRedirect(scrobble.redirect_url(user.id))
|
return HttpResponseRedirect(scrobble.redirect_url(user.id))
|
||||||
return super().get(*args, **kwargs)
|
return super().get(*args, **kwargs)
|
||||||
@ -314,28 +315,64 @@ def lastfm_import(request):
|
|||||||
|
|
||||||
return HttpResponseRedirect(request.META.get("HTTP_REFERER"))
|
return HttpResponseRedirect(request.META.get("HTTP_REFERER"))
|
||||||
|
|
||||||
|
|
||||||
@csrf_exempt
|
@csrf_exempt
|
||||||
@api_view(["POST"])
|
@api_view(["POST"])
|
||||||
def web_scrobbler_webhook(request):
|
def web_scrobbler_webhook(request):
|
||||||
post_data = request.data
|
"""Note, this does not work as implemented. For some reason the web
|
||||||
|
scrobbler tool kicks back a bad response code and does not seem to POST data
|
||||||
|
as expected.
|
||||||
|
|
||||||
|
"""
|
||||||
|
user_id = request.user.id
|
||||||
|
|
||||||
logger.info(
|
logger.info(
|
||||||
"[web_scrobbler_webhook] called",
|
"[web_scrobbler_webhook] called",
|
||||||
extra={
|
extra={
|
||||||
"post_data": post_data,
|
"post_data": request.POST,
|
||||||
"user_id": request.user.id,
|
"user_id": user_id,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
# TODO Figure out why auth isn't working
|
youtube_id = request.POST.get("uniqueID")
|
||||||
scrobble = web_scrobbler_scrobble_media(post_data, 1)
|
if not youtube_id:
|
||||||
|
logger.warning(
|
||||||
|
"[web_scrobbler_webhook] failed",
|
||||||
|
extra={
|
||||||
|
"youtube_id": youtube_id,
|
||||||
|
"user_id": user_id,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
return JsonResponse(
|
||||||
|
{"errors": ["No youtube ID provided"]}, status=status.HTTP_200_OK
|
||||||
|
)
|
||||||
|
|
||||||
|
playing_state = "started"
|
||||||
|
if request.POST.get("isPlaying") == "false":
|
||||||
|
playing_state = "stopped"
|
||||||
|
scrobble = web_scrobbler_scrobble_media(
|
||||||
|
youtube_id, user_id, status=playing_state
|
||||||
|
)
|
||||||
if not scrobble:
|
if not scrobble:
|
||||||
return Response({}, status=status.HTTP_200_OK)
|
logger.warning(
|
||||||
|
"[web_scrobbler_webhook] failed",
|
||||||
|
extra={
|
||||||
|
"youtube_id": youtube_id,
|
||||||
|
"user_id": user_id,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
return JsonResponse(
|
||||||
|
{"errors": ["No scrobble found for user or video"]},
|
||||||
|
status=status.HTTP_200_OK,
|
||||||
|
)
|
||||||
|
|
||||||
logger.info(
|
logger.info(
|
||||||
"[jellyfin_webhook] finished",
|
"[web_scrobbler_webhook] finished",
|
||||||
extra={"scrobble_id": scrobble.id},
|
extra={"scrobble_id": scrobble.id},
|
||||||
)
|
)
|
||||||
return Response({"scrobble_id": scrobble.id}, status=status.HTTP_200_OK)
|
return JsonResponse(
|
||||||
|
{"scrobble_id": scrobble.id}, status=status.HTTP_200_OK
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@csrf_exempt
|
@csrf_exempt
|
||||||
@permission_classes([IsAuthenticated])
|
@permission_classes([IsAuthenticated])
|
||||||
@ -412,7 +449,7 @@ def gps_webhook(request):
|
|||||||
extra={
|
extra={
|
||||||
"post_data": data_dict,
|
"post_data": data_dict,
|
||||||
"user_id": 1,
|
"user_id": 1,
|
||||||
}
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
# TODO Fix this so we have to authenticate!
|
# TODO Fix this so we have to authenticate!
|
||||||
|
|||||||
Reference in New Issue
Block a user