Fix for KeyError when searching community_playlists or featured_playlists. Closes #420 (#421)

* Fix for issue #420 KeyError when searching community_playlists or featured_playlists with scope library

* From PR feedback - better exception message for search guard clause.

* Fixed lint
This commit is contained in:
nick42d 2023-08-05 18:23:23 +08:00 • committed by GitHub
commit 3bf7b49eab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 2 deletions

View file

@ -19,8 +19,10 @@ class SearchMixin:
:param filter: Filter for item types. Allowed values: ``songs``, ``videos``, ``albums``, ``artists``, ``playlists``, ``community_playlists``, ``featured_playlists``, ``uploads``.
Default: Default search, including all types of items.
:param scope: Search scope. Allowed values: ``library``, ``uploads``.
For uploads, no filter can be set! An exception will be thrown if you attempt to do so.
Default: Search the public YouTube Music catalogue.
Changing scope from the default will reduce the number of settable filters. Setting a filter that is not permitted will throw an exception.
For uploads, no filter can be set.
For library, community_playlists and featured_playlists filter cannot be set.
:param limit: Number of search results to return
Default: 20
:param ignore_spelling: Whether to ignore YTM spelling suggestions.
@ -143,6 +145,11 @@ class SearchMixin:
"No filter can be set when searching uploads. Please unset the filter parameter when scope is set to "
"uploads. ")
if scope == scopes[0] and filter in filters[3:5]:
raise Exception(f"{filter} cannot be set when searching library. "
f"Please use one of the following filters or leave out the parameter: "
+ ', '.join(filters[0:3]+filters[5:]))
params = get_search_params(filter, scope, ignore_spelling)
if params:
body['params'] = params