get_library_*: fix for next YouTube update (#301)

This commit is contained in:
sigma67 2022-09-29 21:13:08 +02:00
commit 1cac82be21
No known key found for this signature in database
GPG key ID: 1545A01D4474BAF0
4 changed files with 29 additions and 47 deletions

View file

@ -26,9 +26,7 @@ class LibraryMixin:
endpoint = 'browse'
response = self._send_request(endpoint, body)
results = find_object_by_key(nav(response, SINGLE_COLUMN_TAB + SECTION_LIST),
'itemSectionRenderer')
results = nav(results, ITEM_SECTION + GRID)
results = get_library_contents(response, GRID)
playlists = parse_content_list(results['items'][1:], parse_playlist)
if 'continuations' in results:

View file

@ -7,7 +7,7 @@ from ._utils import validate_order_parameter, prepare_order_params
from ytmusicapi.helpers import *
from ytmusicapi.navigation import *
from ytmusicapi.continuations import get_continuations
from ytmusicapi.parsers.library import parse_library_albums, parse_library_artists
from ytmusicapi.parsers.library import parse_library_albums, parse_library_artists, get_library_contents
from ytmusicapi.parsers.albums import parse_album_header
from ytmusicapi.parsers.uploads import parse_uploaded_items
@ -43,17 +43,10 @@ class UploadsMixin:
if order is not None:
body["params"] = prepare_order_params(order)
response = self._send_request(endpoint, body)
results = find_object_by_key(nav(response, SINGLE_COLUMN_TAB + SECTION_LIST),
'itemSectionRenderer')
results = nav(results, ITEM_SECTION)
if 'musicShelfRenderer' not in results:
results = get_library_contents(response, MUSIC_SHELF)
if results is None:
return []
else:
results = results['musicShelfRenderer']
songs = []
songs.extend(parse_uploaded_items(results['contents'][1:]))
songs = parse_uploaded_items(results['contents'][1:])
if 'continuations' in results:
request_func = lambda additionalParams: self._send_request(

View file

@ -24,12 +24,9 @@ def parse_artists(results, uploaded=False):
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:
results = get_library_contents(response, GRID)
if results is None:
return []
results = nav(results, GRID)
albums = parse_albums(results['items'])
if 'continuations' in results:
@ -83,12 +80,9 @@ def parse_albums(results):
def parse_library_artists(response, request_func, limit):
results = find_object_by_key(nav(response, SINGLE_COLUMN_TAB + SECTION_LIST),
'itemSectionRenderer')
results = nav(results, ITEM_SECTION)
if 'musicShelfRenderer' not in results:
results = get_library_contents(response, MUSIC_SHELF)
if results is None:
return []
results = results['musicShelfRenderer']
artists = parse_artists(results['contents'])
if 'continuations' in results:
@ -102,12 +96,17 @@ def parse_library_artists(response, request_func, limit):
def parse_library_songs(response):
results = find_object_by_key(nav(response, SINGLE_COLUMN_TAB + SECTION_LIST),
'itemSectionRenderer')
results = nav(results, ITEM_SECTION)
songs = {'results': [], 'parsed': []}
if 'musicShelfRenderer' in results:
songs['results'] = results['musicShelfRenderer']
songs['parsed'] = parse_playlist_items(songs['results']['contents'][1:])
results = get_library_contents(response, MUSIC_SHELF)
return {'results': results, 'parsed': (parse_playlist_items(results['contents'][1:]))}
return songs
def get_library_contents(response, renderer):
# first 3 lines are original path prior to #301
contents = nav(response, SINGLE_COLUMN_TAB + SECTION_LIST, True)
if contents is None: # empty library
return None
results = find_object_by_key(contents, 'itemSectionRenderer')
if results is None:
return nav(response, SINGLE_COLUMN_TAB + SECTION_LIST_ITEM + renderer, True)
else:
return nav(results, ITEM_SECTION + renderer)