feat: 进度条

This commit is contained in:
ikun
2024-09-16 13:45:21 +08:00
parent 5964b5fb4e
commit b1b0fe9517
2 changed files with 17 additions and 5 deletions

View File

@@ -9,7 +9,7 @@ def init():
print('\033[1;32;40m \\_____/ |_| \\_| |_____| |_| \\_\\ |_____| /_/' + '\033[0m')
log.info('作者ikun0014')
log.info('本项目基于wxy1343/ManifestAutoUpdate进行修改采用GPL-3.0许可证')
log.info('版本1.2.0')
log.info('版本1.2.1')
log.info('项目仓库https://github.com/ikunshare/Onekey')
log.info('官网ikunshare.com')
log.warning('本项目完全开源免费如果你在淘宝QQ群内通过购买方式获得赶紧回去骂商家死全家\n交流群组:\nhttps://qm.qq.com/q/d7sWovfAGI\nhttps://t.me/ikunshare_group')

View File

@@ -1,6 +1,9 @@
from aiohttp import ClientError
from tqdm.asyncio import tqdm_asyncio
from .log import log
async def get(sha, path, repo, session):
url_list = [
f'https://cdn.jsdmirror.com/gh/{repo}@{sha}/{path}',
@@ -14,12 +17,21 @@ async def get(sha, path, repo, session):
try:
async with session.get(url, ssl=False) as r:
if r.status == 200:
return await r.read()
total_size = int(r.headers.get('Content-Length', 0))
chunk_size = 1024
content = bytearray()
with tqdm_asyncio(total=total_size, unit='B', unit_scale=True, desc=f'下载 {path}') as pbar:
async for chunk in r.content.iter_chunked(chunk_size):
content.extend(chunk)
pbar.update(len(chunk))
return content
else:
log.error(f' 🔄 获取失败: {path} - 状态码: {r.status}')
except ClientError:
log.error(f' 🔄 获取失败: {path} - 连接错误')
retry -= 1
log.warning(f' 🔄 重试剩余次数: {retry} - {path}')
log.error(f' 🔄 超过最大重试次数: {path}')
raise Exception(f' 🔄 无法下载: {path}')
log.warning(f' 🔄 重试剩余次数: {retry} - {path}')
log.error(f' 🔄 超过最大重试次数: {path}')
raise Exception(f' 🔄 无法下载: {path}')