From 995ae3008cce50a68359c30c4360de03c57494fa Mon Sep 17 00:00:00 2001 From: dekzter Date: Mon, 5 May 2025 10:24:37 -0400 Subject: [PATCH] honor m3u account user-agent in xc client --- apps/m3u/tasks.py | 6 +++--- core/xtream_codes.py | 17 ++++++++++++----- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/apps/m3u/tasks.py b/apps/m3u/tasks.py index 5a6fbee3..db069947 100644 --- a/apps/m3u/tasks.py +++ b/apps/m3u/tasks.py @@ -261,7 +261,7 @@ def process_xc_category(account_id, batch, groups, hash_keys): streams_to_update = [] stream_hashes = {} - xc_client = XCClient(account.server_url, account.username, account.password) + xc_client = XCClient(account.server_url, account.username, account.password, account.get_user_agent()) for group_name, props in batch.items(): streams = xc_client.get_live_category_streams(props['xc_id']) for stream in streams: @@ -495,7 +495,7 @@ def refresh_m3u_groups(account_id, use_cache=False, full_refresh=False): xc_client = None if account.account_type == M3UAccount.Types.XC: - xc_client = XCClient(account.server_url, account.username, account.password) + xc_client = XCClient(account.server_url, account.username, account.password, account.get_user_agent()) try: xc_client.authenticate() except Exception as e: @@ -818,4 +818,4 @@ def send_m3u_update(account_id, action, progress, **kwargs): 'type': 'update', 'data': data } - ) \ No newline at end of file + ) diff --git a/core/xtream_codes.py b/core/xtream_codes.py index e79ec5e9..a1905539 100644 --- a/core/xtream_codes.py +++ b/core/xtream_codes.py @@ -4,22 +4,29 @@ class Client: host = "" username = "" password = "" + user_agent = "" - def __init__(self, host, username, password): + def __init__(self, host, username, password, user_agent): self.host = host self.username = username - self.password = password + self.password = user_agent def authenticate(self): - response = requests.get(f"{self.host}/player_api.php?username={self.username}&password={self.password}") + response = requests.get(f"{self.host}/player_api.php?username={self.username}&password={self.password}", headers={ + 'User-Agent': self.user_agent, + }) return response.json() def get_live_categories(self): - response = requests.get(f"{self.host}/player_api.php?username={self.username}&password={self.password}&action=get_live_categories") + response = requests.get(f"{self.host}/player_api.php?username={self.username}&password={self.password}&action=get_live_categories", headers={ + 'User-Agent': self.user_agent, + }) return response.json() def get_live_category_streams(self, category_id): - response = requests.get(f"{self.host}/player_api.php?username={self.username}&password={self.password}&action=get_live_streams&category_id={category_id}") + response = requests.get(f"{self.host}/player_api.php?username={self.username}&password={self.password}&action=get_live_streams&category_id={category_id}", headers={ + 'User-Agent': self.user_agent, + }) return response.json() def get_stream_url(self, stream_id):