mirror of
https://github.com/Arrowar/StreamingCommunity.git
synced 2025-06-07 12:05:35 +00:00
Update __init__.py
This commit is contained in:
parent
e0b2af3fd5
commit
633130c28c
@ -17,11 +17,13 @@ from StreamingCommunity.Api.Template.config_loader import site_constant
|
|||||||
from StreamingCommunity.Api.Template.Class.SearchType import MediaItem
|
from StreamingCommunity.Api.Template.Class.SearchType import MediaItem
|
||||||
from StreamingCommunity.TelegramHelp.telegram_bot import get_bot_instance
|
from StreamingCommunity.TelegramHelp.telegram_bot import get_bot_instance
|
||||||
|
|
||||||
|
|
||||||
# Logic class
|
# Logic class
|
||||||
from .site import title_search, table_show_manager, media_search_manager
|
from .site import title_search, table_show_manager, media_search_manager
|
||||||
from .film import download_film
|
from .film import download_film
|
||||||
from .series import download_series
|
from .series import download_series
|
||||||
|
|
||||||
|
|
||||||
# Variable
|
# Variable
|
||||||
indice = 0
|
indice = 0
|
||||||
_useFor = "Film_&_Serie"
|
_useFor = "Film_&_Serie"
|
||||||
@ -38,38 +40,38 @@ def get_user_input(string_to_search: str = None):
|
|||||||
Asks the user to input a search term.
|
Asks the user to input a search term.
|
||||||
Handles both Telegram bot input and direct input.
|
Handles both Telegram bot input and direct input.
|
||||||
"""
|
"""
|
||||||
# Se string_to_search è già fornito (es. da riga di comando o chiamata precedente), usalo.
|
|
||||||
if string_to_search is not None:
|
if string_to_search is not None:
|
||||||
return string_to_search.strip()
|
return string_to_search.strip()
|
||||||
|
|
||||||
# Altrimenti, chiedi all'utente
|
|
||||||
if site_constant.TELEGRAM_BOT:
|
if site_constant.TELEGRAM_BOT:
|
||||||
bot = get_bot_instance()
|
bot = get_bot_instance()
|
||||||
user_response = bot.ask(
|
user_response = bot.ask(
|
||||||
"key_search", # Tipo di richiesta
|
"key_search", # Tipo di richiesta
|
||||||
"Enter the search term\nor type 'back' to return to the menu: ", # Messaggio per l'utente
|
"Enter the search term\nor type 'back' to return to the menu: ",
|
||||||
None # Nessuna scelta predefinita, l'utente digita
|
None
|
||||||
)
|
)
|
||||||
|
|
||||||
if user_response is None: # Timeout o nessun input
|
if user_response is None:
|
||||||
bot.send_message("Timeout: Nessun termine di ricerca inserito.", None)
|
bot.send_message("Timeout: Nessun termine di ricerca inserito.", None)
|
||||||
return None # Indica che non c'è input
|
return None
|
||||||
|
|
||||||
if user_response.lower() == 'back':
|
if user_response.lower() == 'back':
|
||||||
bot.send_message("Ritorno al menu principale...", None)
|
bot.send_message("Ritorno al menu principale...", None)
|
||||||
|
|
||||||
# Gestire il "back" qui è complesso perché Popen e sys.exit terminano lo script corrente.
|
# Gestire il "back" qui è complesso perché Popen e sys.exit terminano lo script corrente.
|
||||||
# Idealmente, la logica di "back" dovrebbe essere gestita dal chiamante (run.py)
|
# Idealmente, la logica di "back" dovrebbe essere gestita dal chiamante (run.py)
|
||||||
# o restituendo un valore speciale. Per ora, manteniamo il riavvio ma è subottimale.
|
# o restituendo un valore speciale. Per ora, manteniamo il riavvio ma è subottimale.
|
||||||
try:
|
try:
|
||||||
subprocess.Popen([sys.executable] + sys.argv)
|
subprocess.Popen([sys.executable] + sys.argv)
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
bot.send_message(f"Errore durante il tentativo di riavvio: {e}", None)
|
bot.send_message(f"Errore durante il tentativo di riavvio: {e}", None)
|
||||||
return None # Non continuare se il riavvio fallisce
|
return None
|
||||||
|
|
||||||
return user_response.strip()
|
return user_response.strip()
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Input da console
|
|
||||||
return msg.ask(f"\n[purple]Insert a word to search in [green]{site_constant.SITE_NAME}").strip()
|
return msg.ask(f"\n[purple]Insert a word to search in [green]{site_constant.SITE_NAME}").strip()
|
||||||
|
|
||||||
def process_search_result(select_title, selections=None):
|
def process_search_result(select_title, selections=None):
|
||||||
@ -81,13 +83,13 @@ def process_search_result(select_title, selections=None):
|
|||||||
selections (dict, optional): Dictionary containing selection inputs that bypass manual input
|
selections (dict, optional): Dictionary containing selection inputs that bypass manual input
|
||||||
{'season': season_selection, 'episode': episode_selection}
|
{'season': season_selection, 'episode': episode_selection}
|
||||||
"""
|
"""
|
||||||
if not select_title: # Se select_title è None (es. l'utente non ha scelto o errore in get_select_title)
|
if not select_title:
|
||||||
if site_constant.TELEGRAM_BOT:
|
if site_constant.TELEGRAM_BOT:
|
||||||
bot = get_bot_instance()
|
bot = get_bot_instance()
|
||||||
bot.send_message("Nessun titolo selezionato o selezione annullata.", None)
|
bot.send_message("Nessun titolo selezionato o selezione annullata.", None)
|
||||||
else:
|
else:
|
||||||
console.print("[yellow]Nessun titolo selezionato o selezione annullata.")
|
console.print("[yellow]Nessun titolo selezionato o selezione annullata.")
|
||||||
return # Esce se non c'è un titolo valido
|
return
|
||||||
|
|
||||||
if select_title.type == 'tv':
|
if select_title.type == 'tv':
|
||||||
season_selection = None
|
season_selection = None
|
||||||
@ -98,6 +100,7 @@ def process_search_result(select_title, selections=None):
|
|||||||
episode_selection = selections.get('episode')
|
episode_selection = selections.get('episode')
|
||||||
|
|
||||||
download_series(select_title, season_selection, episode_selection)
|
download_series(select_title, season_selection, episode_selection)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
download_film(select_title)
|
download_film(select_title)
|
||||||
|
|
||||||
@ -111,78 +114,33 @@ def search(string_to_search: str = None, get_onlyDatabase: bool = False, direct_
|
|||||||
direct_item (dict, optional): Direct item to process (bypass search).
|
direct_item (dict, optional): Direct item to process (bypass search).
|
||||||
selections (dict, optional): Dictionary containing selection inputs that bypass manual input.
|
selections (dict, optional): Dictionary containing selection inputs that bypass manual input.
|
||||||
"""
|
"""
|
||||||
bot = None # Inizializza bot a None
|
bot = None
|
||||||
if site_constant.TELEGRAM_BOT:
|
if site_constant.TELEGRAM_BOT:
|
||||||
bot = get_bot_instance()
|
bot = get_bot_instance()
|
||||||
|
|
||||||
if direct_item:
|
if direct_item:
|
||||||
# Se un item è fornito direttamente, lo processa e esce.
|
|
||||||
# Utile per test o integrazioni future.
|
|
||||||
select_title_obj = MediaItem(**direct_item)
|
select_title_obj = MediaItem(**direct_item)
|
||||||
process_search_result(select_title_obj, selections)
|
process_search_result(select_title_obj, selections)
|
||||||
return
|
return
|
||||||
|
|
||||||
# CORREZIONE BUG 1: Usa get_user_input per ottenere il termine di ricerca
|
|
||||||
# string_to_search qui è quello passato come argomento alla funzione search.
|
|
||||||
actual_search_query = get_user_input(string_to_search)
|
actual_search_query = get_user_input(string_to_search)
|
||||||
# rimosso il blocco 'if string_to_search is None:' get_user_input è già progettata per gestire il caso in cui string_to_search sia None
|
|
||||||
|
|
||||||
return string_to_search
|
if not actual_search_query: # Se l'utente ha scritto 'back' (gestito da get_user_input) o input vuoto/timeout
|
||||||
|
if bot:
|
||||||
def process_search_result(select_title, selections=None, proxy=None):
|
if actual_search_query is None:
|
||||||
"""
|
bot.send_message("Termine di ricerca non fornito. Ritorno al menu precedente.", None)
|
||||||
Handles the search result and initiates the download for either a film or series.
|
|
||||||
|
|
||||||
Parameters:
|
|
||||||
select_title (MediaItem): The selected media item
|
|
||||||
selections (dict, optional): Dictionary containing selection inputs that bypass manual input
|
|
||||||
{'season': season_selection, 'episode': episode_selection}
|
|
||||||
"""
|
|
||||||
if select_title.type == 'tv':
|
|
||||||
season_selection = None
|
|
||||||
episode_selection = None
|
|
||||||
|
|
||||||
if selections:
|
|
||||||
season_selection = selections.get('season')
|
|
||||||
episode_selection = selections.get('episode')
|
|
||||||
|
|
||||||
download_series(select_title, season_selection, episode_selection, proxy)
|
|
||||||
|
|
||||||
else:
|
|
||||||
download_film(select_title, proxy) # Assuming download_film also needs proxy
|
|
||||||
|
|
||||||
def search(string_to_search: str = None, get_onlyDatabase: bool = False, direct_item: dict = None, selections: dict = None):
|
|
||||||
"""
|
|
||||||
Main function of the application for search.
|
|
||||||
|
|
||||||
Parameters:
|
|
||||||
string_to_search (str, optional): String to search for
|
|
||||||
get_onlyDatabase (bool, optional): If True, return only the database object
|
|
||||||
direct_item (dict, optional): Direct item to process (bypass search)
|
|
||||||
selections (dict, optional): Dictionary containing selection inputs that bypass manual input
|
|
||||||
{'season': season_selection, 'episode': episode_selection}
|
|
||||||
"""
|
|
||||||
if direct_item:
|
|
||||||
select_title = MediaItem(**direct_item)
|
|
||||||
process_search_result(select_title, selections)
|
|
||||||
return
|
return
|
||||||
|
|
||||||
if string_to_search is None:
|
# title_search (da site.py) MOSTRA la lista dei risultati all'utente via bot.
|
||||||
if site_constant.TELEGRAM_BOT:
|
len_database = title_search(actual_search_query)
|
||||||
bot = get_bot_instance()
|
|
||||||
string_to_search = bot.ask(
|
|
||||||
"key_search",
|
|
||||||
f"Enter the search term\nor type 'back' to return to the menu: ",
|
|
||||||
None
|
|
||||||
)
|
|
||||||
|
|
||||||
if string_to_search == 'back':
|
if string_to_search == 'back':
|
||||||
|
|
||||||
# Restart the script
|
# Restart the script
|
||||||
subprocess.Popen([sys.executable] + sys.argv)
|
subprocess.Popen([sys.executable] + sys.argv)
|
||||||
sys.exit()
|
sys.exit()
|
||||||
else:
|
else:
|
||||||
string_to_search = msg.ask(f"\n[purple]Insert a word to search in [green]{site_constant.SITE_NAME}").strip()
|
string_to_search = msg.ask(f"\n[purple]Insert a word to search in [green]{site_constant.SITE_NAME}").strip()
|
||||||
|
|
||||||
# Search on database
|
# Search on database
|
||||||
finder = ProxyFinder(site_constant.FULL_URL)
|
finder = ProxyFinder(site_constant.FULL_URL)
|
||||||
@ -194,10 +152,22 @@ def search(string_to_search: str = None, get_onlyDatabase: bool = False, direct_
|
|||||||
return media_search_manager
|
return media_search_manager
|
||||||
|
|
||||||
if len_database > 0:
|
if len_database > 0:
|
||||||
select_title = get_select_title(table_show_manager, media_search_manager)
|
|
||||||
process_search_result(select_title, selections, proxy)
|
# Se ci sono risultati, chiama get_select_title per chiedere all'utente quale selezionare.
|
||||||
|
select_title_obj = get_select_title(
|
||||||
|
table_show_manager,
|
||||||
|
media_search_manager,
|
||||||
|
len_database
|
||||||
|
)
|
||||||
|
|
||||||
|
process_search_result(select_title_obj, selections)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# If no results are found, ask again
|
no_results_message = f"Nessun risultato trovato per: '{actual_search_query}'"
|
||||||
console.print(f"\n[red]Nothing matching was found for[white]: [purple]{string_to_search}")
|
if bot:
|
||||||
search()
|
bot.send_message(no_results_message, None)
|
||||||
|
else:
|
||||||
|
console.print(f"\n[red]Nothing matching was found for[white]: [purple]{actual_search_query}")
|
||||||
|
|
||||||
|
# NON chiamare search() ricorsivamente.
|
||||||
|
return
|
||||||
|
Loading…
x
Reference in New Issue
Block a user