aboutsummaryrefslogtreecommitdiffstats
path: root/youtube_dlc/YoutubeDL.py
diff options
context:
space:
mode:
authorUnknown <blackjack4494@web.de>2020-09-30 05:50:09 +0200
committerUnknown <blackjack4494@web.de>2020-09-30 05:50:09 +0200
commitbdc3fd2f35c67c513dfc2843d5168f905d7bd5c8 (patch)
treed0f909a00a17c23e0921af2e9f0041f1ea328480 /youtube_dlc/YoutubeDL.py
parent6923b5381fe9fe4b8d120d883b41a22e99f52f63 (diff)
downloadhypervideo-pre-bdc3fd2f35c67c513dfc2843d5168f905d7bd5c8.tar.lz
hypervideo-pre-bdc3fd2f35c67c513dfc2843d5168f905d7bd5c8.tar.xz
hypervideo-pre-bdc3fd2f35c67c513dfc2843d5168f905d7bd5c8.zip
[core] add option to trim file name length with integer
https://github.com/blackjack4494/youtube-dlc/issues/85
Diffstat (limited to 'youtube_dlc/YoutubeDL.py')
-rw-r--r--youtube_dlc/YoutubeDL.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/youtube_dlc/YoutubeDL.py b/youtube_dlc/YoutubeDL.py
index 0bb5ff1e9..fc351db0d 100644
--- a/youtube_dlc/YoutubeDL.py
+++ b/youtube_dlc/YoutubeDL.py
@@ -164,7 +164,8 @@ class YoutubeDL(object):
simulate: Do not download the video files.
format: Video format code. See options.py for more information.
outtmpl: Template for output names.
- restrictfilenames: Do not allow "&" and spaces in file names
+ restrictfilenames: Do not allow "&" and spaces in file names.
+ trim_file_name: Limit length of filename (extension excluded).
ignoreerrors: Do not stop on download errors.
force_generic_extractor: Force downloader to use the generic extractor
nooverwrites: Prevent overwriting files.
@@ -732,6 +733,16 @@ class YoutubeDL(object):
# title "Hello $PATH", we don't want `$PATH` to be expanded.
filename = expand_path(outtmpl).replace(sep, '') % template_dict
+ # https://github.com/blackjack4494/youtube-dlc/issues/85
+ trim_file_name = self.params.get('trim_file_name', False)
+ if trim_file_name:
+ fn_groups = filename.rsplit('.')
+ ext = fn_groups[-1]
+ sub_ext = ''
+ if len(fn_groups) > 2:
+ sub_ext = fn_groups[-2]
+ filename = '.'.join(filter(None, [fn_groups[0][:trim_file_name], sub_ext, ext]))
+
# Temporary fix for #4787
# 'Treat' all problem characters by passing filename through preferredencoding
# to workaround encoding issues with subprocess on python2 @ Windows