aboutsummaryrefslogtreecommitdiff
path: root/youtube_dl/utils.py
diff options
context:
space:
mode:
authorSergey M․ <dstftw@gmail.com>2016-02-07 08:13:04 +0600
committerSergey M․ <dstftw@gmail.com>2016-02-07 08:13:04 +0600
commit86296ad2cd5702a66b05aae79ec9196b62e41e9a (patch)
tree55e6e2d21294d298d164881b274e69bc62e77dde /youtube_dl/utils.py
parent52f5889f77e04420634d70145d689660ea6bfe24 (diff)
[utils] Add ability to control skipping false values in dict_get
Diffstat (limited to 'youtube_dl/utils.py')
-rw-r--r--youtube_dl/utils.py7
1 files changed, 4 insertions, 3 deletions
diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py
index 652dba59d..f3b0180ab 100644
--- a/youtube_dl/utils.py
+++ b/youtube_dl/utils.py
@@ -1717,11 +1717,12 @@ def encode_dict(d, encoding='utf-8'):
return dict((encode(k), encode(v)) for k, v in d.items())
-def dict_get(d, key_or_keys, default=None):
+def dict_get(d, key_or_keys, default=None, skip_false_values=True):
if isinstance(key_or_keys, (list, tuple)):
for key in key_or_keys:
- if d.get(key):
- return d[key]
+ if key not in d or d[key] is None or skip_false_values and not d[key]:
+ continue
+ return d[key]
return default
return d.get(key_or_keys, default)