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
[Feature request] Handle Long filenames in default template and temporary files #1136
Comments
Are you asking only about the default? or about user-provided templates too? For user provided templates, you can do something like |
Related: ytdl-org/youtube-dl#29989 |
Improved defaults would be nice but I thought the effects of temp files (since they will always be longer than the main output file) was the more confusing aspect and there is currently no mechanism for specifying a template for temp files (they just inherit the output template). I experimented with a number of techniques for deterministically shortening but they were not ideal - any format with length limits would ultimately end up being a guess but some limits as you suggested with maybe ~160 characters for title and ~40 for ID might be sensible. Then if temp files could have a different format maybe as high as ~180 for title would be okay without risking a sudden error at chunk 10000. |
annoyingly, when using yt-dlp Ive had an issue where the filename which was video title + chapter name was too long, which only gave a confusing 'no such file or directory' error. I suppose this is a separate issue |
@GenericGoose I think that may under this issue as I see it. I don't think there's a reliable and deterministic way to prevent invalid names in all cases since the limitations come down to filesystems (not even just OS differences) but the way I see this problem is in terms of defaults. The current defaults have no built-in size limitations (even for common limitations such as 255 chars) and since they're composed from multiple properties there are many combinations that can exceed limitations at different stages. In your case the defaults that include chapter names can also encounter this issue. A workaround is to override the default templates unless a more conservative default is introduced. If we consider this issue to have 2 parts:
The your issue would fall clearly under part 1. While I think part 2 is a bigger concern (because it causes confusing errors partway into a download rather than giving a clearer error and failing fast) part 1 is certainly a component of this issue in my view :) |
Re: cross-platform compatibility, you can allow the user to specify a maximum file length as a flag. Users can then alias yt-dlp to automatically include that flag at their leisure. Alternatively, you can determine if the attempted path exceeds the maximum file length by checking to see if the file was successfully created or not. File APIs for all major platforms will provide this information. You can then truncate the requested filename and inform the user. This is how things were handled all the way back in FAT16 with the "FILENA~1.EXT" convention. I run into this bug all the time when archiving tweets. |
It should also be noted that the limitation is often not 255 characters but 255 bytes so for non-ASCII languages you are limited to a lot fewer than 255 char. |
This is why I added the |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
@InconsolableCellist Read the comments literally just above your question! #1136 (comment) #1136 (comment) |
This is THE MOST ANNOYING bug in |
Thank you for this feature. I figured I'd leave a comment with some things I found unclear myself and had to check so if anybody else comes across this thread they don't need to check it for themselves:
|
This happens with Twitter videos often because it uses the whole tweet as filename. How about just using the Twitter handle plus tweet ID and then crop the Tweet? |
This comment was marked as off-topic.
This comment was marked as off-topic.
Thanks to comments in this thread I got this working: $ yt-dlp -o '%(title).200B.%(ext)s' '<url>' Hypothetically, if I wanted to be able to tell which files have truncated names, is it possible to add something to indicate that? Could be an |
Add a |
Awesome. At first I misunderstood you, but this seems to be working great! yt-dlp --output '%(title).200B%(title.201&…|)s.%(ext)s' Edit: yt-dlp --output '%(title).200B%(title.201B&…|)s.%(ext)s' |
@pukkandan : isn't this mixing apples and oranges (200 bytes and 201st character) ? |
@chrizilla possibly. Do you have any suggestions? in #6882 this was suggested but I haven't tried it myself: |
@rpdelaney : If your title consists of ANSI characters only, I guess the 201st character is the 201st byte. But for unicode chars, we probably need to ask if the 201st byte is present, not the 201st character. But I haven't looked into if and how this can be done. Maybe
Depends. For example, the |
At least in linux, I know that the filename length limits are counted in raw bytes since there is no enforcement of a specific character encoding for a filesystem. Counting bytes would be safest. |
@chrizilla How about this then?
|
@rpdelaney : Does it work for you? Yes, this was my suggestion, but upon closer inspection it doesn't work for me. I am not sure this is really on-topic here, so I opened #6983. |
Same for https://twitter.com/BrainStorm_Joe/status/1734386440706953260.
|
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
Everyone agrees this is a good idea. The reason this is not implemented is mostly due to technical reasons and partly due to compatibility reasons. More examples aren't helping. |
Checklist
Verbose log
Description
The defaults can result in filenames that are too long and confusingly this can also occur in temporary files. The example here shows a 239 character filename fails when the
.part-Frag10
suffix causes the filename to exceed 255 characters.The workaround is to explicitly specify an output template that will not become too long even when suffixes are added. The default
%(title)s [%(id)s].%(ext)s
and fallback%(title)s-%(id)s.%(ext)s
can both exceed 255 characters, especially with videos in long tweets.In the example provided the output template is explicitly set to a filename that will exactly exceed 255 characters on fragment 10 to better illustrate the issue. However, omitting template or explicitly using the default
%(title)s [%(id)s].%(ext)s
will still result in an immediate failure on fragment 1.This is related to #1003 and would appear to be cross-platform issue (and depends on the filesystem for the target files rather than the OS or runtime).
Work published by NASA is in the public domain so there are no licensing concerns with testing using this URL.
There are various codepaths that expect to be able to add a suffix to a temporary file and the temporary filename is based on the destination filename. By adding an option to specify tempfile format such as
%(extractor)s-%(id)s.%(ext)s
and altering the default file template to set some high but sane limits this could be mitigated for most users and still allow advanced users to explicitly specify long filenames.The text was updated successfully, but these errors were encountered: