Skip to content

cli.utils.formatter: respect max file name length #5921

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

Merged

Conversation

bastimeyer
Copy link
Member

Fixes #5919

To make sense of this in just a few seconds, just have a look at the two tests added in the last commit...

@bastimeyer bastimeyer changed the title tests: refactor CLI path utils tests cli.utils.formatter: respect max file name length Apr 3, 2024
@bastimeyer bastimeyer force-pushed the cli/utils/formatter/truncate-filename branch from 1020dfd to 5059ed2 Compare April 3, 2024 22:04
Comment on lines +45 to +51
# no file name extension (no dot separator in path or file name extension too long):
# truncate the whole thing
if not keep_extension or len(parts) == 1 or len(parts[1]) > 10:
encoded = path.encode("utf-8")
truncated = encoded[:length]
decoded = truncated.decode("utf-8", errors="ignore")
return decoded
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, the or len(parts[1]) > 10 check is added here so that only file name extensions with fewer than 11 characters will be kept. We must avoid unnecessary file name truncation in cases where --output="{title}" (no user-set file name extension) and when the title metadata includes a dot somewhere in its value. Without the check, the whole text after the last dot would be treated as a file name extension and always be kept, unnecessarily reducing the available space before of the last dot.

@bastimeyer bastimeyer merged commit eecf609 into streamlink:master Apr 4, 2024
@bastimeyer bastimeyer deleted the cli/utils/formatter/truncate-filename branch April 4, 2024 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

File name too long error when using metadata in output filename
2 participants