MCPcopy Create free account
hub / github.com/Dispatcharr/Dispatcharr / dispatch_event_system

Function dispatch_event_system

core/utils.py:708–788  ·  view source on GitHub ↗
(event_type, channel_id=None, channel_name=None, **details)

Source from the content-addressed store, hash-verified

706 raise ValidationError("Enter a valid URL.")
707
708def dispatch_event_system(event_type, channel_id=None, channel_name=None, **details):
709 from django.db import close_old_connections
710
711 try:
712 from apps.connect.utils import trigger_event
713 from apps.channels.models import Channel, Stream
714 from core.models import StreamProfile
715 from core.utils import RedisClient
716
717 payload = dict(details)
718
719 channel_obj = None
720 if channel_id:
721 try:
722 channel_obj = Channel.objects.get(uuid=channel_id)
723 payload["channel_name"] = channel_obj.name
724 except Exception:
725 payload["channel_name"] = channel_name or None
726 else:
727 payload["channel_name"] = channel_name or None
728
729 # Resolve current stream info
730 stream_id = details.get("stream_id")
731 stream_obj = None
732 if not stream_id and channel_obj:
733 try:
734 redis = RedisClient.get_client()
735 sid = redis.get(f"channel_stream:{channel_obj.id}")
736 if sid:
737 stream_id = int(sid)
738 except Exception:
739 stream_id = None
740
741 if stream_id:
742 try:
743 stream_obj = Stream.objects.get(id=stream_id)
744 except Exception:
745 stream_obj = None
746
747 # Populate stream details
748 payload["stream_name"] = getattr(stream_obj, "name", None)
749 payload["stream_url"] = getattr(stream_obj, "url", None)
750
751 # Channel URL: use stream URL as best-effort
752 payload["channel_url"] = payload.get("stream_url")
753
754 # Provider name from M3U account
755 provider_name = None
756 try:
757 if stream_obj and stream_obj.m3u_account:
758 provider_name = stream_obj.m3u_account.name
759 except Exception:
760 provider_name = None
761 payload["provider_name"] = provider_name
762
763 # Profile used
764 profile_used = None
765 try:

Callers 1

_runFunction · 0.85

Calls 5

trigger_eventFunction · 0.90
get_clientMethod · 0.80
keysMethod · 0.80
getMethod · 0.45
filterMethod · 0.45

Tested by

no test coverage detected