@@ -101,10 +101,13 @@ def process_search_result(select_title, selections=None):
101101 episode_selection = selections .get ('episode' )
102102
103103 download_series (select_title , season_selection , episode_selection )
104+ media_search_manager .clear ()
105+ table_show_manager .clear ()
104106 return True
105107
106108 else :
107109 download_film (select_title )
110+ table_show_manager .clear ()
108111 return True
109112
110113# search("Game of Thrones", selections={"season": "1", "episode": "1-3"})
@@ -122,40 +125,37 @@ def search(string_to_search: str = None, get_onlyDatabase: bool = False, direct_
122125 bot = None
123126 if site_constant .TELEGRAM_BOT :
124127 bot = get_bot_instance ()
125-
128+
126129 if direct_item :
127130 select_title = MediaItem (** direct_item )
128- process_search_result (select_title , selections )
129- return True
130-
131+ result = process_search_result (select_title , selections )
132+ return result
133+
131134 # Get the user input for the search term
132135 actual_search_query = get_user_input (string_to_search )
133136
134- # Handle cases where user input is empty, or 'back' was handled (sys.exit or None return)
137+ # Handle empty input
135138 if not actual_search_query :
136139 if bot :
137- if actual_search_query is None : # Specifically for timeout from bot.ask or failed restart
140+ if actual_search_query is None :
138141 bot .send_message ("Search term not provided or operation cancelled. Returning." , None )
139- return
140-
141- # Perform the database search
142- len_database = title_search (quote_plus ( actual_search_query ) )
142+ return False
143+
144+ # Search on database
145+ len_database = title_search (actual_search_query )
143146
144147 # If only the database is needed, return the manager
145148 if get_onlyDatabase :
146149 return media_search_manager
147-
150+
148151 if len_database > 0 :
149152 select_title = get_select_title (table_show_manager , media_search_manager , len_database )
150- process_search_result (select_title , selections )
151- return True
153+ result = process_search_result (select_title , selections )
154+ return result
152155
153156 else :
154157 if bot :
155158 bot .send_message (f"No results found for: '{ actual_search_query } '" , None )
156159 else :
157160 console .print (f"\n [red]Nothing matching was found for[white]: [purple]{ actual_search_query } " )
158-
159- # Do not call search() recursively here to avoid infinite loops on no results.
160- # The flow should return to the caller (e.g., main menu in run.py).
161- return
161+ return False
0 commit comments