Merge branch 'dev' of https://github.com/Dispatcharr/Dispatcharr into proxy-settings

This commit is contained in:
SergeantPanda 2025-06-12 10:45:44 -05:00
commit ada1d51aaa
79 changed files with 6726 additions and 3193 deletions

View file

@ -2,25 +2,24 @@
from django.db import models
from django.utils.text import slugify
class UserAgent(models.Model):
name = models.CharField(
max_length=512,
unique=True,
help_text="The User-Agent name."
max_length=512, unique=True, help_text="The User-Agent name."
)
user_agent = models.CharField(
max_length=512,
unique=True,
help_text="The complete User-Agent string sent by the client."
help_text="The complete User-Agent string sent by the client.",
)
description = models.CharField(
max_length=255,
blank=True,
help_text="An optional description of the client or device type."
help_text="An optional description of the client or device type.",
)
is_active = models.BooleanField(
default=True,
help_text="Whether this user agent is currently allowed/recognized."
help_text="Whether this user agent is currently allowed/recognized.",
)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
@ -28,31 +27,34 @@ class UserAgent(models.Model):
def __str__(self):
return self.name
PROXY_PROFILE_NAME = 'Proxy'
REDIRECT_PROFILE_NAME = 'Redirect'
PROXY_PROFILE_NAME = "Proxy"
REDIRECT_PROFILE_NAME = "Redirect"
class StreamProfile(models.Model):
name = models.CharField(max_length=255, help_text="Name of the stream profile")
command = models.CharField(
max_length=255,
help_text="Command to execute (e.g., 'yt.sh', 'streamlink', or 'vlc')",
blank=True
blank=True,
)
parameters = models.TextField(
help_text="Command-line parameters. Use {userAgent} and {streamUrl} as placeholders.",
blank=True
blank=True,
)
locked = models.BooleanField(
default=False,
help_text="Protected - can't be deleted or modified"
default=False, help_text="Protected - can't be deleted or modified"
)
is_active = models.BooleanField(
default=True, help_text="Whether this profile is active"
)
is_active = models.BooleanField(default=True, help_text="Whether this profile is active")
user_agent = models.ForeignKey(
"UserAgent",
on_delete=models.SET_NULL,
null=True,
blank=True,
help_text="Optional user agent to use. If not set, you can fall back to a default."
help_text="Optional user agent to use. If not set, you can fall back to a default.",
)
def __str__(self):
@ -77,7 +79,9 @@ class StreamProfile(models.Model):
new_value = new_value.pk
if field_name not in allowed_fields and orig_value != new_value:
raise ValidationError(f"Cannot modify {field_name} on a protected profile.")
raise ValidationError(
f"Cannot modify {field_name} on a protected profile."
)
super().save(*args, **kwargs)
@ -90,10 +94,14 @@ class StreamProfile(models.Model):
for field_name, new_value in kwargs.items():
if field_name not in allowed_fields:
raise ValidationError(f"Cannot modify {field_name} on a protected profile.")
raise ValidationError(
f"Cannot modify {field_name} on a protected profile."
)
# Ensure user_agent ForeignKey updates correctly
if field_name == "user_agent" and isinstance(new_value, cls._meta.get_field("user_agent").related_model):
if field_name == "user_agent" and isinstance(
new_value, cls._meta.get_field("user_agent").related_model
):
new_value = new_value.pk # Convert object to ID if needed
setattr(instance, field_name, new_value)
@ -122,7 +130,8 @@ class StreamProfile(models.Model):
# Split the command and iterate through each part to apply replacements
cmd = [self.command] + [
self._replace_in_part(part, replacements) for part in self.parameters.split()
self._replace_in_part(part, replacements)
for part in self.parameters.split()
]
return cmd
@ -134,11 +143,13 @@ class StreamProfile(models.Model):
return part
DEFAULT_USER_AGENT_KEY= slugify("Default User-Agent")
DEFAULT_USER_AGENT_KEY = slugify("Default User-Agent")
DEFAULT_STREAM_PROFILE_KEY = slugify("Default Stream Profile")
STREAM_HASH_KEY = slugify("M3U Hash Key")
PREFERRED_REGION_KEY = slugify("Preferred Region")
AUTO_IMPORT_MAPPED_FILES = slugify("Auto-Import Mapped Files")
NETWORK_ACCESS = slugify("Network Access")
class CoreSettings(models.Model):
key = models.CharField(