add category property for search results (closes #229)
This commit is contained in:
parent
7ddfb3da49
commit
c536720e6e
2 changed files with 12 additions and 5 deletions
|
|
@ -38,6 +38,7 @@ class BrowsingMixin:
|
||||||
|
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
|
"category": "Top result",
|
||||||
"resultType": "video",
|
"resultType": "video",
|
||||||
"videoId": "vU05Eksc_iM",
|
"videoId": "vU05Eksc_iM",
|
||||||
"title": "Wonderwall",
|
"title": "Wonderwall",
|
||||||
|
|
@ -51,6 +52,7 @@ class BrowsingMixin:
|
||||||
"duration": "4:38"
|
"duration": "4:38"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"category": "Songs",
|
||||||
"resultType": "song",
|
"resultType": "song",
|
||||||
"videoId": "ZrOKjDZOtkA",
|
"videoId": "ZrOKjDZOtkA",
|
||||||
"title": "Wonderwall",
|
"title": "Wonderwall",
|
||||||
|
|
@ -72,6 +74,7 @@ class BrowsingMixin:
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"category": "Albums",
|
||||||
"resultType": "album",
|
"resultType": "album",
|
||||||
"browseId": "MPREb_9nqEki4ZDpp",
|
"browseId": "MPREb_9nqEki4ZDpp",
|
||||||
"title": "(What's The Story) Morning Glory? (Remastered)",
|
"title": "(What's The Story) Morning Glory? (Remastered)",
|
||||||
|
|
@ -81,6 +84,7 @@ class BrowsingMixin:
|
||||||
"isExplicit": false
|
"isExplicit": false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"category": "Community playlists",
|
||||||
"resultType": "playlist",
|
"resultType": "playlist",
|
||||||
"browseId": "VLPLK1PkWQlWtnNfovRdGWpKffO1Wdi2kvDx",
|
"browseId": "VLPLK1PkWQlWtnNfovRdGWpKffO1Wdi2kvDx",
|
||||||
"title": "Wonderwall - Oasis",
|
"title": "Wonderwall - Oasis",
|
||||||
|
|
@ -88,6 +92,7 @@ class BrowsingMixin:
|
||||||
"itemCount": "174"
|
"itemCount": "174"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"category": "Videos",
|
||||||
"resultType": "video",
|
"resultType": "video",
|
||||||
"videoId": "bx1Bh8ZvH84",
|
"videoId": "bx1Bh8ZvH84",
|
||||||
"title": "Wonderwall",
|
"title": "Wonderwall",
|
||||||
|
|
@ -101,6 +106,7 @@ class BrowsingMixin:
|
||||||
"duration": "4:38"
|
"duration": "4:38"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"category": "Artists",
|
||||||
"resultType": "artist",
|
"resultType": "artist",
|
||||||
"browseId": "UCmMUZbaYdNH0bEd1PAlAqsA",
|
"browseId": "UCmMUZbaYdNH0bEd1PAlAqsA",
|
||||||
"artist": "Oasis",
|
"artist": "Oasis",
|
||||||
|
|
@ -160,18 +166,19 @@ class BrowsingMixin:
|
||||||
if 'musicShelfRenderer' in res:
|
if 'musicShelfRenderer' in res:
|
||||||
results = res['musicShelfRenderer']['contents']
|
results = res['musicShelfRenderer']['contents']
|
||||||
original_filter = filter
|
original_filter = filter
|
||||||
|
category = nav(res, MUSIC_SHELF + TITLE_TEXT, True)
|
||||||
if not filter and scope == scopes[0]:
|
if not filter and scope == scopes[0]:
|
||||||
filter = nav(res, MUSIC_SHELF + TITLE_TEXT, True)
|
filter = category
|
||||||
|
|
||||||
type = filter[:-1].lower() if filter else None
|
type = filter[:-1].lower() if filter else None
|
||||||
search_results.extend(self.parser.parse_search_results(results, type))
|
search_results.extend(self.parser.parse_search_results(results, type, category))
|
||||||
filter = original_filter
|
filter = original_filter
|
||||||
|
|
||||||
if 'continuations' in res['musicShelfRenderer']:
|
if 'continuations' in res['musicShelfRenderer']:
|
||||||
request_func = lambda additionalParams: self._send_request(
|
request_func = lambda additionalParams: self._send_request(
|
||||||
endpoint, body, additionalParams)
|
endpoint, body, additionalParams)
|
||||||
|
|
||||||
parse_func = lambda contents: self.parser.parse_search_results(contents, type)
|
parse_func = lambda contents: self.parser.parse_search_results(contents, type, category)
|
||||||
|
|
||||||
search_results.extend(
|
search_results.extend(
|
||||||
get_continuations(res['musicShelfRenderer'], 'musicShelfContinuation',
|
get_continuations(res['musicShelfRenderer'], 'musicShelfContinuation',
|
||||||
|
|
|
||||||
|
|
@ -9,12 +9,12 @@ class Parser:
|
||||||
self.lang = language
|
self.lang = language
|
||||||
|
|
||||||
@i18n
|
@i18n
|
||||||
def parse_search_results(self, results, resultType=None):
|
def parse_search_results(self, results, resultType=None, category=None):
|
||||||
search_results = []
|
search_results = []
|
||||||
default_offset = (not resultType) * 2
|
default_offset = (not resultType) * 2
|
||||||
for result in results:
|
for result in results:
|
||||||
data = result[MRLIR]
|
data = result[MRLIR]
|
||||||
search_result = {}
|
search_result = {'category': category}
|
||||||
if not resultType:
|
if not resultType:
|
||||||
resultType = get_item_text(data, 1).lower()
|
resultType = get_item_text(data, 1).lower()
|
||||||
result_types = ['artist', 'playlist', 'song', 'video', 'station']
|
result_types = ['artist', 'playlist', 'song', 'video', 'station']
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue