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
exec on windows needs double quotes around filename, not single quotes #5889
Comments
Just to be clear, is there any way to use single quotes in the windows shell? |
you can use single quotes in windows powershell, but i'm pretty sure you need double quotes or no quotes with escaped spaces (escape with '^') for cmd. I tried running youtube-dl link --exec player.exe in powershell with still no luck though; i think it spawns a cmd process since I can open files with mpc-hc64.exe 'file name.mp4'. And actually I don't get a syntax error; i get file not found in mpc-hc since it's looking for files 'firstwordofname and 2ndword and 3rdword and lastword.mp4' like i'm sending multiple arguments to the player to make a playlist. Surrounding the path with double quotes in windows cmd and keeping it single quotes elsewhere i think is the simplest solution. also I see i can use --restrict-filenames to make the filename have no spaces which has shlex_quote and exec not add single quotes so it works. Without needed to manipulate the filename I can also do (replace "link" with the url or have it as a command argument) youtube-dl link to get the filename of the downloaded vid and play it myself. |
This is my ugly, ugly, ugly hack for adb usage adbWin.bat
and in in youtube-dl:
Note that it will replace every occurrance of a single quote by a double quote |
Batch file fix works until you get a title with a single quote in it. Is there a way to force it just to change the first and the last, with a batch file until there is a more permanent way? |
I ran into the same issue. The problem here is that there are two cases: youtube-dl will only return a quoted string when the path+filename contains spaces. If not, it will return an unquoted string. So that makes it harder to find a simple solution without turning to complicated batch files. I'm currently using a similar workaround to the one proposed by marnunez, but this one is restricted to a single line. Using the above, you can add it to youtube-dl in a single line, where %a becomes the trimmed string instead of {}. But be careful as many quote signs need to be doubled because you're using quotes within quotes! So here's an example. This will just echo the filename: This one is more complicated. An ffmpeg conversion of the output of youtube-dl to mkv, followed by the deletion of the original file. Be careful to always put %a between double double quotes as the filename may contain spaces. The last example uses another interesting feature of the for loop. The resulting variables can be used with the following syntax (referenced in "for /?"): So in the above example, I used %~dpna to strip the filename, including the path, of its extension, so I could add another extension to it. The only major downside to the above method, is that it can't handle filenames with quotes. In that case, you could write a batch file, or an executable, that takes a string, and strips it of its leading and trailing quote, if present. If anyone has a way of doing that in a single line command, as I've shown above, I'd be interested to learn about it. |
I was trying to auto open the file after dl using exec on Windows build (i.e. youtube-dl youtubelink --exec mpc-hc64.exe), but I kept getting syntax error on windows e.g. ([exec] Executing command: mpc-hc64.exe 'The Doors - Break on Through (To the Other Side)-cJQwnAhXnBk.mp4'
blah blah syntax error file not found)
I see shlex_quote def in compat.py adds single quotes around the string and escapes single quotes if it can't import. I just removed the import and replaced the definition to wrap with double quotes and escape the double quotes.
compat.py excerpt:
def shlex_quote(s):
if re.match(r"^[-_\w./]+$", s):
return s
else:
return '"' + s.replace('"', '"'"'"') + '"'
Maybe you can import quote from shlex to use double quotes on windows, but this changed definition works for me, and I can work with/open the files with exec on Windows now.
The text was updated successfully, but these errors were encountered: