Simplify status reporting (#1918)

This commit is contained in:
Philipp Hagemeister 2013-12-08 05:49:35 +01:00
parent 42d3bf844a
commit a213880aaf

View File

@ -204,11 +204,19 @@ def report_destination(self, filename):
"""Report destination filename.""" """Report destination filename."""
self.to_screen(u'[download] Destination: ' + filename) self.to_screen(u'[download] Destination: ' + filename)
def _report_progress_status(self, msg, is_last_line=False):
clear_line = (u'\x1b[K' if sys.stderr.isatty() and os.name != 'nt' else u'')
if self.params.get('progress_with_newline', False):
self.to_screen(u'[download] ' + msg)
else:
self.to_screen(u'\r%s[download] %s' % (clear_line, msg),
skip_eol=not is_last_line)
self.to_console_title(u'youtube-dl ' + msg)
def report_progress(self, percent, data_len_str, speed, eta): def report_progress(self, percent, data_len_str, speed, eta):
"""Report download progress.""" """Report download progress."""
if self.params.get('noprogress', False): if self.params.get('noprogress', False):
return return
clear_line = (u'\x1b[K' if sys.stderr.isatty() and os.name != 'nt' else u'')
if eta is not None: if eta is not None:
eta_str = self.format_eta(eta) eta_str = self.format_eta(eta)
else: else:
@ -218,14 +226,20 @@ def report_progress(self, percent, data_len_str, speed, eta):
else: else:
percent_str = 'Unknown %' percent_str = 'Unknown %'
speed_str = self.format_speed(speed) speed_str = self.format_speed(speed)
if self.params.get('progress_with_newline', False):
self.to_screen(u'[download] %s of %s at %s ETA %s' % msg = (u'%s of %s at %s ETA %s' %
(percent_str, data_len_str, speed_str, eta_str)) (percent_str, data_len_str, speed_str, eta_str))
self._report_progress_status(msg)
def report_finish(self, data_len_str, tot_time):
"""Report download finished."""
if self.params.get('noprogress', False):
self.to_screen(u'[download] Download completed')
else: else:
self.to_screen(u'\r%s[download] %s of %s at %s ETA %s' % self._report_progress_status(
(clear_line, percent_str, data_len_str, speed_str, eta_str), skip_eol=True) (u'100%% of %s in %s' %
self.to_console_title(u'youtube-dl - %s of %s at %s ETA %s' % (data_len_str, self.format_seconds(tot_time))),
(percent_str.strip(), data_len_str.strip(), speed_str.strip(), eta_str.strip())) is_last_line=True)
def report_resuming_byte(self, resume_len): def report_resuming_byte(self, resume_len):
"""Report attempt to resume at given byte.""" """Report attempt to resume at given byte."""
@ -246,15 +260,6 @@ def report_unable_to_resume(self):
"""Report it was impossible to resume download.""" """Report it was impossible to resume download."""
self.to_screen(u'[download] Unable to resume') self.to_screen(u'[download] Unable to resume')
def report_finish(self, data_len_str, tot_time):
"""Report download finished."""
if self.params.get('noprogress', False):
self.to_screen(u'[download] Download completed')
else:
clear_line = (u'\x1b[K' if sys.stderr.isatty() and os.name != 'nt' else u'')
self.to_screen(u'\r%s[download] 100%% of %s in %s' %
(clear_line, data_len_str, self.format_seconds(tot_time)))
def _download_with_rtmpdump(self, filename, url, player_url, page_url, play_path, tc_url, live): def _download_with_rtmpdump(self, filename, url, player_url, page_url, play_path, tc_url, live):
def run_rtmpdump(args): def run_rtmpdump(args):
start = time.time() start = time.time()