Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sanitize filename: Replace ": " with " -" but replace ":" with "-" #4683

Closed
johankj opened this issue Jan 11, 2015 · 1 comment
Closed

Sanitize filename: Replace ": " with " -" but replace ":" with "-" #4683

johankj opened this issue Jan 11, 2015 · 1 comment

Comments

@johankj
Copy link
Contributor

@johankj johankj commented Jan 11, 2015

Downloading videos from YouTube containing ":" will make odd sanitized filenames.
Currently ":" is replaced with " -" which makes perfect sense in the case of "Some Title: Subtitle" which will then be transformed to "Some Title - Subtitle".
But in cases where the title contains a timestamp like "New World Record at 0:12:34" it gets transformed to "New World Record at 0 -12 -34" instead of the slightly better "New World Record at 0-12-34".

It could be solved by e.g. looping over the string and looking at the next char, instead of mapping each char:

for i in range(len(s)):
    char = s[i]
    if char == '?' or ord(char) < 32 or ord(char) == 127:
        char = ''
    elif char == '"':
        char = '' if restricted else '\''
    elif char == ':' and s[i+1] == ' ':
        char = '_-' if restricted else ' -'
    elif char == ':':
        char = '-' if restricted else '-'
    elif char in '\\/|*<>':
        char = '_'
    if restricted and (char in '!&\'()[]{}$;`^,#' or char.isspace()):
        char = '_'
    if restricted and ord(char) > 127:
        char = '_'
    s = s[:i] + char + s[i+1:]
@phihag phihag closed this in 2aeb06d Jan 11, 2015
@phihag
Copy link
Contributor

@phihag phihag commented Jan 11, 2015

Thank you for the report. I believe this issue to be fixed in youtube-dl 2015.01.11 and newer. See our FAQ if you need help updating.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.