1
0
Fork 0
mirror of https://gitlab.com/dstftw/youtube-dl.git synced 2020-11-16 09:42:26 +00:00

[extractor/common] Add support multiple getters in try_get

This commit is contained in:
Sergey M․ 2017-04-18 22:39:58 +07:00
parent bae1404893
commit a32a9a7ef5
No known key found for this signature in database
GPG key ID: 2C393E0F18A9236D

View file

@ -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: