-
Notifications
You must be signed in to change notification settings - Fork 9.9k
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
Inconsistent character substitution in file name and in --exec option #32871
Comments
Is this a new problem, or did you only just start to use your script? |
Hard to say. I use it for few weeks but didn't pay attention to this. What's going on I realised writing the report. Now, older releases don't work at all but what I digged is that v2024.04.08 tries to make file name with two spaces, even if cannot download it.
and v2024.02.03 doesn't even get to that point. So it seems to be at least as old as since april. |
For context, I'm using the video It seems the video title is coming from a call to It reads the key
So, the double-space is coming from the webpage itself, not any processing done by youtube-dl. Then, the filename for output is generated by I'm guessing there are just a certain portion of youtube videos that have extra spaces inserted in their page data for the video title. Perhaps the youtube API returns the proper filename while this page data is not to be relied on? |
SO, to circle back on this, grabbing the video title from page data on youtube sometimes gives a title that includes an extra space. However, on further testing I found that grabbing from the API only (i removed the first branch of the if here and tested with only API query) still results in a title with an extra space. @tansy youtube-dl is going to output what it's going to output, to put it succinctly. I suggest you simply make use of the output file that youtube_dl gives to determine the output filename. You can use from __future__ import unicode_literals
import youtube_dl
class MyLogger(object):
def debug(self, msg):
pass
def warning(self, msg):
pass
def error(self, msg):
print(msg)
def my_hook(d):
if d['status'] == 'finished':
print(f'output filename is {d["filename"]}')
ydl_opts = {
'logger': MyLogger(),
'progress_hooks': [my_hook],
}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
ydl.download(['https://www.youtube.com/watch?v=BaW_jenozKc']) |
(the hook will trigger twice, once for the mp4 and once for the m4a, so you should disambiguate by using a regex test to grab the mp4 filename only) |
Still, it's clearly wrong if the magic filename marker |
The reason this is happening is because the shell collapses multiple spaces depending on the quoting. You have an "extra" layer of quoting that's not needed. What you have:
What you should use:
(we have |
@tansy i just tested the solution in my recent comment and it generated the |
Thank you for your help. Just tested it and it works. |
@tansy if you look carefully and count quotes, its ultimately because |
I think we're all good, then. Thx @aiur-adept. |
Checklist
Verbose log
Description
I use `--exec option to create a script that does something with a downloaded file. When there is some character substitution, like ':' to ' - ', consecutive spaces appear in file name string and not string passed by `--exec', resulting in wrong script.
In the example above title "Hello, Assembly! Retrocoding the World's Smallest Windows App in x86 ASM" result in file name "Hello, Assembly! Retrocoding the World's Smallest Windows App in x86 ASM-b0zxIfJJLAY.webm"
Similar with this title: (@D82C7JS_2iw)
Or one from here: uRlxN0_zVHo.
The text was updated successfully, but these errors were encountered: