From 1dd368278ca733b9976b4a01a02df438c6d10eeb Mon Sep 17 00:00:00 2001 From: dekzter Date: Fri, 13 Mar 2026 09:57:22 -0400 Subject: [PATCH] reverted value checking for consistency, added in user id to client info --- .../migrations/0004_user_stream_priority.py | 18 ----- apps/proxy/ts_proxy/channel_status.py | 70 +++++++++++++++---- apps/proxy/ts_proxy/client_manager.py | 3 +- apps/proxy/ts_proxy/server.py | 7 +- 4 files changed, 59 insertions(+), 39 deletions(-) delete mode 100644 apps/accounts/migrations/0004_user_stream_priority.py diff --git a/apps/accounts/migrations/0004_user_stream_priority.py b/apps/accounts/migrations/0004_user_stream_priority.py deleted file mode 100644 index 35c8bbae..00000000 --- a/apps/accounts/migrations/0004_user_stream_priority.py +++ /dev/null @@ -1,18 +0,0 @@ -# Generated by Django 5.2.4 on 2025-10-21 19:32 - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('accounts', '0003_alter_user_custom_properties'), - ] - - operations = [ - migrations.AddField( - model_name='user', - name='stream_priority', - field=models.IntegerField(default=0, help_text='Priority level for streaming tasks. Lower values indicate higher priority.'), - ), - ] diff --git a/apps/proxy/ts_proxy/channel_status.py b/apps/proxy/ts_proxy/channel_status.py index 4ac8f63f..ffb6be2c 100644 --- a/apps/proxy/ts_proxy/channel_status.py +++ b/apps/proxy/ts_proxy/channel_status.py @@ -265,22 +265,64 @@ class ChannelStatus: } # Add FFmpeg stream information - info['video_codec'] = metadata.get(ChannelMetadataField.VIDEO_CODEC) - info['resolution'] = metadata.get(ChannelMetadataField.RESOLUTION) - info['source_fps'] = metadata.get(ChannelMetadataField.SOURCE_FPS) - info['pixel_format'] = metadata.get(ChannelMetadataField.PIXEL_FORMAT) - info['source_bitrate'] = metadata.get(ChannelMetadataField.SOURCE_BITRATE) - info['audio_codec'] = metadata.get(ChannelMetadataField.AUDIO_CODEC) - info['sample_rate'] = metadata.get(ChannelMetadataField.SAMPLE_RATE) - info['audio_channels'] = metadata.get(ChannelMetadataField.AUDIO_CHANNELS) - info['audio_bitrate'] = metadata.get(ChannelMetadataField.AUDIO_BITRATE) + video_codec = metadata.get(ChannelMetadataField.VIDEO_CODEC) + if video_codec: + info['video_codec'] = video_codec + + resolution = metadata.get(ChannelMetadataField.RESOLUTION) + if resolution: + info['resolution'] = resolution + + source_fps = metadata.get(ChannelMetadataField.SOURCE_FPS) + if source_fps: + info['source_fps'] = source_fps + + pixel_format = metadata.get(ChannelMetadataField.PIXEL_FORMAT) + if pixel_format: + info['pixel_format'] = pixel_format + + source_bitrate = metadata.get(ChannelMetadataField.SOURCE_BITRATE) + if source_bitrate: + info['source_bitrate'] = source_bitrate + + audio_codec = metadata.get(ChannelMetadataField.AUDIO_CODEC) + if audio_codec: + info['audio_codec'] = audio_codec + + sample_rate = metadata.get(ChannelMetadataField.SAMPLE_RATE) + if sample_rate: + info['sample_rate'] = sample_rate + + audio_channels = metadata.get(ChannelMetadataField.AUDIO_CHANNELS) + if audio_channels: + info['audio_channels'] = audio_channels + + audio_bitrate = metadata.get(ChannelMetadataField.AUDIO_BITRATE) + if audio_bitrate: + info['audio_bitrate'] = audio_bitrate + # Add FFmpeg performance stats - info['ffmpeg_speed'] = metadata.get(ChannelMetadataField.FFMPEG_SPEED) - info['ffmpeg_fps'] = metadata.get(ChannelMetadataField.FFMPEG_FPS) - info['actual_fps'] = metadata.get(ChannelMetadataField.ACTUAL_FPS) - info['ffmpeg_bitrate'] = metadata.get(ChannelMetadataField.FFMPEG_BITRATE) - info['stream_type'] = metadata.get(ChannelMetadataField.STREAM_TYPE) + ffmpeg_speed = metadata.get(ChannelMetadataField.FFMPEG_SPEED) + if ffmpeg_speed: + info['ffmpeg_speed'] = ffmpeg_speed + + ffmpeg_fps = metadata.get(ChannelMetadataField.FFMPEG_FPS) + if ffmpeg_fps: + info['ffmpeg_fps'] = ffmpeg_fps + + actual_fps = metadata.get(ChannelMetadataField.ACTUAL_FPS) + if actual_fps: + info['actual_fps'] = actual_fps + + ffmpeg_bitrate = metadata.get(ChannelMetadataField.FFMPEG_BITRATE) + if ffmpeg_bitrate: + info['ffmpeg_bitrate'] = ffmpeg_bitrate + + stream_type = metadata.get(ChannelMetadataField.STREAM_TYPE) + if stream_type: + info['stream_type'] = stream_type + return info diff --git a/apps/proxy/ts_proxy/client_manager.py b/apps/proxy/ts_proxy/client_manager.py index 394ad5ea..c0e5ab0b 100644 --- a/apps/proxy/ts_proxy/client_manager.py +++ b/apps/proxy/ts_proxy/client_manager.py @@ -247,7 +247,8 @@ class ClientManager: "connected_at": current_time, "last_active": current_time, "worker_id": self.worker_id or "unknown", - "user_level": user.user_level if user is not None else 100, # default to a high value since no user means the non-user specific M3U/HDHR + "user_id": str(user.id) if user is not None else "unknown", + # "user_level": user.user_level if user is not None else 100, # default to a high value since no user means the non-user specific M3U/HDHR } try: diff --git a/apps/proxy/ts_proxy/server.py b/apps/proxy/ts_proxy/server.py index 1999b491..4c51768a 100644 --- a/apps/proxy/ts_proxy/server.py +++ b/apps/proxy/ts_proxy/server.py @@ -459,10 +459,6 @@ class ProxyServer: lock_key = RedisKeys.channel_owner(channel_id) current = self.redis_client.get(lock_key) -<<<<<<< HEAD - # Only extend if we're still the owner - if current and current == self.worker_id: -======= if current is None: # Key expired — re-acquire if we have the stream_manager if channel_id in self.stream_managers: @@ -476,8 +472,7 @@ class ProxyServer: return False return False - if current.decode('utf-8') == self.worker_id: ->>>>>>> origin/dev + if current == self.worker_id: self.redis_client.expire(lock_key, ttl) return True