]> jfr.im git - yt-dlp.git/blame - yt_dlp/downloader/fragment.py
Standardize retry mechanism (#1649)
[yt-dlp.git] / yt_dlp / downloader / fragment.py
CommitLineData
1d485a1a 1import concurrent.futures
19a03940 2import contextlib
adbc4ec4
THD
3import http.client
4import json
5import math
95d8f7ea 6import os
ac668111 7import struct
95d8f7ea 8import time
ac668111 9import urllib.error
95d8f7ea
S
10
11from .common import FileDownloader
12from .http import HttpFD
1d3586d0 13from ..aes import aes_cbc_decrypt_bytes, unpad_pkcs7
ac668111 14from ..compat import compat_os_name
95d8f7ea 15from ..utils import (
4c7853de 16 DownloadError,
be5c1ae8 17 RetryManager,
95d8f7ea 18 encodeFilename,
69035555 19 sanitized_Request,
a539f065 20 traverse_obj,
95d8f7ea
S
21)
22
23
24class HttpQuietDownloader(HttpFD):
25 def to_screen(self, *args, **kargs):
26 pass
27
998a3cae 28 to_console_title = to_screen
1d485a1a 29
95d8f7ea
S
30
31class FragmentFD(FileDownloader):
32 """
33 A base file downloader class for fragmented media (e.g. f4m/m3u8 manifests).
16a8b798
S
34
35 Available options:
36
9603b660
S
37 fragment_retries: Number of times to retry a fragment for HTTP error (DASH
38 and hlsnative only)
39 skip_unavailable_fragments:
40 Skip unavailable fragments (DASH and hlsnative only)
0eee52f3
S
41 keep_fragments: Keep downloaded fragments on disk after downloading is
42 finished
59a7a13e 43 concurrent_fragment_downloads: The number of threads to use for native hls and dash downloads
e8e73840 44 _no_ytdl_file: Don't use .ytdl file
290f64db 45
7a5c1cfe 46 For each incomplete fragment download yt-dlp keeps on disk a special
290f64db 47 bookkeeping file with download state and metadata (in future such files will
7a5c1cfe 48 be used for any incomplete download handled by yt-dlp). This file is
290f64db
S
49 used to properly handle resuming, check download file consistency and detect
50 potential errors. The file has a .ytdl extension and represents a standard
51 JSON file of the following format:
52
53 extractor:
54 Dictionary of extractor related data. TBD.
55
56 downloader:
57 Dictionary of downloader related data. May contain following data:
58 current_fragment:
59 Dictionary with current (being downloaded) fragment data:
85f6de25 60 index: 0-based index of current fragment among all fragments
290f64db
S
61 fragment_count:
62 Total count of fragments
50534b71 63
85f6de25 64 This feature is experimental and file format may change in future.
95d8f7ea
S
65 """
66
75a24854 67 def report_retry_fragment(self, err, frag_index, count, retries):
be5c1ae8 68 self.deprecation_warning(
69 'yt_dlp.downloader.FragmentFD.report_retry_fragment is deprecated. Use yt_dlp.downloader.FileDownloader.report_retry instead')
70 return self.report_retry(err, count, retries, frag_index)
721f26b8 71
b4b855eb 72 def report_skip_fragment(self, frag_index, err=None):
73 err = f' {err};' if err else ''
74 self.to_screen(f'[download]{err} Skipping fragment {frag_index:d} ...')
9603b660 75
69035555
S
76 def _prepare_url(self, info_dict, url):
77 headers = info_dict.get('http_headers')
78 return sanitized_Request(url, None, headers) if headers else url
79
3ba7740d 80 def _prepare_and_start_frag_download(self, ctx, info_dict):
95d8f7ea 81 self._prepare_frag_download(ctx)
3ba7740d 82 self._start_frag_download(ctx, info_dict)
95d8f7ea 83
e8e73840 84 def __do_ytdl_file(self, ctx):
adbc4ec4 85 return ctx['live'] is not True and ctx['tmpfilename'] != '-' and not self.params.get('_no_ytdl_file')
adb4b03c 86
d3f0687c 87 def _read_ytdl_file(self, ctx):
500a86a5 88 assert 'ytdl_corrupt' not in ctx
205a0654 89 stream, _ = self.sanitize_open(self.ytdl_filename(ctx['filename']), 'r')
500a86a5 90 try:
4d49884c
F
91 ytdl_data = json.loads(stream.read())
92 ctx['fragment_index'] = ytdl_data['downloader']['current_fragment']['index']
93 if 'extra_state' in ytdl_data['downloader']:
94 ctx['extra_state'] = ytdl_data['downloader']['extra_state']
500a86a5
S
95 except Exception:
96 ctx['ytdl_corrupt'] = True
97 finally:
98 stream.close()
d3f0687c
S
99
100 def _write_ytdl_file(self, ctx):
205a0654 101 frag_index_stream, _ = self.sanitize_open(self.ytdl_filename(ctx['filename']), 'w')
ad3dc496 102 try:
103 downloader = {
104 'current_fragment': {
105 'index': ctx['fragment_index'],
106 },
107 }
108 if 'extra_state' in ctx:
109 downloader['extra_state'] = ctx['extra_state']
110 if ctx.get('fragment_count') is not None:
111 downloader['fragment_count'] = ctx['fragment_count']
112 frag_index_stream.write(json.dumps({'downloader': downloader}))
113 finally:
114 frag_index_stream.close()
d3f0687c 115
273762c8 116 def _download_fragment(self, ctx, frag_url, info_dict, headers=None, request_data=None):
d3f0687c 117 fragment_filename = '%s-Frag%d' % (ctx['tmpfilename'], ctx['fragment_index'])
38d70284 118 fragment_info_dict = {
75a24854
RA
119 'url': frag_url,
120 'http_headers': headers or info_dict.get('http_headers'),
273762c8 121 'request_data': request_data,
bd50a52b 122 'ctx_id': ctx.get('ctx_id'),
38d70284 123 }
3fe75fdc 124 success, _ = ctx['dl'].download(fragment_filename, fragment_info_dict)
75a24854 125 if not success:
d71fd412 126 return False
38d70284 127 if fragment_info_dict.get('filetime'):
128 ctx['fragment_filetime'] = fragment_info_dict.get('filetime')
4c7853de 129 ctx['fragment_filename_sanitized'] = fragment_filename
d71fd412 130 return True
4c7853de 131
132 def _read_fragment(self, ctx):
e06bd880 133 if not ctx.get('fragment_filename_sanitized'):
134 return None
d71fd412
LNO
135 try:
136 down, frag_sanitized = self.sanitize_open(ctx['fragment_filename_sanitized'], 'rb')
137 except FileNotFoundError:
138 if ctx.get('live'):
139 return None
140 raise
d3f0687c
S
141 ctx['fragment_filename_sanitized'] = frag_sanitized
142 frag_content = down.read()
75a24854 143 down.close()
4c7853de 144 return frag_content
75a24854
RA
145
146 def _append_fragment(self, ctx, frag_content):
d3f0687c
S
147 try:
148 ctx['dest_stream'].write(frag_content)
593f2f79 149 ctx['dest_stream'].flush()
d3f0687c 150 finally:
adb4b03c 151 if self.__do_ytdl_file(ctx):
d3f0687c 152 self._write_ytdl_file(ctx)
0eee52f3 153 if not self.params.get('keep_fragments', False):
45806d44 154 self.try_remove(encodeFilename(ctx['fragment_filename_sanitized']))
d3f0687c 155 del ctx['fragment_filename_sanitized']
75a24854 156
95d8f7ea 157 def _prepare_frag_download(self, ctx):
5fa1702c
S
158 if 'live' not in ctx:
159 ctx['live'] = False
5efaf43c
S
160 if not ctx['live']:
161 total_frags_str = '%d' % ctx['total_frags']
162 ad_frags = ctx.get('ad_frags', 0)
163 if ad_frags:
164 total_frags_str += ' (not including %d ad)' % ad_frags
165 else:
166 total_frags_str = 'unknown (live)'
86e5f3ed 167 self.to_screen(f'[{self.FD_NAME}] Total fragments: {total_frags_str}')
95d8f7ea 168 self.report_destination(ctx['filename'])
666c36d5 169 dl = HttpQuietDownloader(self.ydl, {
170 **self.params,
171 'noprogress': True,
172 'test': False,
173 })
95d8f7ea 174 tmpfilename = self.temp_name(ctx['filename'])
75a24854
RA
175 open_mode = 'wb'
176 resume_len = 0
d3f0687c 177
75a24854
RA
178 # Establish possible resume length
179 if os.path.isfile(encodeFilename(tmpfilename)):
180 open_mode = 'ab'
181 resume_len = os.path.getsize(encodeFilename(tmpfilename))
d3f0687c 182
adb4b03c
S
183 # Should be initialized before ytdl file check
184 ctx.update({
185 'tmpfilename': tmpfilename,
186 'fragment_index': 0,
187 })
d3f0687c 188
adb4b03c
S
189 if self.__do_ytdl_file(ctx):
190 if os.path.isfile(encodeFilename(self.ytdl_filename(ctx['filename']))):
191 self._read_ytdl_file(ctx)
500a86a5
S
192 is_corrupt = ctx.get('ytdl_corrupt') is True
193 is_inconsistent = ctx['fragment_index'] > 0 and resume_len == 0
194 if is_corrupt or is_inconsistent:
195 message = (
196 '.ytdl file is corrupt' if is_corrupt else
197 'Inconsistent state of incomplete fragment download')
6f3b4a98 198 self.report_warning(
5ef7d9bd 199 '%s. Restarting from the beginning ...' % message)
e7c3e334 200 ctx['fragment_index'] = resume_len = 0
500a86a5
S
201 if 'ytdl_corrupt' in ctx:
202 del ctx['ytdl_corrupt']
e7c3e334 203 self._write_ytdl_file(ctx)
adb4b03c
S
204 else:
205 self._write_ytdl_file(ctx)
e7c3e334 206 assert ctx['fragment_index'] == 0
d3f0687c 207
205a0654 208 dest_stream, tmpfilename = self.sanitize_open(tmpfilename, open_mode)
75a24854 209
95d8f7ea
S
210 ctx.update({
211 'dl': dl,
212 'dest_stream': dest_stream,
213 'tmpfilename': tmpfilename,
75a24854
RA
214 # Total complete fragments downloaded so far in bytes
215 'complete_frags_downloaded_bytes': resume_len,
95d8f7ea
S
216 })
217
3ba7740d 218 def _start_frag_download(self, ctx, info_dict):
3bce4ff7 219 resume_len = ctx['complete_frags_downloaded_bytes']
95d8f7ea 220 total_frags = ctx['total_frags']
bd50a52b 221 ctx_id = ctx.get('ctx_id')
95d8f7ea
S
222 # This dict stores the download progress, it's updated by the progress
223 # hook
224 state = {
225 'status': 'downloading',
3bce4ff7 226 'downloaded_bytes': resume_len,
3e0304fe
RA
227 'fragment_index': ctx['fragment_index'],
228 'fragment_count': total_frags,
95d8f7ea
S
229 'filename': ctx['filename'],
230 'tmpfilename': ctx['tmpfilename'],
b83b782d
S
231 }
232
233 start = time.time()
234 ctx.update({
235 'started': start,
bd93fd5d 236 'fragment_started': start,
709185a2
S
237 # Amount of fragment's bytes downloaded by the time of the previous
238 # frag progress hook invocation
b83b782d
S
239 'prev_frag_downloaded_bytes': 0,
240 })
95d8f7ea
S
241
242 def frag_progress_hook(s):
243 if s['status'] not in ('downloading', 'finished'):
244 return
245
36195c44
M
246 if not total_frags and ctx.get('fragment_count'):
247 state['fragment_count'] = ctx['fragment_count']
248
bd50a52b
THD
249 if ctx_id is not None and s.get('ctx_id') != ctx_id:
250 return
251
252 state['max_progress'] = ctx.get('max_progress')
253 state['progress_idx'] = ctx.get('progress_idx')
254
5fa1702c 255 time_now = time.time()
2c2f1efd 256 state['elapsed'] = time_now - start
3c91e416 257 frag_total_bytes = s.get('total_bytes') or 0
3ba7740d 258 s['fragment_info_dict'] = s.pop('info_dict', {})
5fa1702c
S
259 if not ctx['live']:
260 estimated_size = (
3089bc74
S
261 (ctx['complete_frags_downloaded_bytes'] + frag_total_bytes)
262 / (state['fragment_index'] + 1) * total_frags)
5fa1702c 263 state['total_bytes_estimate'] = estimated_size
95d8f7ea 264
709185a2 265 if s['status'] == 'finished':
3e0304fe
RA
266 state['fragment_index'] += 1
267 ctx['fragment_index'] = state['fragment_index']
b83b782d
S
268 state['downloaded_bytes'] += frag_total_bytes - ctx['prev_frag_downloaded_bytes']
269 ctx['complete_frags_downloaded_bytes'] = state['downloaded_bytes']
bd93fd5d 270 ctx['speed'] = state['speed'] = self.calc_speed(
271 ctx['fragment_started'], time_now, frag_total_bytes)
272 ctx['fragment_started'] = time.time()
b83b782d 273 ctx['prev_frag_downloaded_bytes'] = 0
709185a2
S
274 else:
275 frag_downloaded_bytes = s['downloaded_bytes']
b83b782d 276 state['downloaded_bytes'] += frag_downloaded_bytes - ctx['prev_frag_downloaded_bytes']
5fa1702c
S
277 if not ctx['live']:
278 state['eta'] = self.calc_eta(
3bce4ff7 279 start, time_now, estimated_size - resume_len,
280 state['downloaded_bytes'] - resume_len)
bd93fd5d 281 ctx['speed'] = state['speed'] = self.calc_speed(
282 ctx['fragment_started'], time_now, frag_downloaded_bytes)
b83b782d 283 ctx['prev_frag_downloaded_bytes'] = frag_downloaded_bytes
3ba7740d 284 self._hook_progress(state, info_dict)
95d8f7ea
S
285
286 ctx['dl'].add_progress_hook(frag_progress_hook)
287
288 return start
289
3ba7740d 290 def _finish_frag_download(self, ctx, info_dict):
95d8f7ea 291 ctx['dest_stream'].close()
adb4b03c
S
292 if self.__do_ytdl_file(ctx):
293 ytdl_filename = encodeFilename(self.ytdl_filename(ctx['filename']))
294 if os.path.isfile(ytdl_filename):
45806d44 295 self.try_remove(ytdl_filename)
95d8f7ea 296 elapsed = time.time() - ctx['started']
0ff2c1ec
S
297
298 if ctx['tmpfilename'] == '-':
299 downloaded_bytes = ctx['complete_frags_downloaded_bytes']
300 else:
301 self.try_rename(ctx['tmpfilename'], ctx['filename'])
38d70284 302 if self.params.get('updatetime', True):
303 filetime = ctx.get('fragment_filetime')
304 if filetime:
19a03940 305 with contextlib.suppress(Exception):
38d70284 306 os.utime(ctx['filename'], (time.time(), filetime))
0ff2c1ec 307 downloaded_bytes = os.path.getsize(encodeFilename(ctx['filename']))
95d8f7ea
S
308
309 self._hook_progress({
0ff2c1ec
S
310 'downloaded_bytes': downloaded_bytes,
311 'total_bytes': downloaded_bytes,
95d8f7ea
S
312 'filename': ctx['filename'],
313 'status': 'finished',
314 'elapsed': elapsed,
bd50a52b
THD
315 'ctx_id': ctx.get('ctx_id'),
316 'max_progress': ctx.get('max_progress'),
317 'progress_idx': ctx.get('progress_idx'),
3ba7740d 318 }, info_dict)
5219cb3e 319
320 def _prepare_external_frag_download(self, ctx):
321 if 'live' not in ctx:
322 ctx['live'] = False
323 if not ctx['live']:
324 total_frags_str = '%d' % ctx['total_frags']
325 ad_frags = ctx.get('ad_frags', 0)
326 if ad_frags:
327 total_frags_str += ' (not including %d ad)' % ad_frags
328 else:
329 total_frags_str = 'unknown (live)'
86e5f3ed 330 self.to_screen(f'[{self.FD_NAME}] Total fragments: {total_frags_str}')
5219cb3e 331
332 tmpfilename = self.temp_name(ctx['filename'])
333
334 # Should be initialized before ytdl file check
335 ctx.update({
336 'tmpfilename': tmpfilename,
337 'fragment_index': 0,
338 })
4c7853de 339
1009f67c 340 def decrypter(self, info_dict):
341 _key_cache = {}
342
343 def _get_key(url):
344 if url not in _key_cache:
345 _key_cache[url] = self.ydl.urlopen(self._prepare_url(info_dict, url)).read()
346 return _key_cache[url]
347
348 def decrypt_fragment(fragment, frag_content):
be5c1ae8 349 if frag_content is None:
350 return
1009f67c 351 decrypt_info = fragment.get('decrypt_info')
352 if not decrypt_info or decrypt_info['METHOD'] != 'AES-128':
353 return frag_content
ac668111 354 iv = decrypt_info.get('IV') or struct.pack('>8xq', fragment['media_sequence'])
1009f67c 355 decrypt_info['KEY'] = decrypt_info.get('KEY') or _get_key(info_dict.get('_decryption_key_url') or decrypt_info['URI'])
356 # Don't decrypt the content in tests since the data is explicitly truncated and it's not to a valid block
357 # size (see https://github.com/ytdl-org/youtube-dl/pull/27660). Tests only care that the correct data downloaded,
358 # not what it decrypts to.
359 if self.params.get('test', False):
360 return frag_content
1d3586d0 361 return unpad_pkcs7(aes_cbc_decrypt_bytes(frag_content, decrypt_info['KEY'], iv))
1009f67c 362
363 return decrypt_fragment
364
bd50a52b
THD
365 def download_and_append_fragments_multiple(self, *args, pack_func=None, finish_func=None):
366 '''
367 @params (ctx1, fragments1, info_dict1), (ctx2, fragments2, info_dict2), ...
368 all args must be either tuple or list
369 '''
adbc4ec4 370 interrupt_trigger = [True]
bd50a52b
THD
371 max_progress = len(args)
372 if max_progress == 1:
373 return self.download_and_append_fragments(*args[0], pack_func=pack_func, finish_func=finish_func)
adbc4ec4 374 max_workers = self.params.get('concurrent_fragment_downloads', 1)
49a57e70 375 if max_progress > 1:
376 self._prepare_multiline_status(max_progress)
a539f065 377 is_live = any(traverse_obj(args, (..., 2, 'is_live'), default=[]))
bd50a52b
THD
378
379 def thread_func(idx, ctx, fragments, info_dict, tpe):
380 ctx['max_progress'] = max_progress
381 ctx['progress_idx'] = idx
adbc4ec4
THD
382 return self.download_and_append_fragments(
383 ctx, fragments, info_dict, pack_func=pack_func, finish_func=finish_func,
384 tpe=tpe, interrupt_trigger=interrupt_trigger)
bd50a52b
THD
385
386 class FTPE(concurrent.futures.ThreadPoolExecutor):
387 # has to stop this or it's going to wait on the worker thread itself
388 def __exit__(self, exc_type, exc_val, exc_tb):
389 pass
390
adbc4ec4 391 if compat_os_name == 'nt':
a44ca5a4 392 def future_result(future):
a539f065
LNO
393 while True:
394 try:
395 return future.result(0.1)
396 except KeyboardInterrupt:
397 raise
398 except concurrent.futures.TimeoutError:
399 continue
400 else:
a44ca5a4 401 def future_result(future):
a539f065
LNO
402 return future.result()
403
f0734e11
L
404 def interrupt_trigger_iter(fg):
405 for f in fg:
406 if not interrupt_trigger[0]:
407 break
408 yield f
409
a539f065 410 spins = []
bd50a52b 411 for idx, (ctx, fragments, info_dict) in enumerate(args):
adbc4ec4 412 tpe = FTPE(math.ceil(max_workers / max_progress))
f0734e11 413 job = tpe.submit(thread_func, idx, ctx, interrupt_trigger_iter(fragments), info_dict, tpe)
bd50a52b
THD
414 spins.append((tpe, job))
415
416 result = True
417 for tpe, job in spins:
418 try:
a44ca5a4 419 result = result and future_result(job)
adbc4ec4
THD
420 except KeyboardInterrupt:
421 interrupt_trigger[0] = False
bd50a52b
THD
422 finally:
423 tpe.shutdown(wait=True)
a539f065 424 if not interrupt_trigger[0] and not is_live:
adbc4ec4 425 raise KeyboardInterrupt()
a539f065
LNO
426 # we expect the user wants to stop and DO WANT the preceding postprocessors to run;
427 # so returning a intermediate result here instead of KeyboardInterrupt on live
819e0531 428 return result
bd50a52b 429
adbc4ec4
THD
430 def download_and_append_fragments(
431 self, ctx, fragments, info_dict, *, pack_func=None, finish_func=None,
432 tpe=None, interrupt_trigger=None):
433 if not interrupt_trigger:
434 interrupt_trigger = (True, )
435
adbc4ec4
THD
436 is_fatal = (
437 ((lambda _: False) if info_dict.get('is_live') else (lambda idx: idx == 0))
438 if self.params.get('skip_unavailable_fragments', True) else (lambda _: True))
439
4c7853de 440 if not pack_func:
441 pack_func = lambda frag_content, _: frag_content
442
443 def download_fragment(fragment, ctx):
a539f065 444 if not interrupt_trigger[0]:
d71fd412 445 return
a539f065 446
4c7853de 447 frag_index = ctx['fragment_index'] = fragment['frag_index']
185bf310 448 ctx['last_error'] = None
d9d8b857 449 headers = info_dict.get('http_headers', {}).copy()
4c7853de 450 byte_range = fragment.get('byte_range')
451 if byte_range:
452 headers['Range'] = 'bytes=%d-%d' % (byte_range['start'], byte_range['end'] - 1)
453
454 # Never skip the first fragment
be5c1ae8 455 fatal = is_fatal(fragment.get('index') or (frag_index - 1))
456
457 def error_callback(err, count, retries):
458 if fatal and count > retries:
459 ctx['dest_stream'].close()
460 self.report_retry(err, count, retries, frag_index, fatal)
461 ctx['last_error'] = err
462
463 for retry in RetryManager(self.params.get('fragment_retries'), error_callback):
4c7853de 464 try:
36195c44 465 ctx['fragment_count'] = fragment.get('fragment_count')
be5c1ae8 466 if not self._download_fragment(ctx, fragment['url'], info_dict, headers):
467 return
ac668111 468 except (urllib.error.HTTPError, http.client.IncompleteRead) as err:
be5c1ae8 469 retry.error = err
470 continue
471 except DownloadError: # has own retry settings
472 if fatal:
473 raise
4c7853de 474
4c7853de 475 def append_fragment(frag_content, frag_index, ctx):
a44ca5a4 476 if frag_content:
477 self._append_fragment(ctx, pack_func(frag_content, frag_index))
478 elif not is_fatal(frag_index - 1):
479 self.report_skip_fragment(frag_index, 'fragment not found')
480 else:
481 ctx['dest_stream'].close()
482 self.report_error(f'fragment {frag_index} not found, unable to continue')
483 return False
4c7853de 484 return True
485
1009f67c 486 decrypt_fragment = self.decrypter(info_dict)
487
adbc4ec4
THD
488 max_workers = math.ceil(
489 self.params.get('concurrent_fragment_downloads', 1) / ctx.get('max_progress', 1))
1d485a1a 490 if max_workers > 1:
4c7853de 491 def _download_fragment(fragment):
723d44b9 492 ctx_copy = ctx.copy()
d71fd412
LNO
493 download_fragment(fragment, ctx_copy)
494 return fragment, fragment['frag_index'], ctx_copy.get('fragment_filename_sanitized')
4c7853de 495
496 self.report_warning('The download speed shown is only of one thread. This is a known issue and patches are welcome')
bd50a52b 497 with tpe or concurrent.futures.ThreadPoolExecutor(max_workers) as pool:
1890fc63 498 try:
499 for fragment, frag_index, frag_filename in pool.map(_download_fragment, fragments):
500 ctx.update({
501 'fragment_filename_sanitized': frag_filename,
502 'fragment_index': frag_index,
503 })
504 if not append_fragment(decrypt_fragment(fragment, self._read_fragment(ctx)), frag_index, ctx):
505 return False
506 except KeyboardInterrupt:
507 self._finish_multiline_status()
508 self.report_error(
509 'Interrupted by user. Waiting for all threads to shutdown...', is_error=False, tb=False)
510 pool.shutdown(wait=False)
511 raise
4c7853de 512 else:
513 for fragment in fragments:
adbc4ec4
THD
514 if not interrupt_trigger[0]:
515 break
c854208c
LNO
516 try:
517 download_fragment(fragment, ctx)
19a03940 518 result = append_fragment(
519 decrypt_fragment(fragment, self._read_fragment(ctx)), fragment['frag_index'], ctx)
c854208c
LNO
520 except KeyboardInterrupt:
521 if info_dict.get('is_live'):
522 break
523 raise
4c7853de 524 if not result:
525 return False
526
25a3f4f5
F
527 if finish_func is not None:
528 ctx['dest_stream'].write(finish_func())
529 ctx['dest_stream'].flush()
3ba7740d 530 self._finish_frag_download(ctx, info_dict)
8e897ed2 531 return True