diff options
author | pukkandan <pukkandan.ytdlp@gmail.com> | 2021-09-17 23:46:17 +0530 |
---|---|---|
committer | pukkandan <pukkandan.ytdlp@gmail.com> | 2021-09-18 00:11:11 +0530 |
commit | f5aa5cfbffeea9352ace141707f35c86f5e11b89 (patch) | |
tree | 5e56f7bea9db56875e20d3641dc5c76b0ac4a507 /yt_dlp | |
parent | f1f6ca78b439343aa3f8ef44f803befd682a3d37 (diff) | |
download | hypervideo-pre-f5aa5cfbffeea9352ace141707f35c86f5e11b89.tar.lz hypervideo-pre-f5aa5cfbffeea9352ace141707f35c86f5e11b89.tar.xz hypervideo-pre-f5aa5cfbffeea9352ace141707f35c86f5e11b89.zip |
Add format type `B` for outtmpl to treat the value as bytes
This is useful to limit the filename to a certain number of bytes rather than characters
Closes #1003
Diffstat (limited to 'yt_dlp')
-rw-r--r-- | yt_dlp/YoutubeDL.py | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/yt_dlp/YoutubeDL.py b/yt_dlp/YoutubeDL.py index 8432abf1a..c9dc50e64 100644 --- a/yt_dlp/YoutubeDL.py +++ b/yt_dlp/YoutubeDL.py @@ -907,7 +907,7 @@ class YoutubeDL(object): def validate_outtmpl(cls, outtmpl): ''' @return None or Exception object ''' outtmpl = re.sub( - STR_FORMAT_RE_TMPL.format('[^)]*', '[ljq]'), + STR_FORMAT_RE_TMPL.format('[^)]*', '[ljqB]'), lambda mobj: f'{mobj.group(0)[:-1]}s', cls._outtmpl_expandpath(outtmpl)) try: @@ -939,7 +939,7 @@ class YoutubeDL(object): } TMPL_DICT = {} - EXTERNAL_FORMAT_RE = re.compile(STR_FORMAT_RE_TMPL.format('[^)]*', f'[{STR_FORMAT_TYPES}ljq]')) + EXTERNAL_FORMAT_RE = re.compile(STR_FORMAT_RE_TMPL.format('[^)]*', f'[{STR_FORMAT_TYPES}ljqB]')) MATH_FUNCTIONS = { '+': float.__add__, '-': float.__sub__, @@ -1031,6 +1031,9 @@ class YoutubeDL(object): value, fmt = json.dumps(value, default=_dumpjson_default), str_fmt elif fmt[-1] == 'q': value, fmt = compat_shlex_quote(str(value)), str_fmt + elif fmt[-1] == 'B': + value = f'%{str_fmt}'.encode('utf-8') % str(value).encode('utf-8') + value, fmt = value.decode('utf-8', 'ignore'), 's' elif fmt[-1] == 'c': value = str(value) if value is None: |