mirror of
https://github.com/Dispatcharr/Dispatcharr.git
synced 2026-07-18 09:06:06 +00:00
Per-field channel overrides for auto-synced channels, hide-from-output flag, range-bounded auto-numbering with re-pack, multi-stream channel safety, multi-provider shared-range merging, and an across-the-board move from per-row sync writes to bulk operations. Migrations: apps/channels: 0036_channeloverride_and_user_hidden, 0037_backfill_auto_created_by_null, 0038_channelgroupm3uaccount_auto_sync_channel_end, 0039_channel_channel_number_nullable apps/m3u: 0020_m3uaccount_auto_cleanup_unused_channels See CHANGELOG.md for the full commit log
37 lines
1.2 KiB
Python
37 lines
1.2 KiB
Python
import threading
|
|
|
|
lock = threading.Lock()
|
|
# Dictionary to track usage: {account_id: current_usage}
|
|
active_streams_map = {}
|
|
|
|
|
|
def format_channel_number(value, empty=""):
|
|
"""Display formatting for an effective channel_number. Returns int for
|
|
whole-valued floats (so ``123.0`` renders as ``123``), the float as-is
|
|
for fractional values, or ``empty`` when the value is ``None``.
|
|
"""
|
|
if value is None:
|
|
return empty
|
|
if value == int(value):
|
|
return int(value)
|
|
return value
|
|
|
|
def increment_stream_count(account):
|
|
with lock:
|
|
current_usage = active_streams_map.get(account.id, 0)
|
|
current_usage += 1
|
|
active_streams_map[account.id] = current_usage
|
|
account.active_streams = current_usage
|
|
account.save(update_fields=['active_streams'])
|
|
|
|
def decrement_stream_count(account):
|
|
with lock:
|
|
current_usage = active_streams_map.get(account.id, 0)
|
|
if current_usage > 0:
|
|
current_usage -= 1
|
|
if current_usage == 0:
|
|
del active_streams_map[account.id]
|
|
else:
|
|
active_streams_map[account.id] = current_usage
|
|
account.active_streams = current_usage
|
|
account.save(update_fields=['active_streams'])
|