1212from StreamingCommunity .Api .Template .Class .SearchType import MediaManager
1313
1414
15- # Logic Import
16- from .util .ScrapeSerie import GetSerieInfo
17-
18-
1915# Variable
2016console = Console ()
2117media_search_manager = MediaManager ()
2218table_show_manager = TVShowManager ()
2319
2420
25- def determine_media_type (item ):
26- """
27- Determine if the item is a film or TV series by checking actual seasons count
28- using GetSerieInfo.
29- """
30- try :
31- scraper = GetSerieInfo (item .get ('path_id' ))
32- scraper .collect_info_title ()
33- return scraper .prog_tipology , scraper .prog_description , scraper .prog_year
34-
35- except Exception as e :
36- console .print (f"[red]Error determining media type: { e } [/red]" )
37- return None , None , None
38-
39-
4021def title_search (query : str ) -> int :
4122 """
4223 Search for titles based on a search query.
@@ -72,24 +53,49 @@ def title_search(query: str) -> int:
7253 console .print (f"[red]Site: { site_constant .SITE_NAME } , request search error: { e } " )
7354 return 0
7455
75- # Limit to only 15 results for performance
76- data = response .json ().get ('agg' ).get ('titoli' ).get ('cards' )[:15 ]
56+ try :
57+ response_data = response .json ()
58+ cards = response_data .get ('agg' , {}).get ('titoli' , {}).get ('cards' , [])
59+
60+ # Limit to only 15 results for performance
61+ data = cards [:15 ]
62+ console .print (f"[cyan]Found { len (cards )} results, processing first { len (data )} ...[/cyan]" )
63+
64+ except Exception as e :
65+ console .print (f"[red]Error parsing search results: { e } [/red]" )
66+ return 0
7767
7868 # Process each item and add to media manager
79- for item in data :
80- media_type , prog_description , prog_year = determine_media_type (item )
81- if media_type is None :
69+ for idx , item in enumerate (data , 1 ):
70+ try :
71+ # Get path_id
72+ path_id = item .get ('path_id' , '' )
73+ if not path_id :
74+ console .print ("[yellow]Skipping item due to missing path_id[/yellow]" )
75+ continue
76+
77+ # Get image URL - handle both relative and absolute URLs
78+ image = item .get ('immagine' , '' )
79+ if image and not image .startswith ('http' ):
80+ image = f"https://www.raiplay.it{ image } "
81+
82+ # Get URL - handle both relative and absolute URLs
83+ url = item .get ('url' , '' )
84+ if url and not url .startswith ('http' ):
85+ url = f"https://www.raiplay.it{ url } "
86+
87+ media_search_manager .add_media ({
88+ 'id' : item .get ('id' , '' ),
89+ 'name' : item .get ('titolo' , 'Unknown' ),
90+ 'type' : "tv" ,
91+ 'path_id' : path_id ,
92+ 'url' : url ,
93+ 'image' : image ,
94+ 'year' : image .split ("/" )[5 ]
95+ })
96+
97+ except Exception as e :
98+ console .print (f"[red]Error processing item '{ item .get ('titolo' , 'Unknown' )} ': { e } [/red]" )
8299 continue
83-
84- media_search_manager .add_media ({
85- 'id' : item .get ('id' , '' ),
86- 'name' : item .get ('titolo' , '' ),
87- 'type' : media_type ,
88- 'path_id' : item .get ('path_id' , '' ),
89- 'url' : f"https://www.raiplay.it{ item .get ('url' , '' )} " ,
90- 'image' : f"https://www.raiplay.it{ item .get ('immagine' , '' )} " ,
91- 'desc' : prog_description ,
92- 'year' : prog_year
93- })
94-
100+
95101 return media_search_manager .get_length ()
0 commit comments