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

Method get_segment

apps/proxy/hls_proxy/server.py:961–997  ·  view source on GitHub ↗

Serve individual MPEG-TS segments to clients. Args: channel_id: Unique identifier for the channel segment_name: Segment filename (e.g., '123.ts') Returns: Flask Response: - MPEG-TS segment data with vi

(self, channel_id: str, segment_name: str)

Source from the content-addressed store, hash-verified

959 return '', 500
960
961 def get_segment(self, channel_id: str, segment_name: str):
962 """
963 Serve individual MPEG-TS segments to clients.
964
965 Args:
966 channel_id: Unique identifier for the channel
967 segment_name: Segment filename (e.g., '123.ts')
968
969 Returns:
970 Flask Response:
971 - MPEG-TS segment data with video/MP2T content type
972 - 404 if segment or channel not found
973
974 Error Handling:
975 - Logs warning if segment not found
976 - Logs error on unexpected exceptions
977 - Returns 404 on any error
978 """
979 if channel_id not in self.stream_managers:
980 return 'Channel not found', 404
981
982 try:
983 # Record client activity
984 client_ip = request.remote_addr
985 self.client_managers[channel_id].record_activity(client_ip)
986
987 segment_id = int(segment_name.split('.')[0])
988 buffer = self.stream_buffers[channel_id]
989
990 with buffer_lock:
991 if segment_id in buffer:
992 return buffer[segment_id], 200 # Return content and status code
993
994 logging.warning(f"Segment {segment_id} not found for channel {channel_id}")
995 except Exception as e:
996 logging.error(f"Error serving segment {segment_name}: {e}")
997 return '', 404
998
999 def change_stream(self, channel_id: str):
1000 """

Callers

nothing calls this directly

Calls 1

record_activityMethod · 0.80

Tested by

no test coverage detected