mirror of
https://github.com/ytdl-org/youtube-dl.git
synced 2024-11-22 18:22:21 +00:00
[extractor/common] Add support multiple getters in try_get
This commit is contained in:
parent
bae1404893
commit
a32a9a7ef5
1 changed files with 10 additions and 7 deletions
|
@ -2103,8 +2103,11 @@ def dict_get(d, key_or_keys, default=None, skip_false_values=True):
|
||||||
|
|
||||||
|
|
||||||
def try_get(src, getter, expected_type=None):
|
def try_get(src, getter, expected_type=None):
|
||||||
|
if not isinstance(getter, (list, tuple)):
|
||||||
|
getter = [getter]
|
||||||
|
for get in getter:
|
||||||
try:
|
try:
|
||||||
v = getter(src)
|
v = get(src)
|
||||||
except (AttributeError, KeyError, TypeError, IndexError):
|
except (AttributeError, KeyError, TypeError, IndexError):
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in a new issue