From 267fb3ed70c7cea31e4cbff072d46693c6648d50 Mon Sep 17 00:00:00 2001 From: wkevin Date: Fri, 21 Jun 2019 16:05:49 +0800 Subject: [PATCH] limit filename with linux namemax length --- youtube_dl/utils.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py index a1f586b80..6e14102e9 100644 --- a/youtube_dl/utils.py +++ b/youtube_dl/utils.py @@ -522,8 +522,12 @@ def sanitize_filename(s, restricted=False, is_id=False): def sanitize_path(s): - """Sanitizes and normalizes path on Windows""" if sys.platform != 'win32': + nm = os.statvfs("/").f_namemax + (f, e) = os.path.splitext(s) + while(sys.getsizeof(f) > (nm - sys.getsizeof(e))): + f = f[0:-1] + s = f + e return s drive_or_unc, _ = os.path.splitdrive(s) if sys.version_info < (2, 7) and not drive_or_unc: