[HOWTO] Fix yt-dlp error "file name too long"

Post tutorials, HOWTO's and other useful resources here.
User avatar
Rava
Contributor
Contributor
Posts: 5401
Joined: 11 Jan 2011, 02:46
Distribution: XFCE 5.01 x86_64 + 4.0 i586
Location: Forests of Germany

[HOWTO] Fix yt-dlp error "file name too long"

Post#1 by Rava » 08 Oct 2022, 08:25

Again encountered the yt-dlp error "file name too long" on twitter. Here a HOWTO fix that.
First let's look at the error occurring

Code: Select all

guest@porteus:/myvideo/reportagen$ yt-dlp https://twitter.com/i/status/1578627042673057792
[twitter] 1578627042673057792: Downloading guest token
[twitter] 1578627042673057792: Downloading JSON metadata
[twitter] 1578627042673057792: Downloading m3u8 information
[info] 1578627042673057792: Downloading 1 format(s): http-2176
ERROR: unable to open for writing: [Errno 36] File name too long: 'JR2 - @WarintheFuture Here a local recorded the smoke (window⧸balcony view) with her comment. She says: it is 6 AM local time. Sunrise today in #Kerch was 06.40 AM cc @JuliaDavisNews @STRATPOINTS_EU @DefenceHQ @general_ben @TheStudyofWar [1578627042673057792].mp4.part'
In it you see the whole long video title / video file name.

Now one fix as suggested via https://github.com/yt-dlp/yt-dlp/issues/5060 is to have the file name as the URL descriptor

Code: Select all

guest@porteus:/myvideo/reportagen$ yt-dlp -o "%(id)s.%(ext)s"  https://twitter.com/i/status/1578627042673057792
[twitter] 1578627042673057792: Downloading guest token
[twitter] 1578627042673057792: Downloading JSON metadata
[twitter] 1578627042673057792: Downloading m3u8 information
[info] 1578627042673057792: Downloading 1 format(s): http-2176
[download] Destination: 1578627042673057792.mp4
[download] 100% of 616.60KiB in 00:02 at 305.55KiB/s
While that works, who wants a non descriptive file named 1578627042673057792.mp4 ?

So I looked for more suggestions and found this https://github.com/yt-dlp/yt-dlp/issues/1136 suggesting an approach of shortening the file name to 200 characters (the limit break is 256 characters, but yt-dlp needs some characters for itself when creating the temp files, therefore cropping the file name to 200 characters is a safe bet.) Feel free to experiment with a slightly higer number, if you do so please report your results in here.

Code: Select all

guest@porteus:/myvideo/reportagen$ yt-dlp  -o "%(title).200s.%(ext)s" https://twitter.com/i/status/1578627042673057792
[twitter] 1578627042673057792: Downloading guest token
[twitter] 1578627042673057792: Downloading JSON metadata
[twitter] 1578627042673057792: Downloading m3u8 information
[info] 1578627042673057792: Downloading 1 format(s): http-2176
[download] Destination: JR2 - @WarintheFuture Here a local recorded the smoke (window⧸balcony view) with her comment. She says: it is 6 AM local time. Sunrise today in #Kerch was 06.40 AM cc @JuliaDavisNews @STRATPOINTS_EU @.mp4
[download] 100% of 616.60KiB in 00:03 at 202.95KiB/s
While JR2 - @WarintheFuture Here a local recorded the smoke (window⧸balcony view) with her comment. She says: it is 6 AM local time. Sunrise today in #Kerch was 06.40 AM cc @JuliaDavisNews @STRATPOINTS_EU @.mp4 is a cropped file name when compared to the original as seen in my 1st [ code ] snippet, it is still nice and descriptive.

I love me this

Code: Select all

yt-dlp  -o "%(title).200s.%(ext)s" URL
solution.
Cheers!
Yours Rava