MCPcopy
hub / github.com/pythongosssss/ComfyUI-Custom-Scripts / download

Function download

pysssss.py:191–215  ·  view source on GitHub ↗
(url, stream, update_callback=None, session=None)

Source from the content-addressed store, hash-verified

189
190
191async def download(url, stream, update_callback=None, session=None):
192 close_session = False
193 if session is None:
194 close_session = True
195 session = get_http_session()
196 try:
197 async with session.get(url) as response:
198 size = int(response.headers.get('content-length', 0)) or None
199
200 with tqdm(
201 unit='B', unit_scale=True, miniters=1, desc=url.split('/')[-1], total=size,
202 ) as progressbar:
203 perc = 0
204 async for chunk in response.content.iter_chunked(2048):
205 stream.write(chunk)
206 progressbar.update(len(chunk))
207 if update_callback is not None and progressbar.total is not None and progressbar.total != 0:
208 last = perc
209 perc = round(progressbar.n / progressbar.total, 2)
210 if perc != last:
211 last = perc
212 await update_callback(perc)
213 finally:
214 if close_session and session is not None:
215 await session.close()
216
217
218async def download_to_file(url, destination, update_callback=None, is_ext_subpath=True, session=None):

Callers 1

download_to_fileFunction · 0.85

Calls 3

get_http_sessionFunction · 0.85
updateMethod · 0.80
closeMethod · 0.80

Tested by

no test coverage detected