Fix continuations for some library functions

Update tests, reduce code duplication
This commit is contained in:
sigma67 2021-02-04 13:22:01 +01:00
commit d97d88d4ef
No known key found for this signature in database
GPG key ID: 1545A01D4474BAF0
5 changed files with 50 additions and 88 deletions

View file

@ -5,7 +5,8 @@ SECTION_LIST = ['sectionListRenderer', 'contents']
SECTION_LIST_ITEM = ['sectionListRenderer', 'contents', 0]
ITEM_SECTION = ['itemSectionRenderer', 'contents', 0]
MUSIC_SHELF = ['musicShelfRenderer']
GRID_ITEMS = ['gridRenderer', 'items']
GRID = ['gridRenderer']
GRID_ITEMS = GRID + ['items']
MENU = ['menu', 'menuRenderer']
MENU_ITEMS = MENU + ['items']
MENU_LIKE_STATUS = MENU + ['topLevelButtons', 0, 'likeButtonRenderer', 'likeStatus']

View file

@ -22,6 +22,24 @@ def parse_artists(results, uploaded=False):
return artists
def parse_library_albums(response, request_func, limit):
results = find_object_by_key(nav(response, SINGLE_COLUMN_TAB + SECTION_LIST),
'itemSectionRenderer')
results = nav(results, ITEM_SECTION)
if 'gridRenderer' not in results:
return []
results = nav(results, GRID)
albums = parse_albums(results['items'])
if 'continuations' in results:
parse_func = lambda contents: parse_albums(contents)
albums.extend(
get_continuations(results, 'gridContinuation', limit - len(albums), request_func,
parse_func))
return albums
def parse_albums(results):
albums = []
for result in results: