Przeglądaj źródła

[downloader/fragment] Restart inconsistent incomplete fragment downloads (#13731)

Sergey M․ 8 lat temu
rodzic
commit
e7c3e33456
1 zmienionych plików z 7 dodań i 2 usunięć
  1. 7 2
      youtube_dl/downloader/fragment.py

+ 7 - 2
youtube_dl/downloader/fragment.py

@@ -151,10 +151,15 @@ class FragmentFD(FileDownloader):
         if self.__do_ytdl_file(ctx):
             if os.path.isfile(encodeFilename(self.ytdl_filename(ctx['filename']))):
                 self._read_ytdl_file(ctx)
+                if ctx['fragment_index'] > 0 and resume_len == 0:
+                    self.report_error(
+                        'Inconsistent state of incomplete fragment download. '
+                        'Restarting from the beginning...')
+                    ctx['fragment_index'] = resume_len = 0
+                    self._write_ytdl_file(ctx)
             else:
                 self._write_ytdl_file(ctx)
-            if ctx['fragment_index'] > 0:
-                assert resume_len > 0
+                assert ctx['fragment_index'] == 0
 
         dest_stream, tmpfilename = sanitize_open(tmpfilename, open_mode)