@@ -207,6 +207,13 @@ def main(script_id = 0):
207207 "torrent" : "white"
208208 }
209209
210+ category_map = {
211+ 1 : "anime" ,
212+ 2 : "film_&_serie" ,
213+ 3 : "serie" ,
214+ 4 : "torrent"
215+ }
216+
210217 if TELEGRAM_BOT :
211218 bot = get_bot_instance ()
212219 bot .send_message (f"Avviato script { script_id } " , None )
@@ -271,6 +278,11 @@ def main(script_id = 0):
271278 '--global' , action = 'store_true' , help = 'Perform a global search across multiple sites.'
272279 )
273280
281+ # Add category selection argument
282+ parser .add_argument (
283+ '--category' , type = int , help = 'Select category directly (1: anime, 2: film_&_serie, 3: serie, 4: torrent).'
284+ )
285+
274286 # Add arguments for search functions
275287 parser .add_argument ('-s' , '--search' , default = None , help = 'Search terms' )
276288
@@ -320,35 +332,60 @@ def main(script_id = 0):
320332 except Exception as e :
321333 console .print (f"[red]Error mapping module { module_name } : { str (e )} " )
322334
323- # Display the category legend
324- legend_text = " | " .join ([f"[{ color } ]{ category .capitalize ()} [/{ color } ]" for category , color in color_map .items ()])
325- console .print (f"\n [bold green]Category Legend:[/bold green] { legend_text } " )
335+ if args .category :
336+ selected_category = category_map .get (args .category )
337+ category_sites = []
338+ for key , label in choice_labels .items ():
339+ if label [1 ] == selected_category :
340+ category_sites .append ((key , label [0 ]))
326341
327- # Construct prompt with proper color mapping
328- prompt_message = "[green]Insert category [white](" + ", " .join (
329- [f"[{ color_map .get (label [1 ], 'white' )} ]{ key } : { label [0 ]} [/{ color_map .get (label [1 ], 'white' )} ]"
330- for key , label in choice_labels .items ()]
331- ) + "[white])"
342+ if len (category_sites ) == 1 :
343+ category = category_sites [0 ][0 ]
344+ console .print (f"[green]Selezionato automaticamente: { category_sites [0 ][1 ]} [/green]" )
332345
333- if TELEGRAM_BOT :
334- category_legend_str = "Categorie: \n " + " | " .join ([
335- f"{ category .capitalize ()} " for category in color_map .keys ()
336- ])
346+ else :
347+ sito_prompt_items = [f"[{ color_map .get (selected_category , 'white' )} ]({ k } ) { v } [/{ color_map .get (selected_category , 'white' )} ]"
348+ for k , v in category_sites ]
349+ sito_prompt_line = ", " .join (sito_prompt_items )
350+
351+ if TELEGRAM_BOT :
352+ console .print (f"\n Insert site: { sito_prompt_line } " )
353+ category = bot .ask (
354+ "select_site" ,
355+ f"Insert site: { sito_prompt_line } " ,
356+ None
357+ )
358+ else :
359+ category = msg .ask (f"\n [cyan]Insert site: { sito_prompt_line } " , choices = [k for k , _ in category_sites ], show_choices = False )
337360
338- prompt_message = "Inserisci il sito:\n " + "\n " .join (
339- [f"{ key } : { label [0 ]} " for key , label in choice_labels .items ()]
361+ else :
362+ legend_text = " | " .join ([f"[{ color } ]{ category .capitalize ()} [/{ color } ]" for category , color in color_map .items ()])
363+ console .print (f"\n [bold cyan]Category Legend:[/bold cyan] { legend_text } " )
364+
365+ prompt_message = "[cyan]Insert site: " + ", " .join (
366+ [f"[{ color_map .get (label [1 ], 'white' )} ]({ key } ) { label [0 ]} [/{ color_map .get (label [1 ], 'white' )} ]"
367+ for key , label in choice_labels .items ()]
340368 )
341369
342- console .print (f"\n { prompt_message } " )
370+ if TELEGRAM_BOT :
371+ category_legend_str = "Categorie: \n " + " | " .join ([
372+ f"{ category .capitalize ()} " for category in color_map .keys ()
373+ ])
343374
344- category = bot .ask (
345- "select_provider" ,
346- f"{ category_legend_str } \n \n { prompt_message } " ,
347- None
348- )
375+ prompt_message_telegram = "Inserisci il sito:\n " + "\n " .join (
376+ [f"{ key } : { label [0 ]} " for key , label in choice_labels .items ()]
377+ )
349378
350- else :
351- category = msg .ask (prompt_message , choices = list (choice_labels .keys ()), default = "0" , show_choices = False , show_default = False )
379+ console .print (f"\n { prompt_message_telegram } " )
380+
381+ category = bot .ask (
382+ "select_provider" ,
383+ f"{ category_legend_str } \n \n { prompt_message_telegram } " ,
384+ None
385+ )
386+
387+ else :
388+ category = msg .ask (prompt_message , choices = list (choice_labels .keys ()), default = "0" , show_choices = False , show_default = False )
352389
353390 # Run the corresponding function based on user input
354391 if category in input_to_function :
@@ -372,4 +409,4 @@ def main(script_id = 0):
372409 # Delete script_id
373410 script_id = TelegramSession .get_session ()
374411 if script_id != "unknown" :
375- TelegramSession .deleteScriptId (script_id )
412+ TelegramSession .deleteScriptId (script_id )
0 commit comments