[scrobbles] Allow skipping checks for existing scrobbles
This commit is contained in:
@ -1087,6 +1087,7 @@ class Scrobble(TimeStampedModel):
|
|||||||
key = media_class_to_foreign_key(media.__class__.__name__)
|
key = media_class_to_foreign_key(media.__class__.__name__)
|
||||||
media_query = models.Q(**{key: media})
|
media_query = models.Q(**{key: media})
|
||||||
scrobble_data[key + "_id"] = media.id
|
scrobble_data[key + "_id"] = media.id
|
||||||
|
skip_in_progress_check = kwargs.get("skip_in_progress_check", False)
|
||||||
|
|
||||||
# Find our last scrobble of this media item (track, video, etc)
|
# Find our last scrobble of this media item (track, video, etc)
|
||||||
scrobble = (
|
scrobble = (
|
||||||
@ -1110,27 +1111,31 @@ class Scrobble(TimeStampedModel):
|
|||||||
)
|
)
|
||||||
return scrobble
|
return scrobble
|
||||||
|
|
||||||
logger.info(
|
if not skip_in_progress_check:
|
||||||
f"[create_or_update] check for existing scrobble to update ",
|
logger.info(
|
||||||
extra={
|
f"[create_or_update] check for existing scrobble to update ",
|
||||||
"scrobble_id": scrobble.id if scrobble else None,
|
extra={
|
||||||
"media_type": mtype,
|
"scrobble_id": scrobble.id if scrobble else None,
|
||||||
"media_id": media.id,
|
"media_type": mtype,
|
||||||
"scrobble_data": scrobble_data,
|
"media_id": media.id,
|
||||||
},
|
"scrobble_data": scrobble_data,
|
||||||
)
|
},
|
||||||
scrobble_data["playback_status"] = scrobble_data.pop("status", None)
|
)
|
||||||
# If it's marked as stopped, send it through our update mechanism, which will complete it
|
scrobble_data["playback_status"] = scrobble_data.pop(
|
||||||
if scrobble and (
|
"status", None
|
||||||
scrobble.can_be_updated
|
)
|
||||||
or scrobble_data["playback_status"] == "stopped"
|
# If it's marked as stopped, send it through our update mechanism, which will complete it
|
||||||
):
|
if scrobble and (
|
||||||
if "log" in scrobble_data.keys() and scrobble.log:
|
scrobble.can_be_updated
|
||||||
scrobble_data["log"] = scrobble.log | scrobble_data["log"]
|
or scrobble_data["playback_status"] == "stopped"
|
||||||
return scrobble.update(scrobble_data)
|
):
|
||||||
|
if "log" in scrobble_data.keys() and scrobble.log:
|
||||||
|
scrobble_data["log"] = scrobble.log | scrobble_data["log"]
|
||||||
|
return scrobble.update(scrobble_data)
|
||||||
|
|
||||||
|
# Discard status before creating
|
||||||
|
scrobble_data.pop("playback_status")
|
||||||
|
|
||||||
# Discard status before creating
|
|
||||||
scrobble_data.pop("playback_status")
|
|
||||||
logger.info(
|
logger.info(
|
||||||
f"[scrobbling] creating new scrobble",
|
f"[scrobbling] creating new scrobble",
|
||||||
extra={
|
extra={
|
||||||
|
|||||||
Reference in New Issue
Block a user