mirror of
https://github.com/ytdl-org/youtube-dl
synced 2025-10-01 13:58:37 +09:00
Switch back to underline for invalid characters, and make restricted ASCII-only
This commit is contained in:
@@ -274,7 +274,7 @@ def parseOpts():
|
||||
dest='outtmpl', metavar='TEMPLATE', help='output filename template. Use %(title)s to get the title, %(uploader)s for the uploader name, %(autonumber)s to get an automatically incremented number, %(ext)s for the filename extension, %(upload_date)s for the upload date (YYYYMMDD), %(extractor)s for the provider (youtube, metacafe, etc), %(id)s for the video id and %% for a literal percent. Use - to output to stdout.')
|
||||
filesystem.add_option('--restrict-filenames',
|
||||
action='store_true', dest='restrictfilenames',
|
||||
help='Avoid some characters such as "&" and spaces in filenames', default=False)
|
||||
help='Restrict filenames to only ASCII characters, and avoid "&" and spaces in filenames', default=False)
|
||||
filesystem.add_option('-a', '--batch-file',
|
||||
dest='batchfile', metavar='FILE', help='file containing URLs to download (\'-\' for stdin)')
|
||||
filesystem.add_option('-w', '--no-overwrites',
|
||||
|
@@ -207,15 +207,20 @@ def sanitize_filename(s, restricted=False):
|
||||
elif char == ':':
|
||||
return '_-' if restricted else ' -'
|
||||
elif char in '\\/|*<>':
|
||||
return '-'
|
||||
return '_'
|
||||
if restricted and (char in '&\'' or char.isspace()):
|
||||
return '_'
|
||||
if restricted and ord(char) > 127:
|
||||
return '_'
|
||||
return char
|
||||
|
||||
result = u''.join(map(replace_insane, s))
|
||||
while '--' in result:
|
||||
result = result.replace('--', '-')
|
||||
return result.strip('-')
|
||||
while '__' in result:
|
||||
result = result.replace('__', '_')
|
||||
result = result.strip('_')
|
||||
if not result:
|
||||
result = '_'
|
||||
return result
|
||||
|
||||
def orderedSet(iterable):
|
||||
""" Remove all duplicates from the input iterable """
|
||||
|
Reference in New Issue
Block a user