mirror of
https://github.com/Dispatcharr/Dispatcharr.git
synced 2026-01-23 02:35:14 +00:00
fetch default user-agent if none is set on m3u
This commit is contained in:
parent
795da9065f
commit
36b281697c
2 changed files with 10 additions and 1 deletions
|
|
@ -5,6 +5,7 @@ import re
|
|||
from django.dispatch import receiver
|
||||
from apps.channels.models import StreamProfile
|
||||
from django_celery_beat.models import PeriodicTask
|
||||
from core.models import CoreSettings, UserAgent
|
||||
|
||||
CUSTOM_M3U_ACCOUNT_NAME="custom"
|
||||
|
||||
|
|
@ -100,6 +101,13 @@ class M3UAccount(models.Model):
|
|||
def get_custom_account(cls):
|
||||
return cls.objects.get(name=CUSTOM_M3U_ACCOUNT_NAME, locked=True)
|
||||
|
||||
def get_user_agent(self):
|
||||
user_agent = self.user_agent
|
||||
if not user_agent:
|
||||
user_agent = UserAgent.objects.get(id=CoreSettings.get_default_user_agent_id())
|
||||
|
||||
return user_agent
|
||||
|
||||
# def get_channel_groups(self):
|
||||
# return ChannelGroup.objects.filter(m3u_account__m3u_account=self)
|
||||
|
||||
|
|
|
|||
|
|
@ -35,7 +35,8 @@ def fetch_m3u_lines(account, use_cache=False):
|
|||
"""Fetch M3U file lines efficiently."""
|
||||
if account.server_url:
|
||||
if not use_cache or not os.path.exists(file_path):
|
||||
headers = {"User-Agent": account.user_agent.user_agent}
|
||||
user_agent = account.get_user_agent()
|
||||
headers = {"User-Agent": user_agent.user_agent}
|
||||
logger.info(f"Fetching from URL {account.server_url}")
|
||||
try:
|
||||
response = requests.get(account.server_url, headers=headers, stream=True)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue