summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNirbheek Chauhan <nirbheek@centricular.com>2022-11-08 22:49:22 +0530
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>2022-11-18 19:39:12 +0000
commit56263fb189a77e0419e252da9fecda3752c7287f (patch)
treee9a8767e947524b7e43e3fc55cbe5a6363110941
parent721c96308e42f5d7b65eab776041efaad25abfb5 (diff)
cerbero: Speed up downloads on Windows drastically
Apparently Invoke-WebRequest updates the progress bar for every byte, which makes downloads happen orders of magnitude slower than necessary. So let's disable the progress bar. On my system, downloads that required minutes now happen instantly. This is now faster than the old urllib implementation too. Part-of: <https://gitlab.freedesktop.org/gstreamer/cerbero/-/merge_requests/1020>
-rw-r--r--cerbero/utils/shell.py15
1 files changed, 10 insertions, 5 deletions
diff --git a/cerbero/utils/shell.py b/cerbero/utils/shell.py
index 2c85b4f7..1e9260ad 100644
--- a/cerbero/utils/shell.py
+++ b/cerbero/utils/shell.py
@@ -387,27 +387,32 @@ async def download(url, dest, check_cert=True, overwrite=False, logfile=None, mi
urls += [urllib.parse.urljoin(u + '/', filename) for u in mirrors]
if sys.platform.startswith('win'):
- cmd = ['powershell', '-Command', 'Invoke-WebRequest', '-UserAgent',
- user_agent, '-Method', 'Get', '-OutFile', dest]
- # We will append the url at the end of the cmd array
- cmd += ['-Uri']
+ cmd = ['powershell', '-Command', '& { Set-Variable -Name ' \
+ 'ProgressPreference -Value \'SilentlyContinue\'; ' \
+ f'Invoke-WebRequest -UserAgent {user_agent} -OutFile {dest} ' \
+ '-Method Get -Uri %s }']
elif which('wget'):
cmd = ['wget', '--user-agent', user_agent, '--tries=2', '--timeout=20',
'--progress=dot:giga', '-O', dest]
if not check_cert:
cmd += ['--no-check-certificate']
+ cmd += ['%s']
elif which('curl'):
cmd = ['curl', '-L', '--fail', '--user-agent', user_agent, '--retry', '2',
'--connect-timeout', '20', '--progress-bar', '-o', dest]
if not check_cert:
cmd += ['-k']
+ cmd += ['%s']
else:
raise FatalError('Need either wget or curl to download things')
errors = []
+ url_fmt = cmd[-1]
+ cmd = cmd[:-1]
for murl in urls:
try:
- return await async_call(cmd + [murl], cpu_bound=False, logfile=logfile)
+ return await async_call(cmd + [url_fmt % murl], cpu_bound=False,
+ logfile=logfile)
except Exception as ex:
if os.path.exists(dest):
os.remove(dest)