[notifications] Add stop notification utility
This commit is contained in:
@ -293,7 +293,7 @@ def deduplicate_tracks(commit=False):
|
||||
other.delete()
|
||||
|
||||
|
||||
def send_notifications_for_scrobble(scrobble_id):
|
||||
def send_start_notifications_for_scrobble(scrobble_id):
|
||||
from scrobbles.models import Scrobble
|
||||
|
||||
scrobble = Scrobble.objects.get(id=scrobble_id)
|
||||
@ -310,6 +310,35 @@ def send_notifications_for_scrobble(scrobble_id):
|
||||
"Title": scrobble.media_obj.strings.verb,
|
||||
"Priority": scrobble.media_obj.strings.priority,
|
||||
"Tags": scrobble.media_obj.strings.tags,
|
||||
"Click": scrobble.media_obj.get_absolute_url(),
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
def send_stop_notifications_for_scrobble(scrobble_id):
|
||||
from scrobbles.models import Scrobble
|
||||
|
||||
scrobble = Scrobble.objects.get(id=scrobble_id)
|
||||
scrobble_surpassed_media_runtime = (
|
||||
timezone.now() - scrobble.timestamp
|
||||
).seconds > scrobble.media_obj.run_time_seconds
|
||||
if not scrobble_surpassed_media_runtime:
|
||||
logger.info("scrobble not surpassed media runtime")
|
||||
return
|
||||
|
||||
profile = scrobble.user.profile
|
||||
if profile and profile.ntfy_enabled and profile.ntfy_url:
|
||||
# TODO allow prority and tags to be configured in the profile
|
||||
notify_str = f"{scrobble.media_obj}"
|
||||
if scrobble.log and scrobble.log.get("description"):
|
||||
notify_str += f" - {scrobble.log.get('description')}"
|
||||
requests.post(
|
||||
profile.ntfy_url,
|
||||
data=notify_str.encode(encoding="utf-8"),
|
||||
headers={
|
||||
"Title": "Stop " scrobble.media_obj.strings.verb.lower() + "?",
|
||||
"Priority": scrobble.media_obj.strings.priority,
|
||||
"Tags": scrobble.media_obj.strings.tags,
|
||||
"Click": scrobble.finish_url,
|
||||
},
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user