Merge pull request #565 from ragchuck:enable-rtsp

feat: added support for rtsp
This commit is contained in:
SergeantPanda 2025-11-11 17:29:03 -06:00 committed by GitHub
commit a7f449f746
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 21 additions and 10 deletions

View file

@ -219,6 +219,10 @@ def fetch_m3u_lines(account, use_cache=False):
# Has HTTP URLs, might be a simple M3U without headers
is_valid_m3u = True
logger.info("Content validated as M3U: contains HTTP URLs")
elif any(line.strip().startswith('rtsp') for line in content_lines):
# Has HTTP URLs, might be a simple M3U without headers
is_valid_m3u = True
logger.info("Content validated as M3U: contains RTSP URLs")
if not is_valid_m3u:
# Log what we actually received for debugging
@ -1399,7 +1403,7 @@ def refresh_m3u_groups(account_id, use_cache=False, full_refresh=False):
)
problematic_lines.append((line_index + 1, line[:200]))
elif extinf_data and line.startswith("http"):
elif extinf_data and (line.startswith("http") or line.startswith("rtsp")):
url_count += 1
# Associate URL with the last EXTINF line
extinf_data[-1]["url"] = line

View file

@ -33,6 +33,7 @@ class EventType:
# Stream types
class StreamType:
HLS = "hls"
RTSP = "rtsp"
TS = "ts"
UNKNOWN = "unknown"

View file

@ -228,10 +228,11 @@ class StreamManager:
# Check stream type before connecting
stream_type = detect_stream_type(self.url)
if self.transcode == False and stream_type == StreamType.HLS:
logger.info(f"Detected HLS stream: {self.url} for channel {self.channel_id}")
logger.info(f"HLS streams will be handled with FFmpeg for now - future version will support HLS natively for channel {self.channel_id}")
# Enable transcoding for HLS streams
if self.transcode == False and stream_type in (StreamType.HLS, StreamType.RTSP):
stream_type_name = "HLS" if stream_type == StreamType.HLS else "RTSP/RTP"
logger.info(f"Detected {stream_type_name} stream: {self.url} for channel {self.channel_id}")
logger.info(f"{stream_type_name} streams require FFmpeg for channel {self.channel_id}")
# Enable transcoding for HLS and RTSP/RTP streams
self.transcode = True
# We'll override the stream profile selection with ffmpeg in the transcoding section
self.force_ffmpeg = True

View file

@ -7,19 +7,23 @@ logger = logging.getLogger("ts_proxy")
def detect_stream_type(url):
"""
Detect if stream URL is HLS or TS format.
Detect if stream URL is HLS, RTSP/RTP, or TS format.
Args:
url (str): The stream URL to analyze
Returns:
str: 'hls' or 'ts' depending on detected format
str: 'hls', 'rtsp', or 'ts' depending on detected format
"""
if not url:
return 'unknown'
url_lower = url.lower()
# Check for RTSP/RTP streams first (requires FFmpeg)
if url_lower.startswith('rtsp://') or url_lower.startswith('rtp://'):
return 'rtsp'
# Look for common HLS indicators
if (url_lower.endswith('.m3u8') or
'.m3u8?' in url_lower or

View file

@ -377,12 +377,13 @@ def validate_flexible_url(value):
import re
# More flexible pattern for non-FQDN hostnames with paths
# Matches: http://hostname, http://hostname/, http://hostname:port/path/to/file.xml
non_fqdn_pattern = r'^https?://[a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?(\:[0-9]+)?(/[^\s]*)?$'
# Matches: http://hostname, https://hostname/, http://hostname:port/path/to/file.xml, rtp://192.168.2.1, rtsp://192.168.178.1
# Also matches FQDNs for rtsp/rtp protocols: rtsp://FQDN/path?query=value
non_fqdn_pattern = r'^(rts?p|https?)://([a-zA-Z0-9]([a-zA-Z0-9\-\.]{0,61}[a-zA-Z0-9])?|[0-9.]+)?(\:[0-9]+)?(/[^\s]*)?$'
non_fqdn_match = re.match(non_fqdn_pattern, value)
if non_fqdn_match:
return # Accept non-FQDN hostnames
return # Accept non-FQDN hostnames and rtsp/rtp URLs
# If it doesn't match our flexible patterns, raise the original error
raise ValidationError("Enter a valid URL.")