Explorar o código

[downloader/external] Properly handle live stream downloading cancellation (closes #8932)

Sergey M․ %!s(int64=8) %!d(string=hai) anos
pai
achega
e7db6759e4
Modificáronse 1 ficheiros con 11 adicións e 1 borrados
  1. 11 1
      youtube_dl/downloader/external.py

+ 11 - 1
youtube_dl/downloader/external.py

@@ -29,7 +29,17 @@ class ExternalFD(FileDownloader):
         self.report_destination(filename)
         tmpfilename = self.temp_name(filename)
 
-        retval = self._call_downloader(tmpfilename, info_dict)
+        try:
+            retval = self._call_downloader(tmpfilename, info_dict)
+        except KeyboardInterrupt:
+            if not info_dict.get('is_live'):
+                raise
+            # Live stream downloading cancellation should be considered as
+            # correct and expected termination thus all postprocessing
+            # should take place
+            retval = 0
+            self.to_screen('[%s] Interrupted by user' % self.get_basename())
+
         if retval == 0:
             fsize = os.path.getsize(encodeFilename(tmpfilename))
             self.to_screen('\r[%s] Downloaded %s bytes' % (self.get_basename(), fsize))