Fix progress hook
All checks were successful
Build and Publish Jimmy.2 / build_and_publish (push) Successful in 6s

This commit is contained in:
Nexus 2024-05-31 03:09:31 +01:00
parent 858782eec8
commit 0c98da328d
Signed by: nex
GPG key ID: 0FA334385D0B689F

View file

@ -265,15 +265,18 @@ class YTDLCog(commands.Cog):
def _download_hook(_data: dict[str, typing.Any]):
n = time.time()
_total = _data.get("total_bytes", _data.get("total_bytes_estimate"))
_total = _data.get("total_bytes", _data.get("total_bytes_estimate")) or ctx.guild.filesize_limit
if _total:
_percent = round(_data.get("downloaded_bytes", 0) / _total * 100, 2)
_percent = round((_data.get("downloaded_bytes") or 0) / _total * 100, 2)
else:
_total = max(1, _data.get("fragment_count", 4096))
_percent = round(max(_data.get("fragment_index", 1), 1) / _total * 100, 2)
_speed_bytes_per_second = _data.get("speed", 1)
_total = max(1, _data.get("fragment_count", 4096) or 4096)
_percent = round(max(_data.get("fragment_index", 1) or 1, 1) / _total * 100, 2)
_speed_bytes_per_second = _data.get("speed", 1) or 1 or 1
_speed_megabits_per_second = round((_speed_bytes_per_second * 8) / 1024 / 1024)
_eta = discord.utils.utcnow() + _data.get("eta") or discord.utils.utcnow()
if _data.get("eta"):
_eta = discord.utils.utcnow() + _data.get("eta")
else:
_eta = discord.utils.utcnow()
blocks = "#" * math.floor(_percent / 10)
bar = f"{blocks}{'.' * (10 - len(blocks))}"
line = (f"{_percent}% [{bar}] | {_speed_megabits_per_second}Mbps | "