diff --git a/src/cogs/ytdl.py b/src/cogs/ytdl.py index 6cf41bd..b3103a3 100644 --- a/src/cogs/ytdl.py +++ b/src/cogs/ytdl.py @@ -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 | "