mirror of
https://github.com/Arrowar/StreamingCommunity.git
synced 2025-07-20 09:00:01 +00:00
Add deep merge config.json
This commit is contained in:
parent
a3cd10dfdd
commit
d0a75eb36d
@ -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:
|
||||
|
@ -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',
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
)
|
||||
|
@ -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
|
||||
)
|
||||
|
@ -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):
|
||||
|
@ -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()
|
||||
|
@ -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()
|
||||
|
@ -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
|
||||
|
@ -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()
|
||||
|
@ -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
|
||||
|
@ -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:
|
||||
|
@ -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()
|
||||
|
@ -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,
|
||||
},
|
||||
|
@ -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
|
||||
)
|
||||
|
||||
|
@ -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]:
|
||||
"""
|
||||
|
@ -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.")
|
||||
|
@ -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
|
||||
|
@ -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}")
|
||||
|
@ -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()
|
||||
|
@ -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.
|
||||
|
||||
|
@ -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.
|
||||
|
Loading…
x
Reference in New Issue
Block a user