|
-
Mar 15th, 2026, 03:21 PM
#1
Thread Starter
Frenzied Member
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:

Here is the same file with the slash that I manually replaced with a unicode slash:
Last edited by nbrege; Mar 15th, 2026 at 03:35 PM.
-
Mar 15th, 2026, 09:42 PM
#2
Re: Slash in filename?
Is it possible for you to change the filename before writing it?
Can you show your code?
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Mar 16th, 2026, 08:42 AM
#3
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.
-
Mar 16th, 2026, 09:08 AM
#4
Re: Slash in filename?
 Originally Posted by dday9
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 - ?
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Mar 16th, 2026, 11:06 AM
#5
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.
-
Mar 17th, 2026, 01:56 AM
#6
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
-
Mar 17th, 2026, 03:28 AM
#7
Re: Slash in filename?
 Originally Posted by Zvoni
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>
-
Mar 17th, 2026, 12:21 PM
#8
Thread Starter
Frenzied Member
Re: Slash in filename?
 Originally Posted by dday9
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|