[scrobbles] Fix log data messiness with Jellyfin and Mopidy

This commit is contained in:
2026-03-11 21:30:38 -04:00
parent 6d5ebb68e3
commit 93666cec54

View File

@ -77,6 +77,12 @@ def mopidy_scrobble_media(post_data: dict, user_id: int) -> Scrobble:
media_obj = PodcastEpisode.find_or_create(**parsed_data)
else:
# TODO this kind of sucks, there's gotta be a way to get this in one shot
media_obj = Track.find_or_create(
title=post_data.get("name", ""),
artist_name=post_data.get("artist", ""),
album_name=post_data.get("album", ""),
run_time_seconds=post_data.get("run_time", 900000),
)
try:
album_id = (
Album.objects.filter(name=post_data.get("album", ""))
@ -85,12 +91,6 @@ def mopidy_scrobble_media(post_data: dict, user_id: int) -> Scrobble:
)
except Exception:
pass
media_obj = Track.find_or_create(
title=post_data.get("name", ""),
artist_name=post_data.get("artist", ""),
album_name=post_data.get("album", ""),
run_time_seconds=post_data.get("run_time", 900000),
)
log = {}
try:
@ -144,6 +144,7 @@ def jellyfin_scrobble_media(
post_data.get(JELLYFIN_POST_KEYS.get("PLAYBACK_POSITION_TICKS"), 1)
/ 10000000
)
album_id = None
if media_type == Scrobble.MediaType.VIDEO:
imdb_id = post_data.get("Provider_imdb", "")
media_obj = Video.find_or_create(imdb_id)
@ -156,6 +157,14 @@ def jellyfin_scrobble_media(
post_data.get("RunTime", 900000)
),
)
try:
album_id = (
Album.objects.filter(name=post_data.get("Album", ""))
.first()
.id
)
except Exception:
pass
# A hack because we don't worry about updating music ... we either finish it or we don't
playback_position_seconds = 0
@ -172,13 +181,17 @@ def jellyfin_scrobble_media(
elif post_data.get("NotificationType") == "PlaybackStop":
playback_status = "stopped"
log = {"raw_data": post_data}
if album_id:
log["album_id"] = album_id
return media_obj.scrobble_for_user(
user_id,
source=post_data.get(JELLYFIN_POST_KEYS.get("SOURCE")),
source_id=post_data.get(JELLYFIN_POST_KEYS.get("MEDIA_SOURCE_ID")),
playback_position_seconds=playback_position_seconds,
status=playback_status,
log={"album_id": media_obj.album_id, "raw_data": post_data},
log=log,
)