mirror of
https://github.com/Dispatcharr/Dispatcharr.git
synced 2026-01-23 10:45:27 +00:00
Properly track current stream id during stream switches.
This commit is contained in:
parent
9e99de77ec
commit
d59c8a9e33
2 changed files with 15 additions and 4 deletions
|
|
@ -181,7 +181,7 @@ class ChannelService:
|
|||
old_url = manager.url
|
||||
|
||||
# Update the stream
|
||||
success = manager.update_url(new_url)
|
||||
success = manager.update_url(new_url, stream_id)
|
||||
logger.info(f"Stream URL changed from {old_url} to {new_url}, result: {success}")
|
||||
|
||||
result.update({
|
||||
|
|
@ -440,6 +440,9 @@ class ChannelService:
|
|||
if m3u_profile_id:
|
||||
metadata[ChannelMetadataField.M3U_PROFILE] = str(m3u_profile_id)
|
||||
|
||||
# Also update the stream switch time field
|
||||
metadata[ChannelMetadataField.STREAM_SWITCH_TIME] = str(time.time())
|
||||
|
||||
# Use the appropriate method based on the key type
|
||||
if key_type == 'hash':
|
||||
proxy_server.redis_client.hset(metadata_key, mapping=metadata)
|
||||
|
|
|
|||
|
|
@ -544,7 +544,7 @@ class StreamManager:
|
|||
# Set running to false to ensure thread exits
|
||||
self.running = False
|
||||
|
||||
def update_url(self, new_url):
|
||||
def update_url(self, new_url, stream_id=None):
|
||||
"""Update stream URL and reconnect with proper cleanup for both HTTP and transcode sessions"""
|
||||
if new_url == self.url:
|
||||
logger.info(f"URL unchanged: {new_url}")
|
||||
|
|
@ -568,6 +568,14 @@ class StreamManager:
|
|||
self.url = new_url
|
||||
self.connected = False
|
||||
|
||||
# Update stream ID if provided
|
||||
if stream_id:
|
||||
old_stream_id = self.current_stream_id
|
||||
self.current_stream_id = stream_id
|
||||
# Add stream ID to tried streams for proper tracking
|
||||
self.tried_stream_ids.add(stream_id)
|
||||
logger.info(f"Updated stream ID from {old_stream_id} to {stream_id} for channel {self.buffer.channel_id}")
|
||||
|
||||
# Reset retry counter to allow immediate reconnect
|
||||
self.retry_count = 0
|
||||
|
||||
|
|
@ -1005,7 +1013,7 @@ class StreamManager:
|
|||
logger.info(f"Stream metadata updated for channel {self.channel_id} to stream ID {stream_id}")
|
||||
|
||||
# IMPORTANT: Just update the URL, don't stop the channel or release resources
|
||||
switch_result = self.update_url(new_url)
|
||||
switch_result = self.update_url(new_url, stream_id)
|
||||
if not switch_result:
|
||||
logger.error(f"Failed to update URL for stream ID {stream_id}")
|
||||
return False
|
||||
|
|
@ -1015,4 +1023,4 @@ class StreamManager:
|
|||
|
||||
except Exception as e:
|
||||
logger.error(f"Error trying next stream for channel {self.channel_id}: {e}", exc_info=True)
|
||||
return False
|
||||
return False
|
||||
Loading…
Add table
Add a link
Reference in a new issue