mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-06 04:57:05 +01:00
[downloader/external] Simplify finished progress hook reporting and add elapsed time (closes #10876)
This commit is contained in:
parent
2ea212628e
commit
f0298f653e
@ -1,9 +1,10 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import os.path
|
import os.path
|
||||||
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import re
|
import time
|
||||||
|
|
||||||
from .common import FileDownloader
|
from .common import FileDownloader
|
||||||
from ..compat import (
|
from ..compat import (
|
||||||
@ -30,6 +31,7 @@ def real_download(self, filename, info_dict):
|
|||||||
tmpfilename = self.temp_name(filename)
|
tmpfilename = self.temp_name(filename)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
started = time.time()
|
||||||
retval = self._call_downloader(tmpfilename, info_dict)
|
retval = self._call_downloader(tmpfilename, info_dict)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
if not info_dict.get('is_live'):
|
if not info_dict.get('is_live'):
|
||||||
@ -41,21 +43,20 @@ def real_download(self, filename, info_dict):
|
|||||||
self.to_screen('[%s] Interrupted by user' % self.get_basename())
|
self.to_screen('[%s] Interrupted by user' % self.get_basename())
|
||||||
|
|
||||||
if retval == 0:
|
if retval == 0:
|
||||||
if filename == '-':
|
status = {
|
||||||
self._hook_progress({
|
|
||||||
'filename': filename,
|
'filename': filename,
|
||||||
'status': 'finished',
|
'status': 'finished',
|
||||||
})
|
'elapsed': time.time() - started,
|
||||||
else:
|
}
|
||||||
|
if filename != '-':
|
||||||
fsize = os.path.getsize(encodeFilename(tmpfilename))
|
fsize = os.path.getsize(encodeFilename(tmpfilename))
|
||||||
self.to_screen('\r[%s] Downloaded %s bytes' % (self.get_basename(), fsize))
|
self.to_screen('\r[%s] Downloaded %s bytes' % (self.get_basename(), fsize))
|
||||||
self.try_rename(tmpfilename, filename)
|
self.try_rename(tmpfilename, filename)
|
||||||
self._hook_progress({
|
status.update({
|
||||||
'downloaded_bytes': fsize,
|
'downloaded_bytes': fsize,
|
||||||
'total_bytes': fsize,
|
'total_bytes': fsize,
|
||||||
'filename': filename,
|
|
||||||
'status': 'finished',
|
|
||||||
})
|
})
|
||||||
|
self._hook_progress(status)
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
self.to_stderr('\n')
|
self.to_stderr('\n')
|
||||||
|
Loading…
Reference in New Issue
Block a user