mirror of
https://github.com/Arrowar/StreamingCommunity.git
synced 2025-06-06 11:35:29 +00:00
[CORE] Remove all cp1252 characters
This commit is contained in:
parent
881e36868e
commit
2d7d654414
@ -47,7 +47,7 @@ def title_search(word_to_search: str) -> int:
|
|||||||
domain_to_use, base_url = search_domain(site_constant.SITE_NAME, site_constant.FULL_URL)
|
domain_to_use, base_url = search_domain(site_constant.SITE_NAME, site_constant.FULL_URL)
|
||||||
|
|
||||||
if domain_to_use is None or base_url is None:
|
if domain_to_use is None or base_url is None:
|
||||||
console.print("[bold red]❌ Error: Unable to determine valid domain or base URL.[/bold red]")
|
console.log("[bold red]Error: Unable to determine valid domain or base URL.[/bold red]")
|
||||||
console.print("[yellow]The service might be temporarily unavailable or the domain may have changed.[/yellow]")
|
console.print("[yellow]The service might be temporarily unavailable or the domain may have changed.[/yellow]")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ def search(string_to_search: str = None, get_onylDatabase: bool = False):
|
|||||||
# Chiedi la scelta all'utente con il bot Telegram
|
# Chiedi la scelta all'utente con il bot Telegram
|
||||||
string_to_search = bot.ask(
|
string_to_search = bot.ask(
|
||||||
"key_search",
|
"key_search",
|
||||||
f"Inserisci la parola da cercare\noppure 🔙 back per tornare alla scelta: ",
|
f"Inserisci la parola da cercare\noppure back per tornare alla scelta: ",
|
||||||
None
|
None
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -117,7 +117,7 @@ def title_search(title: str) -> int:
|
|||||||
domain_to_use, base_url = search_domain(site_constant.SITE_NAME, site_constant.FULL_URL)
|
domain_to_use, base_url = search_domain(site_constant.SITE_NAME, site_constant.FULL_URL)
|
||||||
|
|
||||||
if domain_to_use is None or base_url is None:
|
if domain_to_use is None or base_url is None:
|
||||||
console.print("[bold red]❌ Error: Unable to determine valid domain or base URL.[/bold red]")
|
console.print("[bold red]Error: Unable to determine valid domain or base URL.[/bold red]")
|
||||||
console.print("[yellow]The service might be temporarily unavailable or the domain may have changed.[/yellow]")
|
console.print("[yellow]The service might be temporarily unavailable or the domain may have changed.[/yellow]")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ def title_search(word_to_search: str) -> int:
|
|||||||
domain_to_use, base_url = search_domain(site_constant.SITE_NAME, site_constant.FULL_URL)
|
domain_to_use, base_url = search_domain(site_constant.SITE_NAME, site_constant.FULL_URL)
|
||||||
|
|
||||||
if domain_to_use is None or base_url is None:
|
if domain_to_use is None or base_url is None:
|
||||||
console.print("[bold red]❌ Error: Unable to determine valid domain or base URL.[/bold red]")
|
console.print("[bold red]Error: Unable to determine valid domain or base URL.[/bold red]")
|
||||||
console.print("[yellow]The service might be temporarily unavailable or the domain may have changed.[/yellow]")
|
console.print("[yellow]The service might be temporarily unavailable or the domain may have changed.[/yellow]")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ def title_search(word_to_search: str) -> int:
|
|||||||
domain_to_use, base_url = search_domain(site_constant.SITE_NAME, site_constant.FULL_URL)
|
domain_to_use, base_url = search_domain(site_constant.SITE_NAME, site_constant.FULL_URL)
|
||||||
|
|
||||||
if domain_to_use is None or base_url is None:
|
if domain_to_use is None or base_url is None:
|
||||||
console.print("[bold red]❌ Error: Unable to determine valid domain or base URL.[/bold red]")
|
console.print("[bold red]Error: Unable to determine valid domain or base URL.[/bold red]")
|
||||||
console.print("[yellow]The service might be temporarily unavailable or the domain may have changed.[/yellow]")
|
console.print("[yellow]The service might be temporarily unavailable or the domain may have changed.[/yellow]")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ def title_search(word_to_search: str) -> int:
|
|||||||
domain_to_use, base_url = search_domain(site_constant.SITE_NAME, site_constant.FULL_URL)
|
domain_to_use, base_url = search_domain(site_constant.SITE_NAME, site_constant.FULL_URL)
|
||||||
|
|
||||||
if domain_to_use is None or base_url is None:
|
if domain_to_use is None or base_url is None:
|
||||||
console.print("[bold red]❌ Error: Unable to determine valid domain or base URL.[/bold red]")
|
console.print("[bold red]Error: Unable to determine valid domain or base URL.[/bold red]")
|
||||||
console.print("[yellow]The service might be temporarily unavailable or the domain may have changed.[/yellow]")
|
console.print("[yellow]The service might be temporarily unavailable or the domain may have changed.[/yellow]")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ def search(string_to_search: str = None, get_onylDatabase: bool = False):
|
|||||||
# Chiedi la scelta all'utente con il bot Telegram
|
# Chiedi la scelta all'utente con il bot Telegram
|
||||||
string_to_search = bot.ask(
|
string_to_search = bot.ask(
|
||||||
"key_search",
|
"key_search",
|
||||||
f"Inserisci la parola da cercare\noppure 🔙 back per tornare alla scelta: ",
|
f"Inserisci la parola da cercare\noppure back per tornare alla scelta: ",
|
||||||
None
|
None
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ def title_search(title_search: str) -> int:
|
|||||||
domain_to_use, base_url = search_domain(site_constant.SITE_NAME, site_constant.FULL_URL)
|
domain_to_use, base_url = search_domain(site_constant.SITE_NAME, site_constant.FULL_URL)
|
||||||
|
|
||||||
if domain_to_use is None or base_url is None:
|
if domain_to_use is None or base_url is None:
|
||||||
console.print("[bold red]❌ Error: Unable to determine valid domain or base URL.[/bold red]")
|
console.print("[bold red]Error: Unable to determine valid domain or base URL.[/bold red]")
|
||||||
console.print("[yellow]The service might be temporarily unavailable or the domain may have changed.[/yellow]")
|
console.print("[yellow]The service might be temporarily unavailable or the domain may have changed.[/yellow]")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ class TOR_downloader:
|
|||||||
int(torrent_info.num_leechs) == 0 and
|
int(torrent_info.num_leechs) == 0 and
|
||||||
int(torrent_info.num_seeds) == 0):
|
int(torrent_info.num_seeds) == 0):
|
||||||
|
|
||||||
console.print(f"[bold red]⚠️ Torrent not downloadable. Removing...[/bold red]")
|
console.print(f"[bold red]Torrent not downloadable. Removing...[/bold red]")
|
||||||
try:
|
try:
|
||||||
self.qb.torrents_delete(delete_files=True, torrent_hashes=torrent_info.hash)
|
self.qb.torrents_delete(delete_files=True, torrent_hashes=torrent_info.hash)
|
||||||
except Exception as delete_error:
|
except Exception as delete_error:
|
||||||
@ -137,7 +137,7 @@ class TOR_downloader:
|
|||||||
|
|
||||||
torrent_info = matching_torrents[0]
|
torrent_info = matching_torrents[0]
|
||||||
|
|
||||||
console.print("\n[bold green]🔗 Added Torrent Details:[/bold green]")
|
console.print("\n[bold green]Added Torrent Details:[/bold green]")
|
||||||
console.print(f"[yellow]Name:[/yellow] {torrent_info.name or torrent_name}")
|
console.print(f"[yellow]Name:[/yellow] {torrent_info.name or torrent_name}")
|
||||||
console.print(f"[yellow]Hash:[/yellow] {torrent_info.hash}")
|
console.print(f"[yellow]Hash:[/yellow] {torrent_info.hash}")
|
||||||
print()
|
print()
|
||||||
|
@ -113,7 +113,7 @@ class TelegramRequestManager:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
except (FileNotFoundError, json.JSONDecodeError) as e:
|
except (FileNotFoundError, json.JSONDecodeError) as e:
|
||||||
print(f"⚠️ save_response - errore: {e}")
|
print(f" save_response - errore: {e}")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def get_response(self) -> Optional[str]:
|
def get_response(self) -> Optional[str]:
|
||||||
@ -142,7 +142,7 @@ class TelegramRequestManager:
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"⚠️ clear_file - errore: {e}")
|
print(f" clear_file - errore: {e}")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# Funzione per caricare variabili da un file .env
|
# Funzione per caricare variabili da un file .env
|
||||||
@ -230,20 +230,20 @@ class TelegramBot:
|
|||||||
["screen", "-S", script["screen_id"], "-X", "quit"]
|
["screen", "-S", script["screen_id"], "-X", "quit"]
|
||||||
)
|
)
|
||||||
print(
|
print(
|
||||||
f"✅ La sessione screen con ID {script['screen_id']} è stata fermata automaticamente."
|
f" La sessione screen con ID {script['screen_id']} è stata fermata automaticamente."
|
||||||
)
|
)
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
print(
|
print(
|
||||||
f"⚠️ Impossibile fermare la sessione screen con ID {script['screen_id']}."
|
f" Impossibile fermare la sessione screen con ID {script['screen_id']}."
|
||||||
)
|
)
|
||||||
print(
|
print(
|
||||||
f"⚠️ Lo script con ID {script['screen_id']} ha superato i 10 minuti e verrà rimosso."
|
f" Lo script con ID {script['screen_id']} ha superato i 10 minuti e verrà rimosso."
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
scripts_data_to_save.append(script)
|
scripts_data_to_save.append(script)
|
||||||
else:
|
else:
|
||||||
print(
|
print(
|
||||||
f"⚠️ La sessione screen con ID {script['screen_id']} non esiste più e verrà rimossa."
|
f" La sessione screen con ID {script['screen_id']} non esiste più e verrà rimossa."
|
||||||
)
|
)
|
||||||
|
|
||||||
# Salva la lista aggiornata, senza gli script scaduti o le screen non esistenti
|
# Salva la lista aggiornata, senza gli script scaduti o le screen non esistenti
|
||||||
@ -305,8 +305,8 @@ class TelegramBot:
|
|||||||
|
|
||||||
def handle_get_id(self, message):
|
def handle_get_id(self, message):
|
||||||
if not self.is_authorized(message.from_user.id):
|
if not self.is_authorized(message.from_user.id):
|
||||||
print(f"❌ Non sei autorizzato.")
|
print(f" Non sei autorizzato.")
|
||||||
self.bot.send_message(message.chat.id, "❌ Non sei autorizzato.")
|
self.bot.send_message(message.chat.id, " Non sei autorizzato.")
|
||||||
return
|
return
|
||||||
|
|
||||||
print(f"Il tuo ID utente è: `{message.from_user.id}`")
|
print(f"Il tuo ID utente è: `{message.from_user.id}`")
|
||||||
@ -318,8 +318,8 @@ class TelegramBot:
|
|||||||
|
|
||||||
def handle_start_script(self, message):
|
def handle_start_script(self, message):
|
||||||
if not self.is_authorized(message.from_user.id):
|
if not self.is_authorized(message.from_user.id):
|
||||||
print(f"❌ Non sei autorizzato. {message.from_user.id}")
|
print(f" Non sei autorizzato. {message.from_user.id}")
|
||||||
self.bot.send_message(message.chat.id, "❌ Non sei autorizzato.")
|
self.bot.send_message(message.chat.id, " Non sei autorizzato.")
|
||||||
return
|
return
|
||||||
|
|
||||||
screen_id = str(uuid.uuid4())[:8]
|
screen_id = str(uuid.uuid4())[:8]
|
||||||
@ -335,10 +335,10 @@ class TelegramBot:
|
|||||||
"utf-8"
|
"utf-8"
|
||||||
)
|
)
|
||||||
if screen_id in existing_screens:
|
if screen_id in existing_screens:
|
||||||
print(f"⚠️ Lo script con ID {screen_id} è già in esecuzione.")
|
print(f" Lo script con ID {screen_id} è già in esecuzione.")
|
||||||
self.bot.send_message(
|
self.bot.send_message(
|
||||||
message.chat.id,
|
message.chat.id,
|
||||||
f"⚠️ Lo script con ID {screen_id} è già in esecuzione.",
|
f" Lo script con ID {screen_id} è già in esecuzione.",
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
@ -384,8 +384,8 @@ class TelegramBot:
|
|||||||
|
|
||||||
def handle_list_scripts(self, message):
|
def handle_list_scripts(self, message):
|
||||||
if not self.is_authorized(message.from_user.id):
|
if not self.is_authorized(message.from_user.id):
|
||||||
print(f"❌ Non sei autorizzato.")
|
print(f" Non sei autorizzato.")
|
||||||
self.bot.send_message(message.chat.id, "❌ Non sei autorizzato.")
|
self.bot.send_message(message.chat.id, " Non sei autorizzato.")
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -395,12 +395,12 @@ class TelegramBot:
|
|||||||
scripts_data = []
|
scripts_data = []
|
||||||
|
|
||||||
if not scripts_data:
|
if not scripts_data:
|
||||||
print(f"⚠️ Nessuno script registrato.")
|
print(f" Nessuno script registrato.")
|
||||||
self.bot.send_message(message.chat.id, "⚠️ Nessuno script registrato.")
|
self.bot.send_message(message.chat.id, " Nessuno script registrato.")
|
||||||
return
|
return
|
||||||
|
|
||||||
current_time = time.time()
|
current_time = time.time()
|
||||||
msg = ["🖥️ **Script Registrati:**\n"]
|
msg = [" **Script Registrati:**\n"]
|
||||||
|
|
||||||
for script in scripts_data:
|
for script in scripts_data:
|
||||||
# Calcola la durata
|
# Calcola la durata
|
||||||
@ -414,12 +414,12 @@ class TelegramBot:
|
|||||||
duration_str = f"{int(hours)}h {int(minutes)}m {int(seconds)}s"
|
duration_str = f"{int(hours)}h {int(minutes)}m {int(seconds)}s"
|
||||||
|
|
||||||
# Icona stato
|
# Icona stato
|
||||||
status_icons = {"running": "🟢", "stopped": "🔴", "completed": "⚪"}
|
status_icons = {"running": "", "stopped": "", "completed": ""}
|
||||||
|
|
||||||
# Costruisci riga
|
# Costruisci riga
|
||||||
line = (
|
line = (
|
||||||
f"• ID: `{script['screen_id']}`\n"
|
f"• ID: `{script['screen_id']}`\n"
|
||||||
f"• Stato: {status_icons.get(script['status'], '⚫')}\n"
|
f"• Stato: {status_icons.get(script['status'], '')}\n"
|
||||||
f"• Stop: `/stop {script['screen_id']}`\n"
|
f"• Stop: `/stop {script['screen_id']}`\n"
|
||||||
f"• Screen: `/screen {script['screen_id']}`\n"
|
f"• Screen: `/screen {script['screen_id']}`\n"
|
||||||
f"• Durata: {duration_str}\n"
|
f"• Durata: {duration_str}\n"
|
||||||
@ -437,8 +437,8 @@ class TelegramBot:
|
|||||||
|
|
||||||
def handle_stop_script(self, message):
|
def handle_stop_script(self, message):
|
||||||
if not self.is_authorized(message.from_user.id):
|
if not self.is_authorized(message.from_user.id):
|
||||||
print(f"❌ Non sei autorizzato.")
|
print(f" Non sei autorizzato.")
|
||||||
self.bot.send_message(message.chat.id, "❌ Non sei autorizzato.")
|
self.bot.send_message(message.chat.id, " Non sei autorizzato.")
|
||||||
return
|
return
|
||||||
|
|
||||||
parts = message.text.split()
|
parts = message.text.split()
|
||||||
@ -452,15 +452,15 @@ class TelegramBot:
|
|||||||
running_scripts = [s for s in scripts_data if s["status"] == "running"]
|
running_scripts = [s for s in scripts_data if s["status"] == "running"]
|
||||||
|
|
||||||
if not running_scripts:
|
if not running_scripts:
|
||||||
print(f"⚠️ Nessuno script attivo da fermare.")
|
print(f" Nessuno script attivo da fermare.")
|
||||||
self.bot.send_message(
|
self.bot.send_message(
|
||||||
message.chat.id, "⚠️ Nessuno script attivo da fermare."
|
message.chat.id, " Nessuno script attivo da fermare."
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
msg = "🖥️ **Script Attivi:**\n"
|
msg = " **Script Attivi:**\n"
|
||||||
for script in running_scripts:
|
for script in running_scripts:
|
||||||
msg += f"🔹 `/stop {script['screen_id']}` per fermarlo\n"
|
msg += f" `/stop {script['screen_id']}` per fermarlo\n"
|
||||||
|
|
||||||
print(f"{msg}")
|
print(f"{msg}")
|
||||||
self.bot.send_message(message.chat.id, msg, parse_mode="Markdown")
|
self.bot.send_message(message.chat.id, msg, parse_mode="Markdown")
|
||||||
@ -481,10 +481,10 @@ class TelegramBot:
|
|||||||
|
|
||||||
if len(new_scripts_data) == len(scripts_data):
|
if len(new_scripts_data) == len(scripts_data):
|
||||||
# Nessun elemento rimosso, quindi ID non trovato
|
# Nessun elemento rimosso, quindi ID non trovato
|
||||||
print(f"⚠️ Nessuno script attivo con ID `{screen_id}`.")
|
print(f" Nessuno script attivo con ID `{screen_id}`.")
|
||||||
self.bot.send_message(
|
self.bot.send_message(
|
||||||
message.chat.id,
|
message.chat.id,
|
||||||
f"⚠️ Nessuno script attivo con ID `{screen_id}`.",
|
f" Nessuno script attivo con ID `{screen_id}`.",
|
||||||
parse_mode="Markdown",
|
parse_mode="Markdown",
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
@ -492,14 +492,14 @@ class TelegramBot:
|
|||||||
# Terminare la sessione screen
|
# Terminare la sessione screen
|
||||||
try:
|
try:
|
||||||
subprocess.check_output(["screen", "-S", screen_id, "-X", "quit"])
|
subprocess.check_output(["screen", "-S", screen_id, "-X", "quit"])
|
||||||
print(f"✅ La sessione screen con ID {screen_id} è stata fermata.")
|
print(f" La sessione screen con ID {screen_id} è stata fermata.")
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
print(
|
print(
|
||||||
f"⚠️ Impossibile fermare la sessione screen con ID `{screen_id}`."
|
f" Impossibile fermare la sessione screen con ID `{screen_id}`."
|
||||||
)
|
)
|
||||||
self.bot.send_message(
|
self.bot.send_message(
|
||||||
message.chat.id,
|
message.chat.id,
|
||||||
f"⚠️ Impossibile fermare la sessione screen con ID `{screen_id}`.",
|
f" Impossibile fermare la sessione screen con ID `{screen_id}`.",
|
||||||
parse_mode="Markdown",
|
parse_mode="Markdown",
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
@ -508,27 +508,27 @@ class TelegramBot:
|
|||||||
with open("../../scripts.json", "w") as f:
|
with open("../../scripts.json", "w") as f:
|
||||||
json.dump(new_scripts_data, f, indent=4)
|
json.dump(new_scripts_data, f, indent=4)
|
||||||
|
|
||||||
print(f"✅ Script `{screen_id}` terminato con successo!")
|
print(f" Script `{screen_id}` terminato con successo!")
|
||||||
self.bot.send_message(
|
self.bot.send_message(
|
||||||
message.chat.id,
|
message.chat.id,
|
||||||
f"✅ Script `{screen_id}` terminato con successo!",
|
f" Script `{screen_id}` terminato con successo!",
|
||||||
parse_mode="Markdown",
|
parse_mode="Markdown",
|
||||||
)
|
)
|
||||||
|
|
||||||
def handle_response(self, message):
|
def handle_response(self, message):
|
||||||
text = message.text
|
text = message.text
|
||||||
if self.request_manager.save_response(text):
|
if self.request_manager.save_response(text):
|
||||||
print(f"📥 Risposta salvata correttamente per il tipo {text}")
|
print(f" Risposta salvata correttamente per il tipo {text}")
|
||||||
else:
|
else:
|
||||||
print("⚠️ Nessuna richiesta attiva.")
|
print(" Nessuna richiesta attiva.")
|
||||||
self.bot.reply_to(message, "❌ Nessuna richiesta attiva.")
|
self.bot.reply_to(message, " Nessuna richiesta attiva.")
|
||||||
|
|
||||||
def handle_screen_status(self, message):
|
def handle_screen_status(self, message):
|
||||||
command_parts = message.text.split()
|
command_parts = message.text.split()
|
||||||
if len(command_parts) < 2:
|
if len(command_parts) < 2:
|
||||||
print(f"⚠️ ID mancante nel comando. Usa: /screen <ID>")
|
print(f" ID mancante nel comando. Usa: /screen <ID>")
|
||||||
self.bot.send_message(
|
self.bot.send_message(
|
||||||
message.chat.id, "⚠️ ID mancante nel comando. Usa: /screen <ID>"
|
message.chat.id, " ID mancante nel comando. Usa: /screen <ID>"
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -539,8 +539,8 @@ class TelegramBot:
|
|||||||
# Verifica se lo screen con l'ID specificato esiste
|
# Verifica se lo screen con l'ID specificato esiste
|
||||||
existing_screens = subprocess.check_output(["screen", "-list"]).decode('utf-8')
|
existing_screens = subprocess.check_output(["screen", "-list"]).decode('utf-8')
|
||||||
if screen_id not in existing_screens:
|
if screen_id not in existing_screens:
|
||||||
print(f"⚠️ La sessione screen con ID {screen_id} non esiste.")
|
print(f" La sessione screen con ID {screen_id} non esiste.")
|
||||||
self.bot.send_message(message.chat.id, f"⚠️ La sessione screen con ID {screen_id} non esiste.")
|
self.bot.send_message(message.chat.id, f" La sessione screen con ID {screen_id} non esiste.")
|
||||||
return
|
return
|
||||||
|
|
||||||
# Cattura l'output della screen
|
# Cattura l'output della screen
|
||||||
@ -549,17 +549,17 @@ class TelegramBot:
|
|||||||
check=True,
|
check=True,
|
||||||
)
|
)
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
print(f"❌ Errore durante la cattura dell'output della screen: {e}")
|
print(f" Errore durante la cattura dell'output della screen: {e}")
|
||||||
self.bot.send_message(
|
self.bot.send_message(
|
||||||
message.chat.id,
|
message.chat.id,
|
||||||
f"❌ Errore durante la cattura dell'output della screen: {e}",
|
f" Errore durante la cattura dell'output della screen: {e}",
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
if not os.path.exists(temp_file):
|
if not os.path.exists(temp_file):
|
||||||
print(f"❌ Impossibile catturare l'output della screen.")
|
print(f" Impossibile catturare l'output della screen.")
|
||||||
self.bot.send_message(
|
self.bot.send_message(
|
||||||
message.chat.id, f"❌ Impossibile catturare l'output della screen."
|
message.chat.id, f" Impossibile catturare l'output della screen."
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -594,18 +594,18 @@ class TelegramBot:
|
|||||||
cleaned_output = re.sub(r'segments\.py:\d+', '', cleaned_output)
|
cleaned_output = re.sub(r'segments\.py:\d+', '', cleaned_output)
|
||||||
|
|
||||||
# Invia l'output pulito
|
# Invia l'output pulito
|
||||||
print(f"📄 Output della screen {screen_id}:\n{cleaned_output}")
|
print(f" Output della screen {screen_id}:\n{cleaned_output}")
|
||||||
self._send_long_message(
|
self._send_long_message(
|
||||||
message.chat.id, f"📄 Output della screen {screen_id}:\n{cleaned_output}"
|
message.chat.id, f" Output della screen {screen_id}:\n{cleaned_output}"
|
||||||
)
|
)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(
|
print(
|
||||||
f"❌ Errore durante la lettura o l'invio dell'output della screen: {e}"
|
f" Errore durante la lettura o l'invio dell'output della screen: {e}"
|
||||||
)
|
)
|
||||||
self.bot.send_message(
|
self.bot.send_message(
|
||||||
message.chat.id,
|
message.chat.id,
|
||||||
f"❌ Errore durante la lettura o l'invio dell'output della screen: {e}",
|
f" Errore durante la lettura o l'invio dell'output della screen: {e}",
|
||||||
)
|
)
|
||||||
|
|
||||||
# Cancella il file temporaneo
|
# Cancella il file temporaneo
|
||||||
@ -665,14 +665,14 @@ class TelegramBot:
|
|||||||
return response
|
return response
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
print(f"⚠️ Timeout: nessuna risposta ricevuta.")
|
print(f" Timeout: nessuna risposta ricevuta.")
|
||||||
for chat_id in self.authorized_users: # Manda a tutti gli ID autorizzati
|
for chat_id in self.authorized_users: # Manda a tutti gli ID autorizzati
|
||||||
self.bot.send_message(chat_id, "⚠️ Timeout: nessuna risposta ricevuta.")
|
self.bot.send_message(chat_id, " Timeout: nessuna risposta ricevuta.")
|
||||||
self.request_manager.clear_file()
|
self.request_manager.clear_file()
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
print("🚀 Avvio del bot...")
|
print(" Avvio del bot...")
|
||||||
with open("../../scripts.json", "w") as f:
|
with open("../../scripts.json", "w") as f:
|
||||||
json.dump([], f)
|
json.dump([], f)
|
||||||
self.bot.infinity_polling()
|
self.bot.infinity_polling()
|
||||||
|
@ -39,7 +39,7 @@ class ConfigManager:
|
|||||||
self._validate_and_update_config()
|
self._validate_and_update_config()
|
||||||
self._read_initial_config()
|
self._read_initial_config()
|
||||||
|
|
||||||
console.print(f"[bold cyan]📂 Configuration file path:[/bold cyan] [green]{self.file_path}[/green]")
|
console.print(f"[bold cyan]Configuration file path:[/bold cyan] [green]{self.file_path}[/green]")
|
||||||
|
|
||||||
def _validate_and_update_config(self) -> None:
|
def _validate_and_update_config(self) -> None:
|
||||||
"""Validate local config against reference config and update missing keys."""
|
"""Validate local config against reference config and update missing keys."""
|
||||||
@ -49,10 +49,10 @@ class ConfigManager:
|
|||||||
if os.path.exists(self.file_path):
|
if os.path.exists(self.file_path):
|
||||||
with open(self.file_path, 'r') as f:
|
with open(self.file_path, 'r') as f:
|
||||||
local_config = json.load(f)
|
local_config = json.load(f)
|
||||||
console.print("[bold cyan]📖 Local configuration found.[/bold cyan]")
|
console.print("[bold cyan]Local configuration found.[/bold cyan]")
|
||||||
|
|
||||||
# Download reference config
|
# Download reference config
|
||||||
console.print("[bold cyan]🌍 Downloading reference configuration...[/bold cyan]")
|
console.print("[bold cyan]Downloading reference configuration...[/bold cyan]")
|
||||||
response = requests.get(self.reference_config_url)
|
response = requests.get(self.reference_config_url)
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
raise Exception(f"Failed to download reference config. Status code: {response.status_code}")
|
raise Exception(f"Failed to download reference config. Status code: {response.status_code}")
|
||||||
@ -65,14 +65,14 @@ class ConfigManager:
|
|||||||
# Save the merged config
|
# Save the merged config
|
||||||
with open(self.file_path, 'w') as f:
|
with open(self.file_path, 'w') as f:
|
||||||
json.dump(merged_config, f, indent=4)
|
json.dump(merged_config, f, indent=4)
|
||||||
console.print("[bold green]✅ Configuration updated with missing keys.[/bold green]")
|
console.print("[bold green]Configuration updated with missing keys.[/bold green]")
|
||||||
else:
|
else:
|
||||||
console.print("[bold green]✅ Configuration is up to date.[/bold green]")
|
console.print("[bold green]Configuration is up to date.[/bold green]")
|
||||||
|
|
||||||
self.config = merged_config
|
self.config = merged_config
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
console.print(f"[bold red]❌ Error validating configuration: {e}[/bold red]")
|
console.print(f"[bold red]Error validating configuration: {e}[/bold red]")
|
||||||
if not self.config:
|
if not self.config:
|
||||||
# If validation failed and we have no config, download the reference config
|
# If validation failed and we have no config, download the reference config
|
||||||
self.download_requirements(self.reference_config_url, self.file_path)
|
self.download_requirements(self.reference_config_url, self.file_path)
|
||||||
@ -109,38 +109,38 @@ class ConfigManager:
|
|||||||
self.use_api = self.config.get('DEFAULT', {}).get('use_api', True)
|
self.use_api = self.config.get('DEFAULT', {}).get('use_api', True)
|
||||||
else:
|
else:
|
||||||
self.use_api = True # Default to True if config file doesn't exist
|
self.use_api = True # Default to True if config file doesn't exist
|
||||||
console.print("[bold yellow]⚠️ Configuration file not found. Using default settings.[/bold yellow]")
|
console.print("[bold yellow]Configuration file not found. Using default settings.[/bold yellow]")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.use_api = True # Default to True in case of error
|
self.use_api = True # Default to True in case of error
|
||||||
logging.error(f"❌ Error reading initial configuration: {e}")
|
logging.error(f"Error reading initial configuration: {e}")
|
||||||
|
|
||||||
def read_config(self) -> None:
|
def read_config(self) -> None:
|
||||||
"""Read the configuration file."""
|
"""Read the configuration file."""
|
||||||
try:
|
try:
|
||||||
logging.info(f"📖 Reading file: {self.file_path}")
|
logging.info(f"Reading file: {self.file_path}")
|
||||||
|
|
||||||
# Check if file exists
|
# Check if file exists
|
||||||
if os.path.exists(self.file_path):
|
if os.path.exists(self.file_path):
|
||||||
with open(self.file_path, 'r') as f:
|
with open(self.file_path, 'r') as f:
|
||||||
self.config = json.load(f)
|
self.config = json.load(f)
|
||||||
console.print("[bold green]✅ Configuration file loaded successfully.[/bold green]")
|
console.print("[bold green]Configuration file loaded successfully.[/bold green]")
|
||||||
else:
|
else:
|
||||||
console.print("[bold yellow]⚠️ Configuration file not found. Downloading...[/bold yellow]")
|
console.print("[bold yellow]Configuration file not found. Downloading...[/bold yellow]")
|
||||||
self.download_requirements(self.reference_config_url, self.file_path)
|
self.download_requirements(self.reference_config_url, self.file_path)
|
||||||
|
|
||||||
# Load the downloaded config.json into the config attribute
|
# Load the downloaded config.json into the config attribute
|
||||||
with open(self.file_path, 'r') as f:
|
with open(self.file_path, 'r') as f:
|
||||||
self.config = json.load(f)
|
self.config = json.load(f)
|
||||||
console.print("[bold green]✅ Configuration file downloaded and saved.[/bold green]")
|
console.print("[bold green]Configuration file downloaded and saved.[/bold green]")
|
||||||
|
|
||||||
# Update site configuration separately
|
# Update site configuration separately
|
||||||
self.update_site_config()
|
self.update_site_config()
|
||||||
|
|
||||||
console.print("[bold cyan]🔧 Configuration file processing complete.[/bold cyan]")
|
console.print("[bold cyan]Configuration file processing complete.[/bold cyan]")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f"❌ Error reading configuration file: {e}")
|
logging.error(f"Error reading configuration file: {e}")
|
||||||
|
|
||||||
def download_requirements(self, url: str, filename: str) -> None:
|
def download_requirements(self, url: str, filename: str) -> None:
|
||||||
"""
|
"""
|
||||||
@ -151,20 +151,20 @@ class ConfigManager:
|
|||||||
filename (str): The local filename to save the file as.
|
filename (str): The local filename to save the file as.
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
logging.info(f"🌍 Downloading {filename} from {url}...")
|
logging.info(f"Downloading {filename} from {url}...")
|
||||||
response = requests.get(url)
|
response = requests.get(url)
|
||||||
|
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
with open(filename, 'wb') as f:
|
with open(filename, 'wb') as f:
|
||||||
f.write(response.content)
|
f.write(response.content)
|
||||||
console.print(f"[bold green]✅ Successfully downloaded {filename}.[/bold green]")
|
console.print(f"[bold green]Successfully downloaded {filename}.[/bold green]")
|
||||||
|
|
||||||
else:
|
else:
|
||||||
logging.error(f"❌ Failed to download {filename}. HTTP Status code: {response.status_code}")
|
logging.error(f"Failed to download {filename}. HTTP Status code: {response.status_code}")
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f"❌ Failed to download {filename}: {e}")
|
logging.error(f"Failed to download {filename}: {e}")
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
def update_site_config(self) -> None:
|
def update_site_config(self) -> None:
|
||||||
@ -177,31 +177,31 @@ class ConfigManager:
|
|||||||
}
|
}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
console.print("[bold cyan]🌍 Fetching SITE data from API...[/bold cyan]")
|
console.print("[bold cyan]Fetching SITE data from API...[/bold cyan]")
|
||||||
response = requests.get("https://zvfngpoxwrgswnzytadh.supabase.co/rest/v1/public", headers=headers)
|
response = requests.get("https://zvfngpoxwrgswnzytadh.supabase.co/rest/v1/public", headers=headers)
|
||||||
|
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
self.configSite = response.json()[0]['data']
|
self.configSite = response.json()[0]['data']
|
||||||
console.print("[bold green]✅ SITE data successfully fetched.[/bold green]")
|
console.print("[bold green]SITE data successfully fetched.[/bold green]")
|
||||||
else:
|
else:
|
||||||
console.print(f"[bold red]❌ Failed to fetch SITE data. HTTP Status code: {response.status_code}[/bold red]")
|
console.print(f"[bold red]Failed to fetch SITE data. HTTP Status code: {response.status_code}[/bold red]")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
console.print(f"[bold red]❌ Error fetching SITE data: {e}[/bold red]")
|
console.print(f"[bold red]Error fetching SITE data: {e}[/bold red]")
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
if os.path.exists(self.domains_path):
|
if os.path.exists(self.domains_path):
|
||||||
console.print("[bold cyan]📖 Reading domains from local file...[/bold cyan]")
|
console.print("[bold cyan]Reading domains from local file...[/bold cyan]")
|
||||||
with open(self.domains_path, 'r') as f:
|
with open(self.domains_path, 'r') as f:
|
||||||
self.configSite = json.load(f)
|
self.configSite = json.load(f)
|
||||||
console.print("[bold green]✅ Domains loaded successfully from local file.[/bold green]")
|
console.print("[bold green]Domains loaded successfully from local file.[/bold green]")
|
||||||
else:
|
else:
|
||||||
error_msg = "❌ domains.json not found and API usage is disabled"
|
error_msg = "domains.json not found and API usage is disabled"
|
||||||
console.print(f"[bold red]{error_msg}[/bold red]")
|
console.print(f"[bold red]{error_msg}[/bold red]")
|
||||||
raise FileNotFoundError(error_msg)
|
raise FileNotFoundError(error_msg)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
console.print(f"[bold red]❌ Error reading domains file: {e}[/bold red]")
|
console.print(f"[bold red]Error reading domains file: {e}[/bold red]")
|
||||||
raise
|
raise
|
||||||
|
|
||||||
def read_key(self, section: str, key: str, data_type: type = str, from_site: bool = False) -> Any:
|
def read_key(self, section: str, key: str, data_type: type = str, from_site: bool = False) -> Any:
|
||||||
|
@ -165,7 +165,7 @@ class TVShowManager:
|
|||||||
else:
|
else:
|
||||||
choices = [str(i) for i in range(max_int_input + 1)] + ["q", "quit", "b", "back"]
|
choices = [str(i) for i in range(max_int_input + 1)] + ["q", "quit", "b", "back"]
|
||||||
prompt_msg = "[cyan]Insert media [red]index"
|
prompt_msg = "[cyan]Insert media [red]index"
|
||||||
telegram_msg = "Scegli il contenuto da scaricare:\n📺 Serie TV - 🎞️ Film - 🌀 Anime\noppure `back` per tornare indietro"
|
telegram_msg = "Scegli il contenuto da scaricare:\n Serie TV - Film - Anime\noppure `back` per tornare indietro"
|
||||||
|
|
||||||
if is_telegram:
|
if is_telegram:
|
||||||
key = bot.ask("select_title", telegram_msg, None)
|
key = bot.ask("select_title", telegram_msg, None)
|
||||||
@ -201,7 +201,7 @@ class TVShowManager:
|
|||||||
else:
|
else:
|
||||||
choices = [str(i) for i in range(max_int_input + 1)] + ["q", "quit", "b", "back"]
|
choices = [str(i) for i in range(max_int_input + 1)] + ["q", "quit", "b", "back"]
|
||||||
prompt_msg = "[cyan]Insert media [red]index"
|
prompt_msg = "[cyan]Insert media [red]index"
|
||||||
telegram_msg = "Scegli il contenuto da scaricare:\n📺 Serie TV - 🎞️ Film - 🌀 Anime\noppure `back` per tornare indietro"
|
telegram_msg = "Scegli il contenuto da scaricare:\n Serie TV - Film - Anime\noppure `back` per tornare indietro"
|
||||||
|
|
||||||
if is_telegram:
|
if is_telegram:
|
||||||
key = bot.ask("select_title", telegram_msg, None)
|
key = bot.ask("select_title", telegram_msg, None)
|
||||||
|
@ -149,7 +149,7 @@ def initialize():
|
|||||||
|
|
||||||
def restart_script():
|
def restart_script():
|
||||||
"""Riavvia lo script con gli stessi argomenti della riga di comando."""
|
"""Riavvia lo script con gli stessi argomenti della riga di comando."""
|
||||||
print("\n🔄 Riavvio dello script...\n")
|
print("\nRiavvio dello script...\n")
|
||||||
python = sys.executable
|
python = sys.executable
|
||||||
os.execv(python, [python] + sys.argv)
|
os.execv(python, [python] + sys.argv)
|
||||||
|
|
||||||
@ -157,31 +157,31 @@ def restart_script():
|
|||||||
def force_exit():
|
def force_exit():
|
||||||
"""Forza la chiusura dello script in qualsiasi contesto."""
|
"""Forza la chiusura dello script in qualsiasi contesto."""
|
||||||
|
|
||||||
print("\n🛑 Chiusura dello script in corso...")
|
print("\nChiusura dello script in corso...")
|
||||||
|
|
||||||
# 1️⃣ Chiudi tutti i thread tranne il principale
|
# 1 Chiudi tutti i thread tranne il principale
|
||||||
for t in threading.enumerate():
|
for t in threading.enumerate():
|
||||||
if t is not threading.main_thread():
|
if t is not threading.main_thread():
|
||||||
print(f"🔄 Chiusura thread: {t.name}")
|
print(f"Chiusura thread: {t.name}")
|
||||||
t.join(timeout=1)
|
t.join(timeout=1)
|
||||||
|
|
||||||
# 2️⃣ Ferma asyncio, se attivo
|
# 2 Ferma asyncio, se attivo
|
||||||
try:
|
try:
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
if loop.is_running():
|
if loop.is_running():
|
||||||
print("⚡ Arresto del loop asyncio...")
|
print("Arresto del loop asyncio...")
|
||||||
loop.stop()
|
loop.stop()
|
||||||
except RuntimeError:
|
except RuntimeError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# 3️⃣ Esce con sys.exit(), se fallisce usa os._exit()
|
# 3 Esce con sys.exit(), se fallisce usa os._exit()
|
||||||
try:
|
try:
|
||||||
print("✅ Uscita con sys.exit(0)")
|
print("Uscita con sys.exit(0)")
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
except SystemExit:
|
except SystemExit:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
print("🚨 Uscita forzata con os._exit(0)")
|
print("Uscita forzata con os._exit(0)")
|
||||||
os._exit(0)
|
os._exit(0)
|
||||||
|
|
||||||
|
|
||||||
@ -189,7 +189,7 @@ def main(script_id = 0):
|
|||||||
|
|
||||||
if TELEGRAM_BOT:
|
if TELEGRAM_BOT:
|
||||||
bot = get_bot_instance()
|
bot = get_bot_instance()
|
||||||
bot.send_message(f"🏁 Avviato script {script_id}", None)
|
bot.send_message(f"Avviato script {script_id}", None)
|
||||||
|
|
||||||
start = time.time()
|
start = time.time()
|
||||||
|
|
||||||
@ -305,24 +305,15 @@ def main(script_id = 0):
|
|||||||
) + "[white])"
|
) + "[white])"
|
||||||
|
|
||||||
if TELEGRAM_BOT:
|
if TELEGRAM_BOT:
|
||||||
|
|
||||||
# Mappa delle emoji per i colori
|
|
||||||
emoji_map = {
|
|
||||||
"yellow": "🟡", # Giallo
|
|
||||||
"red": "🔴", # Rosso
|
|
||||||
"blue": "🔵", # Blu
|
|
||||||
"green": "🟢" # Verde
|
|
||||||
}
|
|
||||||
|
|
||||||
# Display the category legend in a single line
|
# Display the category legend in a single line
|
||||||
category_legend_str = "Categorie: \n" + " | ".join([
|
category_legend_str = "Categorie: \n" + " | ".join([
|
||||||
f"{emoji_map.get(color, '⚪')} {category.capitalize()}"
|
f"{category.capitalize()}" for category in color_map.keys()
|
||||||
for category, color in color_map.items()
|
|
||||||
])
|
])
|
||||||
|
|
||||||
# Costruisci il messaggio con le emoji al posto dei colori
|
# Costruisci il messaggio senza emoji
|
||||||
prompt_message = "Inserisci il sito:\n" + "\n".join(
|
prompt_message = "Inserisci il sito:\n" + "\n".join(
|
||||||
[f"{key}: {emoji_map[color_map[label[1]]]} {label[0]}" for key, label in choice_labels.items()]
|
[f"{key}: {label[0]}" for key, label in choice_labels.items()]
|
||||||
)
|
)
|
||||||
|
|
||||||
console.print(f"\n{prompt_message}")
|
console.print(f"\n{prompt_message}")
|
||||||
@ -340,6 +331,7 @@ def main(script_id = 0):
|
|||||||
# Run the corresponding function based on user input
|
# Run the corresponding function based on user input
|
||||||
if category in input_to_function:
|
if category in input_to_function:
|
||||||
run_function(input_to_function[category], search_terms = args.search)
|
run_function(input_to_function[category], search_terms = args.search)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
||||||
if TELEGRAM_BOT:
|
if TELEGRAM_BOT:
|
||||||
@ -358,4 +350,4 @@ def main(script_id = 0):
|
|||||||
# Delete script_id
|
# Delete script_id
|
||||||
script_id = TelegramSession.get_session()
|
script_id = TelegramSession.get_session()
|
||||||
if script_id != "unknown":
|
if script_id != "unknown":
|
||||||
TelegramSession.deleteScriptId(script_id)
|
TelegramSession.deleteScriptId(script_id)
|
Loading…
x
Reference in New Issue
Block a user