Results 1 to 8 of 8

Thread: Slash in filename?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2006
    Location
    MI
    Posts
    2,012

    Slash in filename?

    I have an issue that's been driving me nuts for a couple hours now. I am working on developing a front end interface for yt-dlp, which is an open-source command-line downloader for sites like YouTube. I am successfully downloading all the songs (currently over 600) in a YouTube Music playlist to my PC. I have yt-dlp configured to name the file as "Artist - Title.mp3". The problem is that if a track has a slash ("/") in the title the file actually gets saved with the slash in the filename. Since a slash is a forbidden character in a filename, I am at a loss to understand how yt-dlp can write such a file. Doing some Googling I found that yt-dlp supposedly replaces any illegal characters (<>:"/\|?*) with the unicode equivalent, but the slash in these files looks like a regular forward slash. I wrote a test routine that loops through the characters in the filename & it says that the slash is ascii 63, which is a question mark. Also, any track titles that have a question mark in them DO get written with a unicode question mark character. Anyone have any idea what this slash character is & how it's able to be used in a filename?

    Example of files with question mark & slash in filename:

    Name:  Slash.jpg
Views: 588
Size:  13.7 KB


    Here is the same file with the slash that I manually replaced with a unicode slash:

    Name:  Slash.jpg
Views: 584
Size:  7.3 KB
    Last edited by nbrege; Mar 15th, 2026 at 03:35 PM.

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: Slash in filename?

    Is it possible for you to change the filename before writing it?
    Can you show your code?

  3. #3
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Posts
    12,398

    Re: Slash in filename?

    yt-dlp is an open-source library, you could simply inspect the code.

    It looks like the sanitize_filename method (line 631 of utils/_utils.py) has this line:
    Code:
    elif is_id is NO_DEFAULT and not restricted and char in '"*:<>?|/\\':
        # Replace with their full-width unicode counterparts
        return {'/': '\u29F8', '\\': '\u29f9'}.get(char, chr(ord(char) + 0xfee0))
    Which maps the forward slash ascii character to unicode character \u29F8 which represents the BIG SOLIDUS character (example here).

    So, while the filename visually looks like it should fail, it's not actually using a forbidden character.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | HtmlLessons | CssLessons | Code Tags | Sword of Fury - Jameram

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: Slash in filename?

    Quote Originally Posted by dday9 View Post
    yt-dlp is an open-source library, you could simply inspect the code.

    It looks like the sanitize_filename method (line 631 of utils/_utils.py) has this line:
    Code:
    elif is_id is NO_DEFAULT and not restricted and char in '"*:<>?|/\\':
        # Replace with their full-width unicode counterparts
        return {'/': '\u29F8', '\\': '\u29f9'}.get(char, chr(ord(char) + 0xfee0))
    Which maps the forward slash ascii character to unicode character \u29F8 which represents the BIG SOLIDUS character (example here).

    So, while the filename visually looks like it should fail, it's not actually using a forbidden character.
    I'm not familiar with Python. How would you change that to swap a / for a - ?

  5. #5
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Posts
    12,398

    Re: Slash in filename?

    It isn't in reality. What's happening is that it is converting it to the big solidus Unicode character, but the viewer the OP is using has the charset set to something else (probably ascii). The charset cannot find the proper mapping to the big solidus and it renders it as a question mark.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | HtmlLessons | CssLessons | Code Tags | Sword of Fury - Jameram

  6. #6
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    5,269

    Re: Slash in filename?

    i don't understand, why you're making such a rocket science out of it.
    take any illegal character and replace it with underscore and be done with it.....
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  7. #7
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    6,192

    Re: Slash in filename?

    Quote Originally Posted by Zvoni View Post
    i don't understand, why you're making such a rocket science out of it.
    take any illegal character and replace it with underscore and be done with it.....
    Big solidus is not an illegal character.

    OP's original problem is that while enumerating files somewhere Unicode code points gets transcoded to ANSI which sould not happen or their utility will not work correctly in Chinese locale for what ot matters.

    cheers,
    </wqw>

  8. #8

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2006
    Location
    MI
    Posts
    2,012

    Re: Slash in filename?

    Quote Originally Posted by dday9 View Post
    yt-dlp is an open-source library, you could simply inspect the code.

    It looks like the sanitize_filename method (line 631 of utils/_utils.py) has this line:
    Code:
    elif is_id is NO_DEFAULT and not restricted and char in '"*:<>?|/\\':
        # Replace with their full-width unicode counterparts
        return {'/': '\u29F8', '\\': '\u29f9'}.get(char, chr(ord(char) + 0xfee0))
    Which maps the forward slash ascii character to unicode character \u29F8 which represents the BIG SOLIDUS character (example here).

    So, while the filename visually looks like it should fail, it's not actually using a forbidden character.
    Dday ... thanks for the excellent explanation. I never thought to look in the yt-dlp source code to see what it is doing, but I doubt I would have been able to find it anyways. Thanks again...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width