@@ -205,38 +205,44 @@ def search(
205205 filter = scopes [1 ]
206206
207207 for res in section_list :
208+ result_type = category = None
209+ search_result_types = self .parser .get_search_result_types ()
210+
208211 if "musicCardShelfRenderer" in res :
209212 top_result = parse_top_result (
210213 res ["musicCardShelfRenderer" ], self .parser .get_search_result_types ()
211214 )
212215 search_results .append (top_result )
213216 if not (shelf_contents := nav (res , ["musicCardShelfRenderer" , "contents" ], True )):
214217 continue
215- type = category = None
216218 # if "more from youtube" is present, remove it - it's not parseable
217219 if "messageRenderer" in shelf_contents [0 ]:
218220 category = nav (shelf_contents .pop (0 ), ["messageRenderer" , * TEXT_RUN_TEXT ])
219221
220222 elif "musicShelfRenderer" in res :
221223 shelf_contents = res ["musicShelfRenderer" ]["contents" ]
222224 category = nav (res , MUSIC_SHELF + TITLE_TEXT , True )
223- type_filter = filter or category
224225
225- type = type_filter [:- 1 ].lower () if type_filter else None
226+ # if we know the filter it's easy to set the result type
227+ # unfortunately uploads is modeled as a filter (historical reasons),
228+ # so we take care to not set the result type for that scope
229+ if filter and not scope == scopes [1 ]:
230+ result_type = filter [:- 1 ].lower ()
226231
227232 else :
228233 continue
229234
230- search_result_types = self .parser .get_search_result_types ()
231- search_results .extend (parse_search_results (shelf_contents , search_result_types , type , category ))
235+ search_results .extend (
236+ parse_search_results (shelf_contents , search_result_types , result_type , category )
237+ )
232238
233239 if filter : # if filter is set, there are continuations
234240
235241 def request_func (additionalParams ):
236242 return self ._send_request (endpoint , body , additionalParams )
237243
238244 def parse_func (contents ):
239- return parse_search_results (contents , search_result_types , type , category )
245+ return parse_search_results (contents , search_result_types , result_type , category )
240246
241247 search_results .extend (
242248 get_continuations (
0 commit comments