yt-dlc icon indicating copy to clipboard operation
yt-dlc copied to clipboard

[Broken] YouTube fails to download with [Errno 36] File name too long

Open arter97 opened this issue 3 years ago • 13 comments

Checklist

  • [x] I'm reporting a broken site support
  • [x] I've verified that I'm running youtube-dlc version 2020.10.31
  • [x] I've checked that all provided URLs are alive and playable in a browser
  • [x] I've checked that all URLs and arguments with special characters are properly quoted or escaped
  • [x] I've searched the bugtracker for similar issues including closed ones

Verbose log

arter97@arter97-x1:~/youtube-dl/youtube_dlc$ python3.9 ./__main__.py --verbose https://youtu.be/fYyRDoTPd1E
[debug] System config: []
[debug] User config: []
[debug] Custom config: []
[debug] Command-line args: ['--verbose', 'https://youtu.be/fYyRDoTPd1E']
[debug] Loading archive file None
[debug] Encodings: locale UTF-8, fs utf-8, out utf-8, pref UTF-8
[debug] youtube-dlc version 2020.11.11-2
[debug] Git HEAD: 97d391cd0d66
[debug] Python version 3.9.0 (CPython) - Linux-5.4.77+-x86_64-with-glibc2.32
[debug] exe versions: ffmpeg 4.2.4, ffprobe 4.2.4
[debug] Proxy map: {}
[youtube] fYyRDoTPd1E: Downloading webpage
[youtube] fYyRDoTPd1E: Downloading MPD manifest
[debug] Default format spec: bestvideo+bestaudio/best
WARNING: Requested formats are incompatible for merge and will be merged into mkv.
[debug] Invoking downloader on 'https://manifest.googlevideo.com/api/manifest/dash/expire/1605812269/ei/zWu2X7KrHZSc4QK6uq1o/ip/222.104.200.20/id/7d8c910e84cf7751/source/youtube/requiressl/yes/playback_host/r6---sn-3u-u5xe.googlevideo.com/mh/IA/mm/31%2C29/mn/sn-3u-u5xe%2Csn-3u-bh2k/ms/au%2Crdu/mv/m/mvi/6/pl/16/hfr/all/as/fmp4_audio_clear%2Cwebm_audio_clear%2Cwebm2_audio_clear%2Cfmp4_sd_hd_clear%2Cwebm2_sd_hd_clear/initcwndbps/1411250/vprv/1/mt/1605790606/fvip/6/keepalive/yes/itag/0/sparams/expire%2Cei%2Cip%2Cid%2Csource%2Crequiressl%2Chfr%2Cas%2Cvprv%2Citag/sig/AOq0QJ8wRgIhAK6wOFlM5bKS43d0sh9PthBE10T8hUFghfM1OmJn4hcfAiEA_iLJQWZbsq51KW4PYzGFSPLf7HKZjupRrStBQ-bxCT0%3D/lsparams/playback_host%2Cmh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps/lsig/AG3C_xAwRQIhALbDqXkkC9ZOO9wvaJSJC6Kb8a0_RYDsLw2ie3aGEaTfAiBXlousgD0YbLit_dUesE90EU6QTsCEhvKS0BUbeYhK7g%3D%3D'
[dashsegments] Total fragments: 79
[download] Destination: ആയിരത്തിലധികം മനുഷ്യരെ കൊന്ന് തിന്ന നരഭോജി.അലക്സാണ്ടര്‍ സാവ്നി  ബീന്‍, ചാപ്റ്റര്‍ 1-fYyRDoTPd1E.f136.mp4
ERROR: unable to open for writing: [Errno 36] File name too long: 'ആയിരത്തിലധികം മനുഷ്യരെ കൊന്ന് തിന്ന നരഭോജി.അലക്സാണ്ടര്\u200d സാവ്നി  ബീന്\u200d, ചാപ്റ്റര്\u200d 1-fYyRDoTPd1E.f136.mp4.part-Frag0.part'
Traceback (most recent call last):
  File "/home/arter97/youtube-dl/youtube_dlc/downloader/http.py", line 257, in download
    ctx.stream, ctx.tmpfilename = sanitize_open(
  File "/home/arter97/youtube-dl/youtube_dlc/utils.py", line 2055, in sanitize_open
    stream = open(encodeFilename(filename), open_mode)
OSError: [Errno 36] File name too long: 'ആയിരത്തിലധികം മനുഷ്യരെ കൊന്ന് തിന്ന നരഭോജി.അലക്സാണ്ടര്\u200d സാവ്നി  ബീന്\u200d, ചാപ്റ്റര്\u200d 1-fYyRDoTPd1E.f136.mp4.part-Frag0.part'

Description

https://youtu.be/fYyRDoTPd1E fails to download. I believe it has to do something with title(filename) sanitation. \u200d is left out escaped.

The issue persists across many CPython runtimes including 20.04's default Python 3.8.

Thanks.

arter97 avatar Nov 19 '20 13:11 arter97

Strange... I have Python version 3.6.9 and here it goes well.:

youtube-dlc --verbose https://youtu.be/fYyRDoTPd1E
[debug] System config: []
[debug] User config: ['-i', '-o', '/dev/shm/%(title)s.%(ext)s', '-f', 'bestvideo[height<=1080][ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best', '--no-mtime', '--add-metadata', '--embed-thumbnail']
[debug] Custom config: []
[debug] Command-line args: ['--verbose', 'https://youtu.be/fYyRDoTPd1E']
[debug] Loading archive file None
[debug] Encodings: locale UTF-8, fs utf-8, out UTF-8, pref UTF-8
[debug] youtube-dlc version 2020.11.17
[debug] Python version 3.6.9 (CPython) - Linux-4.15.0-124-generic-x86_64-with-LinuxMint-19.3-tricia
[debug] exe versions: ffmpeg N-99932-g17a0dfe-Nico-20201118, ffprobe N-99932-g17a0dfe-Nico-20201118
[debug] Proxy map: {}
[youtube] fYyRDoTPd1E: Downloading webpage
[youtube] fYyRDoTPd1E: Downloading MPD manifest
[youtube] fYyRDoTPd1E: Downloading thumbnail ...
[youtube] fYyRDoTPd1E: Writing thumbnail to: /dev/shm/ആയിരത്തിലധികം മനുഷ്യരെ കൊന്ന് തിന്ന നരഭോജി.അലക്സാണ്ടര്‍ സാവ്നി  ബീന്‍, ചാപ്റ്റര്‍ 1.webp
[debug] Invoking downloader on 'https://manifest.googlevideo.com/api/manifest/dash/expire/1605826824/ei/qKS2X5C-B5rR1wKG-7rADg/ip/217.121.193.63/id/7d8c910e84cf7751/source/youtube/requiressl/yes/playback_host/r5---sn-5hnekn7l.googlevideo.com/mh/IA/mm/31%2C26/mn/sn-5hnekn7l%2Csn-4g5e6nsk/ms/au%2Conr/mv/m/mvi/5/pl/15/hfr/all/as/fmp4_audio_clear%2Cwebm_audio_clear%2Cwebm2_audio_clear%2Cfmp4_sd_hd_clear%2Cwebm2_sd_hd_clear/initcwndbps/2095000/vprv/1/mt/1605805118/fvip/5/keepalive/yes/itag/0/sparams/expire%2Cei%2Cip%2Cid%2Csource%2Crequiressl%2Chfr%2Cas%2Cvprv%2Citag/sig/AOq0QJ8wRQIgJmu_OhFpATcUdldiYzpmciYFNwysFDagDtIrFg3ngooCIQDKqhOz4oSwb4nJD8ziKjZz18E_chCnlR48tuiVA-UW6Q%3D%3D/lsparams/playback_host%2Cmh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps/lsig/AG3C_xAwRQIhANU2nzKdySgdt1GFvIlK_uha80b0we2zv1z3IuRy3yQEAiA52iopBZPnKr2dqzxIh8cPxZUELGkjltFY8EUbGxgcbA%3D%3D'
[dashsegments] Total fragments: 79
[download] Destination: /dev/shm/ആയിരത്തിലധികം മനുഷ്യരെ കൊന്ന് തിന്ന നരഭോജി.അലക്സാണ്ടര്‍ സാവ്നി  ബീന്‍, ചാപ്റ്റര്‍ 1.f136.mp4
[download] 100% of 46.32MiB in 00:14
[debug] Invoking downloader on 'https://manifest.googlevideo.com/api/manifest/dash/expire/1605826824/ei/qKS2X5C-B5rR1wKG-7rADg/ip/217.121.193.63/id/7d8c910e84cf7751/source/youtube/requiressl/yes/playback_host/r5---sn-5hnekn7l.googlevideo.com/mh/IA/mm/31%2C26/mn/sn-5hnekn7l%2Csn-4g5e6nsk/ms/au%2Conr/mv/m/mvi/5/pl/15/hfr/all/as/fmp4_audio_clear%2Cwebm_audio_clear%2Cwebm2_audio_clear%2Cfmp4_sd_hd_clear%2Cwebm2_sd_hd_clear/initcwndbps/2095000/vprv/1/mt/1605805118/fvip/5/keepalive/yes/itag/0/sparams/expire%2Cei%2Cip%2Cid%2Csource%2Crequiressl%2Chfr%2Cas%2Cvprv%2Citag/sig/AOq0QJ8wRQIgJmu_OhFpATcUdldiYzpmciYFNwysFDagDtIrFg3ngooCIQDKqhOz4oSwb4nJD8ziKjZz18E_chCnlR48tuiVA-UW6Q%3D%3D/lsparams/playback_host%2Cmh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps/lsig/AG3C_xAwRQIhANU2nzKdySgdt1GFvIlK_uha80b0we2zv1z3IuRy3yQEAiA52iopBZPnKr2dqzxIh8cPxZUELGkjltFY8EUbGxgcbA%3D%3D'
[dashsegments] Total fragments: 43
[download] Destination: /dev/shm/ആയിരത്തിലധികം മനുഷ്യരെ കൊന്ന് തിന്ന നരഭോജി.അലക്സാണ്ടര്‍ സാവ്നി  ബീന്‍, ചാപ്റ്റര്‍ 1.f140.m4a
[download] 100% of 6.40MiB in 00:03
[ffmpeg] Merging formats into "/dev/shm/ആയിരത്തിലധികം മനുഷ്യരെ കൊന്ന് തിന്ന നരഭോജി.അലക്സാണ്ടര്‍ സാവ്നി  ബീന്‍, ചാപ്റ്റര്‍ 1.mp4"
[debug] ffmpeg command line: ffmpeg -y -loglevel repeat+info -i 'file:/dev/shm/ആയിരത്തിലധികം മനുഷ്യരെ കൊന്ന് തിന്ന നരഭോജി.അലക്സാണ്ടര്‍ സാവ്നി  ബീന്‍, ചാപ്റ്റര്‍ 1.f136.mp4' -i 'file:/dev/shm/ആയിരത്തിലധികം മനുഷ്യരെ കൊന്ന് തിന്ന നരഭോജി.അലക്സാണ്ടര്‍ സാവ്നി  ബീന്‍, ചാപ്റ്റര്‍ 1.f140.m4a' -c copy -map 0:v:0 -map 1:a:0 'file:/dev/shm/ആയിരത്തിലധികം മനുഷ്യരെ കൊന്ന് തിന്ന നരഭോജി.അലക്സാണ്ടര്‍ സാവ്നി  ബീന്‍, ചാപ്റ്റര്‍ 1.temp.mp4'
Deleting original file /dev/shm/ആയിരത്തിലധികം മനുഷ്യരെ കൊന്ന് തിന്ന നരഭോജി.അലക്സാണ്ടര്‍ സാവ്നി  ബീന്‍, ചാപ്റ്റര്‍ 1.f140.m4a (pass -k to keep)
Deleting original file /dev/shm/ആയിരത്തിലധികം മനുഷ്യരെ കൊന്ന് തിന്ന നരഭോജി.അലക്സാണ്ടര്‍ സാവ്നി  ബീന്‍, ചാപ്റ്റര്‍ 1.f136.mp4 (pass -k to keep)
[ffmpeg] Adding metadata to '/dev/shm/ആയിരത്തിലധികം മനുഷ്യരെ കൊന്ന് തിന്ന നരഭോജി.അലക്സാണ്ടര്‍ സാവ്നി  ബീന്‍, ചാപ്റ്റര്‍ 1.mp4'
[debug] ffmpeg command line: ffmpeg -y -loglevel repeat+info -i 'file:/dev/shm/ആയിരത്തിലധികം മനുഷ്യരെ കൊന്ന് തിന്ന നരഭോജി.അലക്സാണ്ടര്‍ സാവ്നി  ബീന്‍, ചാപ്റ്റര്‍ 1.mp4' -map 0 -c copy -metadata 'title=ആയിരത്തിലധികം മനുഷ്യരെ കൊന്ന് തിന്ന നരഭോജി.അലക്സാണ്ടര്‍ സാവ്നി  ബീന്‍, ചാപ്റ്റര്‍ 1' -metadata date=20191008 -metadata 'description=Chapter 1 
https://youtu.be/fYyRDoTPd1E

Chapter 2 https://youtu.be/7H1HZdRLpBA

Chapter 3 
https://youtu.be/o6Sg-0L9Wlo

അലക്സാണ്ടര്‍ സാവ്നി ബീനിന്‍റെ കഥ സമാനതകളില്ലാത്ത ഒന്നാണ്. പുരാവൃത്തങ്ങളുടെ ഭീകര കഥനങളില്‍ ഒരു മഹാമേരുവിനേപ്പോലെ സാവ്നി ബീന്‍ വേറിട്ട് നില്‍ക്കുന്നു. ഒന്നും രണ്ടുമല്ല. ഏകദേശം ആയിരത്തോളം മനുഷ്യരെയാണ് സാവ്നി ബീനും ഭാര്യ ആഗ്നസും ചേര്‍ന്ന് നരഭോജനം ചെയ്തത് .' -metadata 'comment=Chapter 1 
https://youtu.be/fYyRDoTPd1E

Chapter 2 https://youtu.be/7H1HZdRLpBA

Chapter 3 
https://youtu.be/o6Sg-0L9Wlo

അലക്സാണ്ടര്‍ സാവ്നി ബീനിന്‍റെ കഥ സമാനതകളില്ലാത്ത ഒന്നാണ്. പുരാവൃത്തങ്ങളുടെ ഭീകര കഥനങളില്‍ ഒരു മഹാമേരുവിനേപ്പോലെ സാവ്നി ബീന്‍ വേറിട്ട് നില്‍ക്കുന്നു. ഒന്നും രണ്ടുമല്ല. ഏകദേശം ആയിരത്തോളം മനുഷ്യരെയാണ് സാവ്നി ബീനും ഭാര്യ ആഗ്നസും ചേര്‍ന്ന് നരഭോജനം ചെയ്തത് .' -metadata 'purl=https://www.youtube.com/watch?v=fYyRDoTPd1E' -metadata 'artist=NiA TV' 'file:/dev/shm/ആയിരത്തിലധികം മനുഷ്യരെ കൊന്ന് തിന്ന നരഭോജി.അലക്സാണ്ടര്‍ സാവ്നി  ബീന്‍, ചാപ്റ്റര്‍ 1.temp.mp4'
[ffmpeg] Converting thumbnail "/dev/shm/ആയിരത്തിലധികം മനുഷ്യരെ കൊന്ന് തിന്ന നരഭോജി.അലക്സാണ്ടര്‍ സാവ്നി  ബീന്‍, ചാപ്റ്റര്‍ 1.webp" to JPEG
[debug] ffmpeg command line: ffmpeg -y -loglevel repeat+info -i 'file:/dev/shm/ആയിരത്തിലധികം മനുഷ്യരെ കൊന്ന് തിന്ന നരഭോജി.അലക്സാണ്ടര്‍ സാവ്നി  ബീന്‍, ചാപ്റ്റര്‍ 1.webp' -bsf:v mjpeg2jpeg 'file:/dev/shm/ആയിരത്തിലധികം മനുഷ്യരെ കൊന്ന് തിന്ന നരഭോജി.അലക്സാണ്ടര്‍ സാവ്നി  ബീന്‍, ചാപ്റ്റര്‍ 1.jpg'
[atomicparsley] Adding thumbnail to "/dev/shm/ആയിരത്തിലധികം മനുഷ്യരെ കൊന്ന് തിന്ന നരഭോജി.അലക്സാണ്ടര്‍ സാവ്നി  ബീന്‍, ചാപ്റ്റര്‍ 1.mp4"
[debug] AtomicParsley command line: AtomicParsley '/dev/shm/ആയിരത്തിലധികം മനുഷ്യരെ കൊന്ന് തിന്ന നരഭോജി.അലക്സാണ്ടര്‍ സാവ്നി  ബീന്‍, ചാപ്റ്റര്‍ 1.mp4' --artwork '/dev/shm/ആയിരത്തിലധികം മനുഷ്യരെ കൊന്ന് തിന്ന നരഭോജി.അലക്സാണ്ടര്‍ സാവ്നി  ബീന്‍, ചാപ്റ്റര്‍ 1.jpg' -o '/dev/shm/ആയിരത്തിലധികം മനുഷ്യരെ കൊന്ന് തിന്ന നരഭോജി.അലക്സാണ്ടര്‍ സാവ്നി  ബീന്‍, ചാപ്റ്റര്‍ 1.temp.mp4'

OSError: [Errno 36] File name too long:

But I have a different Operating System (LinuxMint 19.3; based on Ubuntu 18.04). However your ffmpeg version is rather old (don't know if that matters in this case).

[Edit] I see that the title is in the Malayalam language. Do you have that font installed? If not, than you maybe have to install it (Google search).

nicolaasjan avatar Nov 19 '20 17:11 nicolaasjan

try youtube-dlc -o "%(id)s.%(ext)s" https://youtu.be/fYyRDoTPd1E from https://www.reddit.com/r/youtubedl/comments/ddj635/file_name_too_long_error/

october262 avatar Nov 19 '20 22:11 october262

I remember @h-h-h-h had mentioned about a fix for this

pukkandan avatar Nov 20 '20 00:11 pukkandan

@nicolaasjan

Strange... I have Python version 3.6.9 and here it goes well.:

youtube-dlc --verbose https://youtu.be/fYyRDoTPd1E
[debug] System config: []
[debug] User config: ['-i', '-o', '/dev/shm/%(title)s.%(ext)s', '-f', 'bestvideo[height<=1080][ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best', '--no-mtime', '--add-metadata', '--embed-thumbnail']

Probably because you're using a user config. Btw, why are you downloading it to shm?

But I have a different Operating System (LinuxMint 19.3; based on Ubuntu 18.04). However your ffmpeg version is rather old (don't know if that matters in this case).

Nah, the error happens in the Python code.

[Edit] I see that the title is in the Malayalam language. Do you have that font installed? If not, than you maybe have to install it (Google search).

The download should work regardless with Python and Linux VFS's Unicode handling. And yes, I have a font installed and the terminal shows them properly.

arter97 avatar Nov 20 '20 04:11 arter97

@october262

try youtube-dlc -o "%(id)s.%(ext)s" https://youtu.be/fYyRDoTPd1E from https://www.reddit.com/r/youtubedl/comments/ddj635/file_name_too_long_error/

Well this works, but it's merely just a workaround. I need the title to be written in the filename.

And the original Reddit thread you linked probably really is long for the file-system to handle. The video I linked is not, and manually creating a file with the same title works.

It's clear to me that something's wrong with the Python code, and as I mentioned in the original post, I suspect it's a mis-unescaping of certain characters(\u200d).

arter97 avatar Nov 20 '20 04:11 arter97

I remember @h-h-h-h had mentioned about a fix for this [@pukkandan]

  • Under Windows, there's the MAX_PATH limitation (max path length of 260 chars), which this aims to fix. Would be needed to be applied before every file access, though. The PR doesn't do it. The specifics of it would need to be discussed with @blackjack4494.
  • The Python Windows installer has some option about changing an OS setting regarding file paths. By default, that OS setting is off. If someone develops with that setting turned on, they may be oblivious to the issue (not sure).

But, if I'm not mistaken, people here aren't on Windows.

h-h-h-h avatar Nov 20 '20 05:11 h-h-h-h

I need the title to be written in the filename. [@arter97]

If it's a MAX_PATH issue, shortening the title helps: -o "%(title).100s.%(ext)s"

This should actually be documented so everybody knows these capabilities. It's a Python string formatting thing.

h-h-h-h avatar Nov 20 '20 05:11 h-h-h-h

Hahaha, looks like it is indeed a filename length issue.

python3.9 ./__main__.py -o '%(title)s.%(ext)s' https://youtu.be/fYyRDoTPd1E

This works.

python3.9 ./__main__.py -o '%(title)s-%(id)s.%(ext)s' https://youtu.be/fYyRDoTPd1E

This doesn't, and it turns out that adding ID makes the file name exceeds 256 bytes.

You guys can close this issue. Welp.

arter97 avatar Nov 20 '20 05:11 arter97

@arter97

Probably because you're using a user config.

You're right... Without it, it throws the filename error.

Btw, why are you downloading it to shm?

Yeah, I'll have to admit that's a bit strange. :) But:

  1. I don't intend to keep these files.
  2. It's a bit faster.
  3. It doesn't unnecessarily wear my ssd.

nicolaasjan avatar Nov 20 '20 08:11 nicolaasjan

This doesn't fix the issue but you can use: %(title).50s to limit the title length as a work around.

sh ~/Resources/GitHub/anonymous/yt-dlc
$ python -m youtube_dlc -o '%(title).50s-%(id)s.%(ext)s' https://youtu.be/fYyRDoTPd1E
[youtube] fYyRDoTPd1E: Downloading webpage
[youtube] fYyRDoTPd1E: Downloading MPD manifest
WARNING: Requested formats are incompatible for merge and will be merged into mkv.
[dashsegments] Total fragments: 79
[download] Destination: ആയിരത്തിലധികം മനുഷ്യരെ കൊന്ന് തിന്ന നരഭോജി.അലക്സാണ-fYyRDoTPd1E.f136.mp4
[download] 100% of 46.32MiB in 00:20
[dashsegments] Total fragments: 43
[download] Destination: ആയിരത്തിലധികം മനുഷ്യരെ കൊന്ന് തിന്ന നരഭോജി.അലക്സാണ-fYyRDoTPd1E.f251.webm
[download] 100% of 6.42MiB in 00:35
[ffmpeg] Merging formats into "ആയിരത്തിലധികം മനുഷ്യരെ കൊന്ന് തിന്ന നരഭോജി.അലക്സാണ-fYyRDoTPd1E.mkv"
Deleting original file ആയിരത്തിലധികം മനുഷ്യരെ കൊന്ന് തിന്ന നരഭോജി.അലക്സാണ-fYyRDoTPd1E.f251.webm (pass -k to keep)
Deleting original file ആയിരത്തിലധികം മനുഷ്യരെ കൊന്ന് തിന്ന നരഭോജി.അലക്സാണ-fYyRDoTPd1E.f136.mp4 (pass -k to keep)

konomikitten avatar Nov 22 '20 02:11 konomikitten

Regarding the MAX_PATH issue on Windows, a temporary fix is to use \\?\C: notation at the beginning of the output string. E.g:

"\\?\C:\%(uploader)s/%(uploader)s - %(upload_date)s - %(title)s/%(uploader)s - %(upload_date)s - %(title)s [%(id)s].%(ext)s"

This seems to work even when regedit/group policy changes to allow paths over 260 characters don't.

tyablix avatar Dec 22 '20 06:12 tyablix

@tyablix That is a nice workaround, but be carefull when using it. You might end up creating files that is invisible to windows explorer

pukkandan avatar Dec 23 '20 19:12 pukkandan

@pukkandan That's good to know. I've used it a little on the rare occasion a title is too long and I did notice explorer won't really let you do much with the file once it is created. Third party file copying software like Teracopy seems to have no issues in those cases though

tyablix avatar Dec 24 '20 05:12 tyablix