search: support featured_playlists, community_playlists filters
This commit is contained in:
parent
1df1d550da
commit
b76eea3738
2 changed files with 52 additions and 29 deletions
|
|
@ -33,25 +33,28 @@ class TestYTMusic(unittest.TestCase):
|
||||||
###############
|
###############
|
||||||
|
|
||||||
def test_search(self):
|
def test_search(self):
|
||||||
query = "Oasis Wonderwall"
|
query = "edm playlist"
|
||||||
self.assertRaises(Exception, self.yt_auth.search, query, "song")
|
self.assertRaises(Exception, self.yt_auth.search, query, "song")
|
||||||
results = self.yt.search(query)
|
results = self.yt.search(query)
|
||||||
self.assertGreater(len(results), 10)
|
self.assertGreater(len(results), 10)
|
||||||
|
results = self.yt_auth.search('Martin Stig Andersen - Deteriation', ignore_spelling=True)
|
||||||
|
self.assertGreater(len(results), 0)
|
||||||
results = self.yt_auth.search(query, 'songs')
|
results = self.yt_auth.search(query, 'songs')
|
||||||
self.assertGreater(len(results), 10)
|
self.assertGreater(len(results), 10)
|
||||||
results = self.yt_auth.search(query, 'videos')
|
results = self.yt_auth.search(query, 'videos')
|
||||||
self.assertGreater(len(results), 10)
|
self.assertGreater(len(results), 10)
|
||||||
results = self.yt_auth.search(query, 'albums', limit=40)
|
results = self.yt_auth.search(query, 'albums', limit=40)
|
||||||
self.assertGreater(len(results), 20)
|
self.assertGreater(len(results), 20)
|
||||||
results = self.yt_auth.search(query, 'artists')
|
results = self.yt_auth.search('oasiss', 'artists', ignore_spelling=True)
|
||||||
self.assertGreater(len(results), 0)
|
self.assertGreater(len(results), 0)
|
||||||
results = self.yt_auth.search(query, 'playlists')
|
results = self.yt_auth.search("classical music", 'playlists')
|
||||||
|
self.assertGreater(len(results), 5)
|
||||||
|
results = self.yt_auth.search("clasical music", 'playlists', ignore_spelling=True)
|
||||||
|
self.assertGreater(len(results), 5)
|
||||||
|
results = self.yt_auth.search("clasic rock", 'community_playlists', ignore_spelling=True)
|
||||||
|
self.assertGreater(len(results), 5)
|
||||||
|
results = self.yt_auth.search("hip hop", 'featured_playlists')
|
||||||
self.assertGreater(len(results), 5)
|
self.assertGreater(len(results), 5)
|
||||||
|
|
||||||
def test_search_ignore_spelling(self):
|
|
||||||
query = "Martin Stig Andersen - Deteriation"
|
|
||||||
results = self.yt_auth.search(query, ignore_spelling=True)
|
|
||||||
self.assertGreater(len(results), 0)
|
|
||||||
|
|
||||||
def test_search_uploads(self):
|
def test_search_uploads(self):
|
||||||
results = self.yt_auth.search('audiomachine', 'uploads', limit=40)
|
results = self.yt_auth.search('audiomachine', 'uploads', limit=40)
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ class BrowsingMixin:
|
||||||
Returns results within the provided category.
|
Returns results within the provided category.
|
||||||
|
|
||||||
:param query: Query string, i.e. 'Oasis Wonderwall'
|
:param query: Query string, i.e. 'Oasis Wonderwall'
|
||||||
:param filter: Filter for item types. Allowed values: ``songs``, ``videos``, ``albums``, ``artists``, ``playlists``, ``uploads``.
|
: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.
|
Default: Default search, including all types of items.
|
||||||
:param limit: Number of search results to return
|
:param limit: Number of search results to return
|
||||||
Default: 20
|
Default: 20
|
||||||
|
|
@ -112,39 +112,59 @@ class BrowsingMixin:
|
||||||
body = {'query': query}
|
body = {'query': query}
|
||||||
endpoint = 'search'
|
endpoint = 'search'
|
||||||
search_results = []
|
search_results = []
|
||||||
filters = ['albums', 'artists', 'playlists', 'songs', 'videos', 'uploads']
|
filters = ['albums', 'artists', 'playlists', 'community_playlists', 'featured_playlists', 'songs', 'videos', 'uploads']
|
||||||
if filter and filter not in filters:
|
if filter and filter not in filters:
|
||||||
raise Exception(
|
raise Exception(
|
||||||
"Invalid filter provided. Please use one of the following filters or leave out the parameter: "
|
"Invalid filter provided. Please use one of the following filters or leave out the parameter: "
|
||||||
+ ', '.join(filters))
|
+ ', '.join(filters))
|
||||||
|
|
||||||
|
params = None
|
||||||
if filter:
|
if filter:
|
||||||
param1 = 'Eg-KAQwIA'
|
|
||||||
|
|
||||||
if not ignore_spelling:
|
|
||||||
param3 = 'MABqChAEEAMQCRAFEAo%3D'
|
|
||||||
else:
|
|
||||||
param3 = 'MABCAggBagoQBBADEAkQBRAK'
|
|
||||||
|
|
||||||
if filter == 'uploads':
|
if filter == 'uploads':
|
||||||
params = 'agIYAw%3D%3D'
|
params = 'agIYAw%3D%3D'
|
||||||
else:
|
|
||||||
if filter == 'videos':
|
elif filter == 'playlists':
|
||||||
param2 = 'BABGAAgACgA'
|
params = 'Eg-KAQwIABAAGAAgACgB'
|
||||||
elif filter == 'albums':
|
if not ignore_spelling:
|
||||||
param2 = 'BAAGAEgACgA'
|
params += 'MABqChAEEAMQCRAFEAo%3D'
|
||||||
elif filter == 'artists':
|
|
||||||
param2 = 'BAAGAAgASgA'
|
|
||||||
elif filter == 'playlists':
|
|
||||||
param2 = 'BAAGAAgACgB'
|
|
||||||
else:
|
else:
|
||||||
param2 = 'RAAGAAgACgA'
|
params += 'MABCAggBagoQBBADEAkQBRAK'
|
||||||
params = param1 + param2 + param3
|
|
||||||
|
elif 'playlists' in filter:
|
||||||
|
param1 = 'EgeKAQQoA'
|
||||||
|
if filter == 'featured_playlists':
|
||||||
|
param2 = 'Dg'
|
||||||
|
else: # community_playlists
|
||||||
|
param2 = 'EA'
|
||||||
|
|
||||||
|
if not ignore_spelling:
|
||||||
|
param3 = 'BagwQDhAKEAMQBBAJEAU%3D'
|
||||||
|
else:
|
||||||
|
param3 = 'BQgIIAWoMEA4QChADEAQQCRAF'
|
||||||
|
|
||||||
|
filter = 'playlists' # reset to playlists for parser
|
||||||
|
|
||||||
|
else:
|
||||||
|
param1 = 'EgWKAQI'
|
||||||
|
filter_params = {
|
||||||
|
'songs': 'I',
|
||||||
|
'videos': 'Q',
|
||||||
|
'albums': 'Y',
|
||||||
|
'artists': 'g'
|
||||||
|
}
|
||||||
|
param2 = filter_params[filter]
|
||||||
|
if not ignore_spelling:
|
||||||
|
param3 = 'AWoMEA4QChADEAQQCRAF'
|
||||||
|
else:
|
||||||
|
param3 = 'AUICCAFqDBAOEAoQAxAEEAkQBQ%3D%3D'
|
||||||
|
|
||||||
|
params = params if params else param1 + param2 + param3
|
||||||
|
|
||||||
body['params'] = params
|
|
||||||
elif ignore_spelling:
|
elif ignore_spelling:
|
||||||
body['params'] = "QgIIAQ%3D%3D"
|
params = 'EhGKAQ4IARABGAEgASgAOAFAAUICCAE%3D'
|
||||||
|
|
||||||
|
if params:
|
||||||
|
body['params'] = params
|
||||||
response = self._send_request(endpoint, body)
|
response = self._send_request(endpoint, body)
|
||||||
|
|
||||||
# no results
|
# no results
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue