diff options
author | Sergey M․ <dstftw@gmail.com> | 2018-03-24 16:29:03 +0700 |
---|---|---|
committer | Sergey M․ <dstftw@gmail.com> | 2018-03-24 16:35:21 +0700 |
commit | f0298f653e2199d6e4488882e40eea8e31140d7e (patch) | |
tree | 1095af04e06d4c1e7aab796c51ae16ea907ecacb | |
parent | 2ea212628e0ffc0d66858817841643c4579c5d9d (diff) |
[downloader/external] Simplify finished progress hook reporting and add elapsed time (closes #10876)
-rw-r--r-- | youtube_dl/downloader/external.py | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/youtube_dl/downloader/external.py b/youtube_dl/downloader/external.py index 48c255ddc..958d00aac 100644 --- a/youtube_dl/downloader/external.py +++ b/youtube_dl/downloader/external.py @@ -1,9 +1,10 @@ from __future__ import unicode_literals import os.path +import re import subprocess import sys -import re +import time from .common import FileDownloader from ..compat import ( @@ -30,6 +31,7 @@ class ExternalFD(FileDownloader): tmpfilename = self.temp_name(filename) try: + started = time.time() retval = self._call_downloader(tmpfilename, info_dict) except KeyboardInterrupt: if not info_dict.get('is_live'): @@ -41,21 +43,20 @@ class ExternalFD(FileDownloader): self.to_screen('[%s] Interrupted by user' % self.get_basename()) if retval == 0: - if filename == '-': - self._hook_progress({ - 'filename': filename, - 'status': 'finished', - }) - else: + status = { + 'filename': filename, + 'status': 'finished', + 'elapsed': time.time() - started, + } + if filename != '-': fsize = os.path.getsize(encodeFilename(tmpfilename)) self.to_screen('\r[%s] Downloaded %s bytes' % (self.get_basename(), fsize)) self.try_rename(tmpfilename, filename) - self._hook_progress({ + status.update({ 'downloaded_bytes': fsize, 'total_bytes': fsize, - 'filename': filename, - 'status': 'finished', }) + self._hook_progress(status) return True else: self.to_stderr('\n') |