Fixed: KeyError when artist doesn't have subscribers count
This commit is contained in:
parent
45cdac891f
commit
3bcd7bd73f
2 changed files with 11 additions and 5 deletions
|
|
@ -190,7 +190,7 @@ class BrowsingMixin:
|
|||
subscription_button = header['subscriptionButton']['subscribeButtonRenderer']
|
||||
artist['channelId'] = subscription_button['channelId']
|
||||
artist['subscribers'] = nav(subscription_button,
|
||||
['subscriberCountText', 'runs', 0, 'text'])
|
||||
['subscriberCountText', 'runs', 0, 'text'], True)
|
||||
artist['subscribed'] = subscription_button['subscribed']
|
||||
artist['thumbnails'] = nav(header, THUMBNAILS)
|
||||
artist['songs'] = {'browseId': None}
|
||||
|
|
|
|||
|
|
@ -322,11 +322,17 @@ def get_continuations(results, continuation_type, per_page, limit, request_func,
|
|||
return items
|
||||
|
||||
|
||||
def nav(root, items):
|
||||
def nav(root, items, none_if_absent=False):
|
||||
"""Access a nested object in root by item sequence."""
|
||||
for k in items:
|
||||
root = root[k]
|
||||
return root
|
||||
try:
|
||||
for k in items:
|
||||
root = root[k]
|
||||
return root
|
||||
except KeyError as err:
|
||||
if none_if_absent:
|
||||
return None
|
||||
else:
|
||||
raise err;
|
||||
|
||||
|
||||
def find_object_by_key(object_list, key, nested=None, is_key=False):
|
||||
|
|
|
|||
Loading…
Reference in a new issue