From 9b6e3940a752710e23cab2bf99c7c36aef891619 Mon Sep 17 00:00:00 2001 From: Ben Welsh Date: Wed, 10 Aug 2022 05:25:40 -0700 Subject: [PATCH] Update youtube_dl/extractor/twitter.py Co-authored-by: dirkf --- youtube_dl/extractor/twitter.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/youtube_dl/extractor/twitter.py b/youtube_dl/extractor/twitter.py index 9260d8912..407564372 100644 --- a/youtube_dl/extractor/twitter.py +++ b/youtube_dl/extractor/twitter.py @@ -466,7 +466,12 @@ class TwitterIE(TwitterBaseIE): # Keep the file name short so it doesn't exceed filesystem limits title = description if len(title) > 40: - title = title[:35] + "[...]" + trim = 35 + # allow up to 10 more characters to find whitespace + m = re.search(r'\s+', title, trim, trim + 10) + if m: + trim = m.start() + 1 + title = title[:trim] + '...' if uploader: title = '%s - %s' % (uploader, title)