[extractor/common] Fix dumping requests with long file abspath on Windows
authorSergey M․ <dstftw@gmail.com>
Tue, 14 Oct 2014 14:43:48 +0000 (21:43 +0700)
committerSergey M <dstftw@gmail.com>
Tue, 14 Oct 2014 14:43:48 +0000 (21:43 +0700)
youtube_dl/extractor/common.py

index 450c7dfd69d0000c810f18ef35741aae05221c40..e8366f7f91c663f1f7bdf70db0588016f49da3de 100644 (file)
@@ -281,6 +281,12 @@ class InfoExtractor(object):
             raw_filename = basen + '.dump'
             filename = sanitize_filename(raw_filename, restricted=True)
             self.to_screen('Saving request to ' + filename)
+            # Working around MAX_PATH limitation on Windows (see
+            # http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx)
+            if os.name == 'nt':
+                absfilepath = os.path.abspath(filename)
+                if len(absfilepath) > 259:
+                    filename = '\\\\?\\' + absfilepath
             with open(filename, 'wb') as outf:
                 outf.write(webpage_bytes)