This commit is contained in:
Rasmus M 2020-10-22 18:31:13 +07:00 committed by GitHub
commit b6da08fadb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 2 deletions

View File

@ -631,7 +631,7 @@ class YoutubeDL(object):
except UnicodeEncodeError:
self.to_screen('[download] The file has already been downloaded')
def prepare_filename(self, info_dict):
def prepare_filename(self, info_dict, temp=False):
"""Generate the output filename."""
try:
template_dict = dict(info_dict)
@ -710,6 +710,9 @@ class YoutubeDL(object):
# title "Hello $PATH", we don't want `$PATH` to be expanded.
filename = expand_path(outtmpl).replace(sep, '') % template_dict
if temp and self.params.get("tempdir", None) is not None:
filename = os.path.join(self.params["tempdir"], os.path.basename(filename))
# Temporary fix for #4787
# 'Treat' all problem characters by passing filename through preferredencoding
# to workaround encoding issues with subprocess on python2 @ Windows
@ -1912,7 +1915,7 @@ class YoutubeDL(object):
new_info = dict(info_dict)
new_info.update(f)
fname = prepend_extension(
self.prepare_filename(new_info),
self.prepare_filename(new_info, temp=True),
'f%s' % f['format_id'], new_info['ext'])
if not ensure_dir_exists(fname):
return

View File

@ -392,6 +392,7 @@ def _real_main(argv=None):
'max_views': opts.max_views,
'daterange': date,
'cachedir': opts.cachedir,
'tempdir': opts.tempdir,
'youtube_print_sig_code': opts.youtube_print_sig_code,
'age_limit': opts.age_limit,
'download_archive': download_archive_fn,

View File

@ -756,6 +756,9 @@ def parseOpts(overrideArguments=None):
filesystem.add_option(
'--cache-dir', dest='cachedir', default=None, metavar='DIR',
help='Location in the filesystem where youtube-dl can store some downloaded information permanently. By default $XDG_CACHE_HOME/youtube-dl or ~/.cache/youtube-dl . At the moment, only YouTube player files (for videos with obfuscated signatures) are cached, but that may change.')
filesystem.add_option(
'--temp-dir', dest='tempdir', default=None, metavar='DIR',
help='Directory where youtube-dl can store some temporary files.')
filesystem.add_option(
'--no-cache-dir', action='store_const', const=False, dest='cachedir',
help='Disable filesystem caching')