progress, with a dictionary with the entries
* status: One of "downloading", "error", or "finished".
Check this first and ignore unknown values.
+ * info_dict: The extracted info_dict
If status is one of "downloading", or "finished", the
following properties may also be present:
from __future__ import division, unicode_literals
+import copy
import os
import re
import sys
'filename': filename,
'status': 'finished',
'total_bytes': os.path.getsize(encodeFilename(filename)),
- })
+ }, info_dict)
return True, False
if subtitle is False:
"""Real download process. Redefine in subclasses."""
raise NotImplementedError('This method must be implemented by subclasses')
- def _hook_progress(self, status):
+ def _hook_progress(self, status, info_dict):
+ if not self._progress_hooks:
+ return
+ info_dict = dict(info_dict)
+ for key in ('__original_infodict', '__postprocessors'):
+ info_dict.pop(key, None)
for ph in self._progress_hooks:
- ph(status)
+ ph({**status, 'info_dict': copy.deepcopy(info_dict)})
def add_progress_hook(self, ph):
# See YoutubeDl.py (search for progress_hooks) for a description of
if real_downloader:
self._prepare_external_frag_download(ctx)
else:
- self._prepare_and_start_frag_download(ctx)
+ self._prepare_and_start_frag_download(ctx, info_dict)
fragments_to_download = []
frag_index = 0
'downloaded_bytes': fsize,
'total_bytes': fsize,
})
- self._hook_progress(status)
+ self._hook_progress(status, info_dict)
return True
else:
self.to_stderr('\n')
base_url_parsed = compat_urllib_parse_urlparse(base_url)
- self._start_frag_download(ctx)
+ self._start_frag_download(ctx, info_dict)
frag_index = 0
while fragments_list:
msg = 'Missed %d fragments' % (fragments_list[0][1] - (frag_i + 1))
self.report_warning(msg)
- self._finish_frag_download(ctx)
+ self._finish_frag_download(ctx, info_dict)
return True
headers = info_dict.get('http_headers')
return sanitized_Request(url, None, headers) if headers else url
- def _prepare_and_start_frag_download(self, ctx):
+ def _prepare_and_start_frag_download(self, ctx, info_dict):
self._prepare_frag_download(ctx)
- self._start_frag_download(ctx)
+ self._start_frag_download(ctx, info_dict)
def __do_ytdl_file(self, ctx):
return not ctx['live'] and not ctx['tmpfilename'] == '-' and not self.params.get('_no_ytdl_file')
'complete_frags_downloaded_bytes': resume_len,
})
- def _start_frag_download(self, ctx):
+ def _start_frag_download(self, ctx, info_dict):
resume_len = ctx['complete_frags_downloaded_bytes']
total_frags = ctx['total_frags']
# This dict stores the download progress, it's updated by the progress
time_now = time.time()
state['elapsed'] = time_now - start
frag_total_bytes = s.get('total_bytes') or 0
+ s['fragment_info_dict'] = s.pop('info_dict', {})
if not ctx['live']:
estimated_size = (
(ctx['complete_frags_downloaded_bytes'] + frag_total_bytes)
state['speed'] = s.get('speed') or ctx.get('speed')
ctx['speed'] = state['speed']
ctx['prev_frag_downloaded_bytes'] = frag_downloaded_bytes
- self._hook_progress(state)
+ self._hook_progress(state, info_dict)
ctx['dl'].add_progress_hook(frag_progress_hook)
return start
- def _finish_frag_download(self, ctx):
+ def _finish_frag_download(self, ctx, info_dict):
ctx['dest_stream'].close()
if self.__do_ytdl_file(ctx):
ytdl_filename = encodeFilename(self.ytdl_filename(ctx['filename']))
'filename': ctx['filename'],
'status': 'finished',
'elapsed': elapsed,
- })
+ }, info_dict)
def _prepare_external_frag_download(self, ctx):
if 'live' not in ctx:
if not result:
return False
- self._finish_frag_download(ctx)
+ self._finish_frag_download(ctx, info_dict)
return True
if real_downloader:
self._prepare_external_frag_download(ctx)
else:
- self._prepare_and_start_frag_download(ctx)
+ self._prepare_and_start_frag_download(ctx, info_dict)
extra_state = ctx.setdefault('extra_state', {})
'status': 'finished',
'downloaded_bytes': ctx.resume_len,
'total_bytes': ctx.resume_len,
- })
+ }, info_dict)
raise SucceedDownload()
else:
# The length does not match, we start the download over
'eta': eta,
'speed': speed,
'elapsed': now - ctx.start_time,
- })
+ }, info_dict)
if data_len is not None and byte_counter == data_len:
break
'filename': ctx.filename,
'status': 'finished',
'elapsed': time.time() - ctx.start_time,
- })
+ }, info_dict)
return True
'total_frags': len(segments),
}
- self._prepare_and_start_frag_download(ctx)
+ self._prepare_and_start_frag_download(ctx, info_dict)
extra_state = ctx.setdefault('extra_state', {
'ism_track_written': False,
self.report_error('giving up after %s fragment retries' % fragment_retries)
return False
- self._finish_frag_download(ctx)
+ self._finish_frag_download(ctx, info_dict)
return True
'total_frags': len(fragments),
}
- self._prepare_and_start_frag_download(ctx)
+ self._prepare_and_start_frag_download(ctx, info_dict)
extra_state = ctx.setdefault('extra_state', {
'header_written': False,
ctx['dest_stream'].write(
b'--%b--\r\n\r\n' % frag_boundary.encode('us-ascii'))
- self._finish_frag_download(ctx)
+ self._finish_frag_download(ctx, info_dict)
return True
'eta': eta,
'elapsed': time_now - start,
'speed': speed,
- })
+ }, info_dict)
cursor_in_new_line = False
else:
# no percent for live streams
'status': 'downloading',
'elapsed': time_now - start,
'speed': speed,
- })
+ }, info_dict)
cursor_in_new_line = False
elif self.params.get('verbose', False):
if not cursor_in_new_line:
'filename': filename,
'status': 'finished',
'elapsed': time.time() - started,
- })
+ }, info_dict)
return True
else:
self.to_stderr('\n')
'total_bytes': fsize,
'filename': filename,
'status': 'finished',
- })
+ }, info_dict)
return True
else:
self.to_stderr('\n')
self.report_error('giving up after %s fragment retries' % fragment_retries)
return False, None, None, None
- self._prepare_and_start_frag_download(ctx)
+ self._prepare_and_start_frag_download(ctx, info_dict)
success, raw_fragment = dl_fragment(info_dict['url'])
if not success:
if test:
break
- self._finish_frag_download(ctx)
+ self._finish_frag_download(ctx, info_dict)
return True
@staticmethod