diff options
author | pukkandan <pukkandan.ytdlp@gmail.com> | 2021-05-03 22:36:03 +0530 |
---|---|---|
committer | pukkandan <pukkandan.ytdlp@gmail.com> | 2021-05-06 20:28:58 +0530 |
commit | e625be0d10d96a20702d630dcc88e3269554e172 (patch) | |
tree | 73f96152c871708a9c1430dc205fdd7089f144ab /yt_dlp/utils.py | |
parent | 12e73423f1df25bfe2fa00434b2688dd7dd9d227 (diff) | |
download | hypervideo-pre-e625be0d10d96a20702d630dcc88e3269554e172.tar.lz hypervideo-pre-e625be0d10d96a20702d630dcc88e3269554e172.tar.xz hypervideo-pre-e625be0d10d96a20702d630dcc88e3269554e172.zip |
Improve output template internal formatting
* Allow slicing lists/strings using `field.start:end:step`
* A field can also be used as offset like `field1+num+field2`
* A default value can be given using `field|default`
* Capture all format strings and set it to `None` if invalid. This prevents invalid fields from causing errors
Diffstat (limited to 'yt_dlp/utils.py')
-rw-r--r-- | yt_dlp/utils.py | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/yt_dlp/utils.py b/yt_dlp/utils.py index 08e2d19d2..baa2a415e 100644 --- a/yt_dlp/utils.py +++ b/yt_dlp/utils.py @@ -6112,11 +6112,11 @@ def traverse_dict(dictn, keys, casesense=True): key = key.lower() dictn = dictn.get(key) elif isinstance(dictn, (list, tuple, compat_str)): - key, n = int_or_none(key), len(dictn) - if key is not None and -n <= key < n: - dictn = dictn[key] + if ':' in key: + key = slice(*map(int_or_none, key.split(':'))) else: - dictn = None + key = int_or_none(key) + dictn = try_get(dictn, lambda x: x[key]) else: return None return dictn |