diff --git a/StreamingCommunity/Api/Player/ddl.py b/StreamingCommunity/Api/Player/ddl.py index 4269209..851b752 100644 --- a/StreamingCommunity/Api/Player/ddl.py +++ b/StreamingCommunity/Api/Player/ddl.py @@ -10,7 +10,7 @@ from bs4 import BeautifulSoup # Internal utilities from StreamingCommunity.Util._jsonConfig import config_manager -from StreamingCommunity.Util.headers import get_headers +from StreamingCommunity.Util.headers import get_userAgent # Variable @@ -22,7 +22,7 @@ class VideoSource: """ Initializes the VideoSource object with default values. """ - self.headers = {'user-agent': get_headers()} + self.headers = {'user-agent': get_userAgent()} self.cookie = cookie def setup(self, url: str) -> None: diff --git a/StreamingCommunity/Api/Player/maxstream.py b/StreamingCommunity/Api/Player/maxstream.py index 3cb17b2..da19d19 100644 --- a/StreamingCommunity/Api/Player/maxstream.py +++ b/StreamingCommunity/Api/Player/maxstream.py @@ -12,7 +12,7 @@ from bs4 import BeautifulSoup # Internal utilities from StreamingCommunity.Util._jsonConfig import config_manager -from StreamingCommunity.Util.headers import get_headers +from StreamingCommunity.Util.headers import get_userAgent # Variable @@ -31,7 +31,7 @@ class VideoSource: self.redirect_url = None self.maxstream_url = None self.m3u8_url = None - self.headers = {'user-agent': get_headers()} + self.headers = {'user-agent': get_userAgent()} def get_redirect_url(self): """ @@ -78,7 +78,7 @@ class VideoSource: logging.warning("Anchor tag not found. Trying the alternative method.") headers = { 'origin': 'https://stayonline.pro', - 'user-agent': get_headers(), + 'user-agent': get_userAgent(), 'x-requested-with': 'XMLHttpRequest', } diff --git a/StreamingCommunity/Api/Player/supervideo.py b/StreamingCommunity/Api/Player/supervideo.py index 74f803a..610eeac 100644 --- a/StreamingCommunity/Api/Player/supervideo.py +++ b/StreamingCommunity/Api/Player/supervideo.py @@ -12,7 +12,7 @@ from bs4 import BeautifulSoup # Internal utilities from StreamingCommunity.Util._jsonConfig import config_manager -from StreamingCommunity.Util.headers import get_headers +from StreamingCommunity.Util.headers import get_userAgent # Variable @@ -30,7 +30,7 @@ class VideoSource: self.headers = { 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8', 'accept-language': 'it-IT,it;q=0.9,en-US;q=0.8,en;q=0.7', - 'User-Agent': get_headers() + 'User-Agent': get_userAgent() } self.client = httpx.Client() self.url = url diff --git a/StreamingCommunity/Api/Player/vixcloud.py b/StreamingCommunity/Api/Player/vixcloud.py index 8059599..09f5a24 100644 --- a/StreamingCommunity/Api/Player/vixcloud.py +++ b/StreamingCommunity/Api/Player/vixcloud.py @@ -11,7 +11,7 @@ from bs4 import BeautifulSoup # Internal utilities -from StreamingCommunity.Util.headers import get_headers +from StreamingCommunity.Util.headers import get_userAgent from StreamingCommunity.Util.console import console from StreamingCommunity.Util._jsonConfig import config_manager from .Helper.Vixcloud.util import WindowVideo, WindowParameter, StreamsCollection @@ -31,7 +31,7 @@ class VideoSource: - url (str): The URL of the streaming site. - is_series (bool): Flag for series or movie content """ - self.headers = {'user-agent': get_headers()} + self.headers = {'user-agent': get_userAgent()} self.url = url self.is_series = is_series @@ -180,7 +180,7 @@ class VideoSource: """ headers = { 'referer': url_to_download, - 'user-agent': get_headers(), + 'user-agent': get_userAgent(), } # API request to get video details @@ -199,7 +199,7 @@ class VideoSource: url=f'{self.url}/api/download/generate_link?scws_id={track["video_id"]}&rendition={track["quality"]}', headers={ 'referer': url_to_download, - 'user-agent': get_headers(), + 'user-agent': get_userAgent(), 'x-xsrf-token': config_manager.get("SITE", self.base_name)['extra']['x-xsrf-token'] }, cookies={ @@ -228,7 +228,7 @@ class VideoSourceAnime(VideoSource): Extends base VideoSource with anime-specific initialization """ - self.headers = {'user-agent': get_headers()} + self.headers = {'user-agent': get_userAgent()} self.url = url self.src_mp4 = None diff --git a/StreamingCommunity/Api/Site/1337xx/site.py b/StreamingCommunity/Api/Site/1337xx/site.py index c092564..1ba39b9 100644 --- a/StreamingCommunity/Api/Site/1337xx/site.py +++ b/StreamingCommunity/Api/Site/1337xx/site.py @@ -10,7 +10,7 @@ from bs4 import BeautifulSoup # Internal utilities from StreamingCommunity.Util.console import console from StreamingCommunity.Util._jsonConfig import config_manager -from StreamingCommunity.Util.headers import get_headers +from StreamingCommunity.Util.headers import get_userAgent from StreamingCommunity.Util.table import TVShowManager @@ -55,7 +55,7 @@ def title_search(word_to_search: str) -> int: try: response = httpx.get( url=f"{site_constant.FULL_URL}/search/{word_to_search}/1/", - headers={'user-agent': get_headers()}, + headers={'user-agent': get_userAgent()}, follow_redirects=True, timeout=max_timeout ) diff --git a/StreamingCommunity/Api/Site/1337xx/title.py b/StreamingCommunity/Api/Site/1337xx/title.py index e5f01b4..1679622 100644 --- a/StreamingCommunity/Api/Site/1337xx/title.py +++ b/StreamingCommunity/Api/Site/1337xx/title.py @@ -12,7 +12,7 @@ from bs4 import BeautifulSoup from StreamingCommunity.Util.console import console from StreamingCommunity.Util.os import os_manager from StreamingCommunity.Util.message import start_message -from StreamingCommunity.Util.headers import get_headers +from StreamingCommunity.Util.headers import get_userAgent from StreamingCommunity.Lib.Downloader import TOR_downloader @@ -44,7 +44,7 @@ def download_title(select_title: MediaItem): response = httpx.get( url=f"{site_constant.FULL_URL}{select_title.url}", headers={ - 'user-agent': get_headers() + 'user-agent': get_userAgent() }, follow_redirects=True ) diff --git a/StreamingCommunity/Api/Site/animeunity/util/ScrapeSerie.py b/StreamingCommunity/Api/Site/animeunity/util/ScrapeSerie.py index 608aefb..bf2221e 100644 --- a/StreamingCommunity/Api/Site/animeunity/util/ScrapeSerie.py +++ b/StreamingCommunity/Api/Site/animeunity/util/ScrapeSerie.py @@ -8,7 +8,7 @@ import httpx # Internal utilities -from StreamingCommunity.Util.headers import get_headers +from StreamingCommunity.Util.headers import get_userAgent from StreamingCommunity.Util._jsonConfig import config_manager from StreamingCommunity.Api.Player.Helper.Vixcloud.util import EpisodeManager, Episode @@ -27,7 +27,7 @@ class ScrapeSerieAnime: url (str): Url of the streaming site """ self.is_series = False - self.headers = {'user-agent': get_headers()} + self.headers = {'user-agent': get_userAgent()} self.url = url def setup(self, version: str = None, media_id: int = None, series_name: str = None): diff --git a/StreamingCommunity/Api/Site/cb01new/site.py b/StreamingCommunity/Api/Site/cb01new/site.py index 6023a90..05fe114 100644 --- a/StreamingCommunity/Api/Site/cb01new/site.py +++ b/StreamingCommunity/Api/Site/cb01new/site.py @@ -10,7 +10,7 @@ from bs4 import BeautifulSoup # Internal utilities from StreamingCommunity.Util.console import console from StreamingCommunity.Util._jsonConfig import config_manager -from StreamingCommunity.Util.headers import get_headers +from StreamingCommunity.Util.headers import get_userAgent from StreamingCommunity.Util.table import TVShowManager @@ -53,7 +53,7 @@ def title_search(word_to_search: str) -> int: response = httpx.get( url=f"{site_constant.FULL_URL}/?s={word_to_search}", - headers={'user-agent': get_headers()}, + headers={'user-agent': get_userAgent()}, timeout=max_timeout ) response.raise_for_status() diff --git a/StreamingCommunity/Api/Site/ddlstreamitaly/site.py b/StreamingCommunity/Api/Site/ddlstreamitaly/site.py index 7b297c9..9671f79 100644 --- a/StreamingCommunity/Api/Site/ddlstreamitaly/site.py +++ b/StreamingCommunity/Api/Site/ddlstreamitaly/site.py @@ -12,7 +12,7 @@ from bs4 import BeautifulSoup # Internal utilities from StreamingCommunity.Util.console import console from StreamingCommunity.Util._jsonConfig import config_manager -from StreamingCommunity.Util.headers import get_headers +from StreamingCommunity.Util.headers import get_userAgent from StreamingCommunity.Util.table import TVShowManager @@ -57,7 +57,7 @@ def title_search(word_to_search: str) -> int: try: response = httpx.get( url=f"{site_constant.FULL_URL}/search/?&q={word_to_search}&quick=1&type=videobox_video&nodes=11", - headers={'user-agent': get_headers()}, + headers={'user-agent': get_userAgent()}, timeout=max_timeout ) response.raise_for_status() diff --git a/StreamingCommunity/Api/Site/ddlstreamitaly/util/ScrapeSerie.py b/StreamingCommunity/Api/Site/ddlstreamitaly/util/ScrapeSerie.py index 46ff438..26af8f2 100644 --- a/StreamingCommunity/Api/Site/ddlstreamitaly/util/ScrapeSerie.py +++ b/StreamingCommunity/Api/Site/ddlstreamitaly/util/ScrapeSerie.py @@ -12,7 +12,7 @@ from bs4 import BeautifulSoup # Internal utilities from StreamingCommunity.Util._jsonConfig import config_manager -from StreamingCommunity.Util.headers import get_headers +from StreamingCommunity.Util.headers import get_userAgent # Logic class @@ -31,7 +31,7 @@ class GetSerieInfo: Parameters: - dict_serie (MediaItem): Dictionary containing series information (optional). """ - self.headers = {'user-agent': get_headers()} + self.headers = {'user-agent': get_userAgent()} self.cookies = cookies self.url = dict_serie.url self.tv_name = None diff --git a/StreamingCommunity/Api/Site/guardaserie/site.py b/StreamingCommunity/Api/Site/guardaserie/site.py index a5d78a9..9bdd4c8 100644 --- a/StreamingCommunity/Api/Site/guardaserie/site.py +++ b/StreamingCommunity/Api/Site/guardaserie/site.py @@ -10,7 +10,7 @@ from bs4 import BeautifulSoup # Internal utilities from StreamingCommunity.Util.console import console from StreamingCommunity.Util._jsonConfig import config_manager -from StreamingCommunity.Util.headers import get_headers +from StreamingCommunity.Util.headers import get_userAgent from StreamingCommunity.Util.table import TVShowManager @@ -56,7 +56,7 @@ def title_search(word_to_search: str) -> int: try: response = httpx.get( url=f"{site_constant.FULL_URL}/?story={word_to_search}&do=search&subaction=search", - headers={'user-agent': get_headers()}, + headers={'user-agent': get_userAgent()}, timeout=max_timeout ) response.raise_for_status() diff --git a/StreamingCommunity/Api/Site/guardaserie/util/ScrapeSerie.py b/StreamingCommunity/Api/Site/guardaserie/util/ScrapeSerie.py index 8db25ed..9d05d7e 100644 --- a/StreamingCommunity/Api/Site/guardaserie/util/ScrapeSerie.py +++ b/StreamingCommunity/Api/Site/guardaserie/util/ScrapeSerie.py @@ -10,7 +10,7 @@ from bs4 import BeautifulSoup # Internal utilities -from StreamingCommunity.Util.headers import get_headers +from StreamingCommunity.Util.headers import get_userAgent from StreamingCommunity.Util._jsonConfig import config_manager @@ -30,7 +30,7 @@ class GetSerieInfo: Parameters: dict_serie (MediaItem): Dictionary containing series information (optional). """ - self.headers = {'user-agent': get_headers()} + self.headers = {'user-agent': get_userAgent()} self.url = dict_serie.url self.tv_name = None self.list_episodes = None diff --git a/StreamingCommunity/Api/Site/mostraguarda/film.py b/StreamingCommunity/Api/Site/mostraguarda/film.py index d2ed3e8..a27d278 100644 --- a/StreamingCommunity/Api/Site/mostraguarda/film.py +++ b/StreamingCommunity/Api/Site/mostraguarda/film.py @@ -13,7 +13,7 @@ from bs4 import BeautifulSoup from StreamingCommunity.Util.console import console from StreamingCommunity.Util.os import os_manager from StreamingCommunity.Util.message import start_message -from StreamingCommunity.Util.headers import get_headers +from StreamingCommunity.Util.headers import get_userAgent from StreamingCommunity.Util.table import TVShowManager, get_call_stack from StreamingCommunity.Lib.Downloader import HLS_Downloader @@ -45,7 +45,7 @@ def download_film(movie_details: Json_film) -> str: # Make request to main site try: url = f"{site_constant.FULL_URL}/set-movie-a/{movie_details.imdb_id}" - response = httpx.get(url, headers={'User-Agent': get_headers()}) + response = httpx.get(url, headers={'User-Agent': get_userAgent()}) response.raise_for_status() except: diff --git a/StreamingCommunity/Api/Site/streamingcommunity/site.py b/StreamingCommunity/Api/Site/streamingcommunity/site.py index 21e336e..597ee13 100644 --- a/StreamingCommunity/Api/Site/streamingcommunity/site.py +++ b/StreamingCommunity/Api/Site/streamingcommunity/site.py @@ -10,7 +10,7 @@ import httpx # Internal utilities from StreamingCommunity.Util.console import console from StreamingCommunity.Util._jsonConfig import config_manager -from StreamingCommunity.Util.headers import get_headers +from StreamingCommunity.Util.headers import get_userAgent from StreamingCommunity.Util.table import TVShowManager from StreamingCommunity.TelegramHelp.telegram_bot import get_bot_instance @@ -58,7 +58,7 @@ def title_search(title_search: str) -> int: try: response = httpx.get( url=f"{site_constant.FULL_URL}/api/search?q={title_search.replace(' ', '+')}", - headers={'user-agent': get_headers()}, + headers={'user-agent': get_userAgent()}, timeout=max_timeout ) response.raise_for_status() diff --git a/StreamingCommunity/Api/Site/streamingcommunity/util/ScrapeSerie.py b/StreamingCommunity/Api/Site/streamingcommunity/util/ScrapeSerie.py index 47450ec..5146dd3 100644 --- a/StreamingCommunity/Api/Site/streamingcommunity/util/ScrapeSerie.py +++ b/StreamingCommunity/Api/Site/streamingcommunity/util/ScrapeSerie.py @@ -10,7 +10,7 @@ from bs4 import BeautifulSoup # Internal utilities -from StreamingCommunity.Util.headers import get_headers +from StreamingCommunity.Util.headers import get_userAgent from StreamingCommunity.Util._jsonConfig import config_manager from StreamingCommunity.Api.Player.Helper.Vixcloud.util import Season, EpisodeManager @@ -28,7 +28,7 @@ class ScrapeSerie: - url (str): The URL of the streaming site. """ self.is_series = False - self.headers = {'user-agent': get_headers()} + self.headers = {'user-agent': get_userAgent()} self.url = url def setup(self, media_id: int = None, series_name: str = None): @@ -89,7 +89,7 @@ class ScrapeSerie: response = httpx.get( url=f'{self.url}/titles/{self.media_id}-{self.series_name}/stagione-{number_season}', headers={ - 'User-Agent': get_headers(), + 'User-Agent': get_userAgent(), 'x-inertia': 'true', 'x-inertia-version': self.version, }, diff --git a/StreamingCommunity/Api/Template/Util/get_domain.py b/StreamingCommunity/Api/Template/Util/get_domain.py index 9371131..76ebe76 100644 --- a/StreamingCommunity/Api/Template/Util/get_domain.py +++ b/StreamingCommunity/Api/Template/Util/get_domain.py @@ -14,21 +14,6 @@ from StreamingCommunity.Util.headers import get_headers from StreamingCommunity.Util.console import console from StreamingCommunity.Util._jsonConfig import config_manager -base_headers = { - 'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7', - 'accept-language': 'it-IT,it;q=0.9,en-US;q=0.8,en;q=0.7', - 'dnt': '1', - 'priority': 'u=0, i', - 'referer': '', - 'sec-ch-ua-mobile': '?0', - 'sec-ch-ua-platform': '"Windows"', - 'sec-fetch-dest': 'document', - 'sec-fetch-mode': 'navigate', - 'sec-fetch-site': 'same-origin', - 'sec-fetch-user': '?1', - 'upgrade-insecure-requests': '1', - 'user-agent': '' -} def get_tld(url_str): @@ -82,9 +67,6 @@ def validate_url(url, base_url, max_timeout, max_retries=2, sleep=1): base_domain = get_base_domain(base_url) url_domain = get_base_domain(url) - base_headers['referer'] = url - base_headers['user-agent'] = get_headers() - if base_domain != url_domain: console.print(f"[red]Domain structure mismatch: {url_domain} != {base_domain}") return False, None @@ -98,7 +80,7 @@ def validate_url(url, base_url, max_timeout, max_retries=2, sleep=1): client = httpx.Client( verify=False, - headers=base_headers, + headers=get_headers(), timeout=max_timeout ) diff --git a/StreamingCommunity/Lib/Downloader/HLS/downloader.py b/StreamingCommunity/Lib/Downloader/HLS/downloader.py index 8cc8a00..9a84d51 100644 --- a/StreamingCommunity/Lib/Downloader/HLS/downloader.py +++ b/StreamingCommunity/Lib/Downloader/HLS/downloader.py @@ -14,7 +14,7 @@ import httpx # Internal utilities from StreamingCommunity.Util._jsonConfig import config_manager -from StreamingCommunity.Util.headers import get_headers +from StreamingCommunity.Util.headers import get_userAgent from StreamingCommunity.Util.console import console, Panel from StreamingCommunity.Util.os import ( compute_sha1_hash, @@ -55,7 +55,7 @@ TELEGRAM_BOT = config_manager.get_bool('DEFAULT', 'telegram_bot') class HLSClient: """Client for making HTTP requests to HLS endpoints with retry mechanism.""" def __init__(self): - self.headers = {'User-Agent': get_headers()} + self.headers = {'User-Agent': get_userAgent()} def request(self, url: str, return_content: bool = False) -> Optional[httpx.Response]: """ diff --git a/StreamingCommunity/Lib/Downloader/HLS/proxyes.py b/StreamingCommunity/Lib/Downloader/HLS/proxyes.py index b0d026f..c0e56a0 100644 --- a/StreamingCommunity/Lib/Downloader/HLS/proxyes.py +++ b/StreamingCommunity/Lib/Downloader/HLS/proxyes.py @@ -12,7 +12,7 @@ import httpx # Internal utilities from StreamingCommunity.Util._jsonConfig import config_manager -from StreamingCommunity.Util.headers import get_headers +from StreamingCommunity.Util.headers import get_userAgent from StreamingCommunity.Util.os import os_manager @@ -46,7 +46,7 @@ class ProxyManager: try: with httpx.Client(proxies=proxy, verify=False) as client: - response = client.get(self.url, timeout=self.timeout, headers={'user-agent': get_headers()}) + response = client.get(self.url, timeout=self.timeout, headers={'user-agent': get_userAgent()}) if response.status_code == 200: logging.info(f"Proxy {proxy} is working.") diff --git a/StreamingCommunity/Lib/Downloader/HLS/segments.py b/StreamingCommunity/Lib/Downloader/HLS/segments.py index f03348b..3809cda 100644 --- a/StreamingCommunity/Lib/Downloader/HLS/segments.py +++ b/StreamingCommunity/Lib/Downloader/HLS/segments.py @@ -22,7 +22,7 @@ from tqdm import tqdm # Internal utilities from StreamingCommunity.Util.color import Colors from StreamingCommunity.Util.console import console -from StreamingCommunity.Util.headers import get_headers, random_headers +from StreamingCommunity.Util.headers import get_userAgent, random_headers from StreamingCommunity.Util._jsonConfig import config_manager from StreamingCommunity.Util.os import os_manager @@ -102,7 +102,7 @@ class M3U8_Segments: self.key_base_url = f"{parsed_url.scheme}://{parsed_url.netloc}/" try: - client_params = {'headers': {'User-Agent': get_headers()}, 'timeout': MAX_TIMEOOUT} + client_params = {'headers': {'User-Agent': get_userAgent()}, 'timeout': MAX_TIMEOOUT} response = httpx.get(url=key_uri, **client_params) response.raise_for_status() @@ -145,7 +145,7 @@ class M3U8_Segments: def get_info(self) -> None: if self.is_index_url: try: - client_params = {'headers': {'User-Agent': get_headers()}, 'timeout': MAX_TIMEOOUT} + client_params = {'headers': {'User-Agent': get_userAgent()}, 'timeout': MAX_TIMEOOUT} response = httpx.get(self.url, **client_params) response.raise_for_status() @@ -186,8 +186,8 @@ class M3U8_Segments: def _get_http_client(self, index: int = None): client_params = { - #'headers': random_headers(self.key_base_url) if hasattr(self, 'key_base_url') else {'User-Agent': get_headers()}, - 'headers': {'User-Agent': get_headers()}, + #'headers': random_headers(self.key_base_url) if hasattr(self, 'key_base_url') else {'User-Agent': get_userAgent()}, + 'headers': {'User-Agent': get_userAgent()}, 'timeout': SEGMENT_MAX_TIMEOUT, 'follow_redirects': True, 'http2': False diff --git a/StreamingCommunity/Lib/Downloader/MP4/downloader.py b/StreamingCommunity/Lib/Downloader/MP4/downloader.py index 86c921b..104cba8 100644 --- a/StreamingCommunity/Lib/Downloader/MP4/downloader.py +++ b/StreamingCommunity/Lib/Downloader/MP4/downloader.py @@ -15,7 +15,7 @@ from tqdm import tqdm # Internal utilities -from StreamingCommunity.Util.headers import get_headers +from StreamingCommunity.Util.headers import get_userAgent from StreamingCommunity.Util.color import Colors from StreamingCommunity.Util.console import console, Panel from StreamingCommunity.Util._jsonConfig import config_manager @@ -99,7 +99,7 @@ def MP4_downloader(url: str, path: str, referer: str = None, headers_: dict = No if headers_: headers.update(headers_) else: - headers['User-Agent'] = get_headers() + headers['User-Agent'] = get_userAgent() except Exception as header_err: logging.error(f"Error preparing headers: {header_err}") diff --git a/StreamingCommunity/Upload/update.py b/StreamingCommunity/Upload/update.py index 566c355..f562ec8 100644 --- a/StreamingCommunity/Upload/update.py +++ b/StreamingCommunity/Upload/update.py @@ -13,7 +13,7 @@ import httpx from .version import __version__, __author__, __title__ from StreamingCommunity.Util.console import console from StreamingCommunity.Util._jsonConfig import config_manager -from StreamingCommunity.Util.headers import get_headers +from StreamingCommunity.Util.headers import get_userAgent @@ -31,14 +31,14 @@ def update(): try: response_reposity = httpx.get( url=f"https://api.github.com/repos/{__author__}/{__title__}", - headers={'user-agent': get_headers()}, + headers={'user-agent': get_userAgent()}, timeout=config_manager.get_int("REQUESTS", "timeout"), follow_redirects=True ).json() response_releases = httpx.get( url=f"https://api.github.com/repos/{__author__}/{__title__}/releases", - headers={'user-agent': get_headers()}, + headers={'user-agent': get_userAgent()}, timeout=config_manager.get_int("REQUESTS", "timeout"), follow_redirects=True ).json() diff --git a/StreamingCommunity/Util/_jsonConfig.py b/StreamingCommunity/Util/_jsonConfig.py index f2ecf25..57f6f76 100644 --- a/StreamingCommunity/Util/_jsonConfig.py +++ b/StreamingCommunity/Util/_jsonConfig.py @@ -27,17 +27,79 @@ class ConfigManager: base_path = os.path.join(".") else: base_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..')) + self.file_path = os.path.join(base_path, file_name) self.domains_path = os.path.join(base_path, 'domains.json') self.config = {} self.configSite = {} self.cache = {} + self.reference_config_url = 'https://raw.githubusercontent.com/Arrowar/StreamingCommunity/refs/heads/main/config.json' - # Read initial config to get use_api setting + # Validate and update config before proceeding + self._validate_and_update_config() self._read_initial_config() console.print(f"[bold cyan]📂 Configuration file path:[/bold cyan] [green]{self.file_path}[/green]") - + + def _validate_and_update_config(self) -> None: + """Validate local config against reference config and update missing keys.""" + try: + # Load local config if exists + local_config = {} + if os.path.exists(self.file_path): + with open(self.file_path, 'r') as f: + local_config = json.load(f) + console.print("[bold cyan]📖 Local configuration found.[/bold cyan]") + + # Download reference config + console.print("[bold cyan]🌍 Downloading reference configuration...[/bold cyan]") + response = requests.get(self.reference_config_url) + if response.status_code != 200: + raise Exception(f"Failed to download reference config. Status code: {response.status_code}") + reference_config = response.json() + + # Compare and update missing keys + merged_config = self._deep_merge_configs(local_config, reference_config) + + if merged_config != local_config: + # Save the merged config + with open(self.file_path, 'w') as f: + json.dump(merged_config, f, indent=4) + console.print("[bold green]✅ Configuration updated with missing keys.[/bold green]") + else: + console.print("[bold green]✅ Configuration is up to date.[/bold green]") + + self.config = merged_config + + except Exception as e: + console.print(f"[bold red]❌ Error validating configuration: {e}[/bold red]") + if not self.config: + # If validation failed and we have no config, download the reference config + self.download_requirements(self.reference_config_url, self.file_path) + with open(self.file_path, 'r') as f: + self.config = json.load(f) + + def _deep_merge_configs(self, local_config: dict, reference_config: dict) -> dict: + """ + Recursively merge reference config into local config, preserving local values. + + Args: + local_config (dict): The local configuration + reference_config (dict): The reference configuration + + Returns: + dict: Merged configuration + """ + merged = local_config.copy() + + for key, value in reference_config.items(): + if key not in merged: + merged[key] = value + elif isinstance(value, dict) and isinstance(merged[key], dict): + merged[key] = self._deep_merge_configs(merged[key], value) + + return merged + def _read_initial_config(self) -> None: """Read initial configuration to get use_api setting.""" try: @@ -63,13 +125,9 @@ class ConfigManager: with open(self.file_path, 'r') as f: self.config = json.load(f) console.print("[bold green]✅ Configuration file loaded successfully.[/bold green]") - else: console.print("[bold yellow]⚠️ Configuration file not found. Downloading...[/bold yellow]") - self.download_requirements( - 'https://raw.githubusercontent.com/Arrowar/StreamingCommunity/refs/heads/main/config.json', - self.file_path - ) + self.download_requirements(self.reference_config_url, self.file_path) # Load the downloaded config.json into the config attribute with open(self.file_path, 'r') as f: @@ -84,7 +142,7 @@ class ConfigManager: except Exception as e: logging.error(f"❌ Error reading configuration file: {e}") - def download_requirements(self, url: str, filename: str): + def download_requirements(self, url: str, filename: str) -> None: """ Download a file from the specified URL if not found locally using requests. diff --git a/StreamingCommunity/Util/headers.py b/StreamingCommunity/Util/headers.py index 0ee6257..0947917 100644 --- a/StreamingCommunity/Util/headers.py +++ b/StreamingCommunity/Util/headers.py @@ -7,7 +7,10 @@ import random import ua_generator -def get_headers() -> str: +# Variable +ua = ua_generator.generate(device='desktop', browser=('chrome', 'edge')) + +def get_userAgent() -> str: """ Generate a random user agent to use in HTTP requests. @@ -20,6 +23,10 @@ def get_headers() -> str: return user_agent +def get_headers() -> dict: + return ua.headers.get() + + def random_headers(referer: str = None): """ Generate random HTTP headers to simulate human-like behavior.