classFileDownloader(object): def__init__(self, ydl, params): """Create a FileDownloader object with the given options.""" self.ydl = ydl self._progress_hooks = [] self.params = params self.add_progress_hook(self.report_progress)
def_hook_progress(self, status): for ph in self._progress_hooks: ph(status)
defadd_progress_hook(self, ph): # See YoutubeDl.py (search for progress_hooks) for a description of # this interface self._progress_hooks.append(ph)
defreport_progress(self, s): if s['status'] == 'finished': # logic return
if self.params.get('noprogress'): return
if s['status'] != 'downloading': # logic return
在 logger 的处理上, 也是直接看是否有自定义的 logger,如果有就使用。
1 2 3 4
if self.params.get('logger') is not None: self.params['logger'].warning(message) self.params['logger'].info(message) self.params['logger'].debug(message)