Skip to content

Use the defined User-Agent in Xtream requests #381

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions usr/lib/hypnotix/hypnotix.py
Original file line number Diff line number Diff line change
Expand Up @@ -1612,6 +1612,7 @@ def reload(self, page=None, refresh=False):
provider.password,
provider.url,
hide_adult_content=False,
user_agent=self.settings.get_string("user-agent"),
cache_path=PROVIDERS_PATH,
)
if self.x.auth_data != {}:
Expand Down
8 changes: 6 additions & 2 deletions usr/lib/hypnotix/xtream.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ class XTream:
server = ""
username = ""
password = ""
user_agent = ""

live_type = "Live"
vod_type = "VOD"
Expand Down Expand Up @@ -293,6 +294,7 @@ def __init__(
provider_url: str,
hide_adult_content: bool = False,
cache_path: str = "",
user_agent: str = "",
):
"""Initialize Xtream Class

Expand All @@ -302,6 +304,7 @@ def __init__(
provider_password (str): Password of the IPTV provider
provider_url (str): URL of the IPTV provider
hide_adult_content(bool): When `True` hide stream that are marked for adult
user_agent (str): User-Agent for HTTP requests
cache_path (str, optional): Location where to save loaded files. Defaults to empty string.

Returns: XTream Class Instance
Expand All @@ -316,6 +319,7 @@ def __init__(
self.name = provider_name
self.cache_path = cache_path
self.hide_adult_content = hide_adult_content
self.user_agent = user_agent

# if the cache_path is specified, test that it is a directory
if self.cache_path != "":
Expand Down Expand Up @@ -429,7 +433,7 @@ def authenticate(self):
self.auth_data = {}
try:
# Request authentication, wait 4 seconds maximum
r = requests.get(self.get_authenticate_URL(), timeout=(4))
r = requests.get(self.get_authenticate_URL(), timeout=(4), headers={'User-Agent': self.user_agent })
# If the answer is ok, process data and change state
if r.ok:
self.auth_data = r.json()
Expand Down Expand Up @@ -742,7 +746,7 @@ def _get_request(self, URL: str, timeout: Tuple = (2, 15)):
[type]: JSON dictionary of the loaded data, or None
"""
try:
r = requests.get(URL, timeout=timeout)
r = requests.get(URL, timeout=timeout, headers={'User-Agent': self.user_agent })
if r.status_code == 200:
return r.json()

Expand Down