mirror of
https://github.com/l1ving/youtube-dl
synced 2025-02-03 17:23:00 +08:00
Added a "filename_hook" hook to allow changing generated filenames before they're used
This commit is contained in:
parent
954529c10f
commit
b4481181b0
@ -151,6 +151,10 @@ 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.
|
||||
filename_hook: A function that gets called before creating a filename,
|
||||
allowing to change it before the filename is created.
|
||||
It should accept filename as first positional argument
|
||||
and return the desired filename (no extensions added)
|
||||
restrictfilenames: Do not allow "&" and spaces in file names
|
||||
ignoreerrors: Do not stop on download errors.
|
||||
force_generic_extractor: Force downloader to use the generic extractor
|
||||
@ -612,7 +616,9 @@ class YoutubeDL(object):
|
||||
# to workaround encoding issues with subprocess on python2 @ Windows
|
||||
if sys.version_info < (3, 0) and sys.platform == 'win32':
|
||||
filename = encodeFilename(filename, True).decode(preferredencoding())
|
||||
return sanitize_path(filename)
|
||||
filename = sanitize_path(filename)
|
||||
filename = self.params.get('filename_hook', lambda x: x)(filename)
|
||||
return compat_str(filename)
|
||||
except ValueError as err:
|
||||
self.report_error('Error in output template: ' + str(err) + ' (encoding: ' + repr(preferredencoding()) + ')')
|
||||
return None
|
||||
|
Loading…
Reference in New Issue
Block a user