From 0c6a37e9aacf19405c3daf2b7993f55c8b8e421a Mon Sep 17 00:00:00 2001 From: James Taylor Date: Thu, 26 Dec 2019 19:39:48 -0800 Subject: extract_items: allow extracting items that are normally dug into for more By checking first if it's in item_types rather than checking if it can be dug into first. For example: this allows extracting things like sectionListRenderer --- youtube/yt_data_extract/common.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'youtube/yt_data_extract') diff --git a/youtube/yt_data_extract/common.py b/youtube/yt_data_extract/common.py index 3dda8eb..8d91f26 100644 --- a/youtube/yt_data_extract/common.py +++ b/youtube/yt_data_extract/common.py @@ -376,8 +376,12 @@ def extract_items_from_renderer(renderer, item_types=_item_types): # mode 2: dig into the current renderer key, value = list(renderer.items())[0] + # the renderer is an item + if key in item_types: + items.append(renderer) + # has a list in it, add it to the iter stack - if key in nested_renderer_list_dispatch: + elif key in nested_renderer_list_dispatch: renderer_list, continuation = nested_renderer_list_dispatch[key](value) if renderer_list: iter_stack.append(current_iter) @@ -390,10 +394,6 @@ def extract_items_from_renderer(renderer, item_types=_item_types): renderer = nested_renderer_dispatch[key](value) continue # don't reset renderer to None - # the renderer is an item - elif key in item_types: - items.append(renderer) - renderer = None def extract_items(response, item_types=_item_types): -- cgit v1.2.3