mirror of
https://github.com/Arrowar/StreamingCommunity.git
synced 2025-06-05 02:55:25 +00:00
Merge c94e69354553dd5d4a96f08fc0d78d6b58126015 into 3cbabfb98b95a7f10a8decc31edcb06c2088eb68
This commit is contained in:
commit
cb7082e210
@ -30,17 +30,27 @@ class ConfigManager:
|
||||
Args:
|
||||
file_name (str, optional): Configuration file name. Default: 'config.json'.
|
||||
"""
|
||||
# Determine the base path - use the current working directory
|
||||
if getattr(sys, 'frozen', False):
|
||||
# If the application is frozen (e.g., PyInstaller)
|
||||
base_path = os.path.dirname(sys.executable)
|
||||
|
||||
else:
|
||||
|
||||
# Get the actual path of the module file
|
||||
current_file_path = os.path.abspath(__file__)
|
||||
base_path = os.path.dirname(os.path.dirname(os.path.dirname(current_file_path)))
|
||||
# Check if the file name is a full path or just a file name
|
||||
if os.path.basename(file_name) == file_name:
|
||||
# Determine the base path - use the current working directory
|
||||
if getattr(sys, 'frozen', False):
|
||||
# If the application is frozen (e.g., PyInstaller)
|
||||
base_path = os.path.dirname(sys.executable)
|
||||
|
||||
else:
|
||||
|
||||
# Get the actual path of the module file
|
||||
current_file_path = os.path.abspath(__file__)
|
||||
# Navigate upwards to find the project root
|
||||
# Assuming this file is in a package structure like StreamingCommunity/Util/config_json.py
|
||||
# We need to go up 2 levels to reach the project root
|
||||
base_path = os.path.dirname(os.path.dirname(os.path.dirname(current_file_path)))
|
||||
|
||||
else:
|
||||
base_path = os.path.dirname(os.path.abspath(file_name))
|
||||
file_name = os.path.basename(file_name)
|
||||
|
||||
# Initialize file paths
|
||||
self.file_path = os.path.join(base_path, file_name)
|
||||
self.domains_path = os.path.join(base_path, 'domains.json')
|
||||
@ -268,32 +278,33 @@ class ConfigManager:
|
||||
self._load_site_data_from_file()
|
||||
|
||||
def _load_site_data_from_api(self) -> None:
|
||||
"""Load site data from GitHub."""
|
||||
domains_github_url = "https://raw.githubusercontent.com/Arrowar/StreamingCommunity/refs/heads/main/.github/.domain/domains.json"
|
||||
"""Load site data from API."""
|
||||
headers = {
|
||||
"User-Agent": get_userAgent()
|
||||
"apikey": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Inp2Zm5ncG94d3Jnc3duenl0YWRoIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NDAxNTIxNjMsImV4cCI6MjA1NTcyODE2M30.FNTCCMwi0QaKjOu8gtZsT5yQttUW8QiDDGXmzkn89QE",
|
||||
"Authorization": f"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Inp2Zm5ncG94d3Jnc3duenl0YWRoIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NDAxNTIxNjMsImV4cCI6MjA1NTcyODE2M30.FNTCCMwi0QaKjOu8gtZsT5yQttUW8QiDDGXmzkn89QE",
|
||||
"Content-Type": "application/json",
|
||||
"User-Agent": get_userAgent()
|
||||
}
|
||||
|
||||
try:
|
||||
console.print(f"[bold cyan]Retrieving site data from GitHub:[/bold cyan] [green]{domains_github_url}[/green]")
|
||||
response = requests.get(domains_github_url, timeout=8, headers=headers)
|
||||
console.print("[bold cyan]Retrieving site data from API...[/bold cyan]")
|
||||
response = requests.get("https://zvfngpoxwrgswnzytadh.supabase.co/rest/v1/public", timeout=8, headers=headers)
|
||||
|
||||
if response.ok:
|
||||
self.configSite = response.json()
|
||||
|
||||
site_count = len(self.configSite) if isinstance(self.configSite, dict) else 0
|
||||
console.print(f"[bold green]Site data loaded from GitHub:[/bold green] {site_count} streaming services found.")
|
||||
|
||||
data = response.json()
|
||||
if data and len(data) > 0:
|
||||
self.configSite = data[0]['data']
|
||||
|
||||
site_count = len(self.configSite) if isinstance(self.configSite, dict) else 0
|
||||
|
||||
else:
|
||||
console.print("[bold yellow]API returned an empty data set[/bold yellow]")
|
||||
else:
|
||||
console.print(f"[bold red]GitHub request failed:[/bold red] HTTP {response.status_code}, {response.text[:100]}")
|
||||
console.print(f"[bold red]API request failed:[/bold red] HTTP {response.status_code}, {response.text[:100]}")
|
||||
self._handle_site_data_fallback()
|
||||
|
||||
except json.JSONDecodeError as e:
|
||||
console.print(f"[bold red]Error parsing JSON from GitHub:[/bold red] {str(e)}")
|
||||
self._handle_site_data_fallback()
|
||||
|
||||
except Exception as e:
|
||||
console.print(f"[bold red]GitHub connection error:[/bold red] {str(e)}")
|
||||
console.print(f"[bold red]API connection error:[/bold red] {str(e)}")
|
||||
self._handle_site_data_fallback()
|
||||
|
||||
def _load_site_data_from_file(self) -> None:
|
||||
@ -558,6 +569,7 @@ class ConfigManager:
|
||||
return section in config_source
|
||||
|
||||
|
||||
# Helper function to check the platform
|
||||
def get_use_large_bar():
|
||||
"""
|
||||
Determine if the large bar feature should be enabled.
|
||||
|
@ -29,9 +29,9 @@ from StreamingCommunity.TelegramHelp.telegram_bot import get_bot_instance, Teleg
|
||||
|
||||
|
||||
# Config
|
||||
SHOW_TRENDING = config_manager.get_bool('DEFAULT', 'show_trending')
|
||||
NOT_CLOSE_CONSOLE = config_manager.get_bool('DEFAULT', 'not_close')
|
||||
TELEGRAM_BOT = config_manager.get_bool('DEFAULT', 'telegram_bot')
|
||||
# SHOW_TRENDING = config_manager.get_bool('DEFAULT', 'show_trending')
|
||||
# NOT_CLOSE_CONSOLE = config_manager.get_bool('DEFAULT', 'not_close')
|
||||
# TELEGRAM_BOT = config_manager.get_bool('DEFAULT', 'telegram_bot')
|
||||
|
||||
|
||||
# Variable
|
||||
@ -61,7 +61,7 @@ def load_search_functions():
|
||||
loaded_functions = {}
|
||||
|
||||
# Lista dei siti da escludere se TELEGRAM_BOT è attivo
|
||||
excluded_sites = {"cb01new", "guardaserie", "ilcorsaronero", "mostraguarda"} if TELEGRAM_BOT else set()
|
||||
excluded_sites = {"cb01new", "guardaserie", "ilcorsaronero", "mostraguarda"} if config_manager.get_bool('DEFAULT', 'telegram_bot') else set()
|
||||
|
||||
# Find api home directory
|
||||
if getattr(sys, 'frozen', False): # Modalità PyInstaller
|
||||
@ -142,7 +142,8 @@ def initialize():
|
||||
sys.exit(0)
|
||||
|
||||
# Trending tmbd
|
||||
if SHOW_TRENDING:
|
||||
# SHOW_TRENDING
|
||||
if config_manager.get_bool('DEFAULT', 'show_trending'):
|
||||
print()
|
||||
tmdb.display_trending_films()
|
||||
tmdb.display_trending_tv_shows()
|
||||
@ -200,10 +201,6 @@ def main(script_id = 0):
|
||||
"torrent": "white"
|
||||
}
|
||||
|
||||
if TELEGRAM_BOT:
|
||||
bot = get_bot_instance()
|
||||
bot.send_message(f"Avviato script {script_id}", None)
|
||||
|
||||
start = time.time()
|
||||
|
||||
# Create logger
|
||||
@ -244,6 +241,11 @@ def main(script_id = 0):
|
||||
|
||||
parser.add_argument("script_id", nargs="?", default="unknown", help="ID dello script")
|
||||
|
||||
# Add arguments for the custom config file
|
||||
parser.add_argument(
|
||||
'--config', type=str, help='Load custom config file name (e.g., custom_config.json).'
|
||||
)
|
||||
|
||||
# Add arguments for the main configuration parameters
|
||||
parser.add_argument(
|
||||
'--add_siteName', type=bool, help='Enable or disable adding the site name to the file name (e.g., true/false).'
|
||||
@ -279,6 +281,16 @@ def main(script_id = 0):
|
||||
# Parse command-line arguments
|
||||
args = parser.parse_args()
|
||||
|
||||
# If custom config file is specified, update config_manager
|
||||
if args.config:
|
||||
config_manager.__init__(args.config)
|
||||
|
||||
# TELEGRAM_BOT:
|
||||
if config_manager.get_bool('DEFAULT', 'telegram_bot'):
|
||||
bot = get_bot_instance()
|
||||
bot.send_message(f"Avviato script {script_id}", None)
|
||||
|
||||
|
||||
search_terms = args.search
|
||||
# Map command-line arguments to the config values
|
||||
config_updates = {}
|
||||
@ -332,7 +344,8 @@ def main(script_id = 0):
|
||||
for key, label in choice_labels.items()]
|
||||
) + "[white])"
|
||||
|
||||
if TELEGRAM_BOT:
|
||||
# TELEGRAM_BOT
|
||||
if config_manager.get_bool('DEFAULT', 'telegram_bot'):
|
||||
category_legend_str = "Categorie: \n" + " | ".join([
|
||||
f"{category.capitalize()}" for category in color_map.keys()
|
||||
])
|
||||
@ -357,18 +370,21 @@ def main(script_id = 0):
|
||||
run_function(input_to_function[category], search_terms=search_terms)
|
||||
|
||||
else:
|
||||
if TELEGRAM_BOT:
|
||||
# TELEGRAM_BOT
|
||||
if config_manager.get_bool('DEFAULT', 'telegram_bot'):
|
||||
bot.send_message(f"Categoria non valida", None)
|
||||
|
||||
console.print("[red]Invalid category.")
|
||||
|
||||
if NOT_CLOSE_CONSOLE:
|
||||
# NOT_CLOSE_CONSOLE
|
||||
if config_manager.get_bool('DEFAULT', 'not_close'):
|
||||
restart_script()
|
||||
|
||||
else:
|
||||
force_exit()
|
||||
|
||||
if TELEGRAM_BOT:
|
||||
# TELEGRAM_BOT
|
||||
if config_manager.get_bool('DEFAULT', 'telegram_bot'):
|
||||
bot.send_message(f"Chiusura in corso", None)
|
||||
|
||||
# Delete script_id
|
||||
|
Loading…
x
Reference in New Issue
Block a user