dfdf
This commit is contained in:
@@ -467,27 +467,16 @@ class Telegram(Provider):
|
||||
pass
|
||||
|
||||
# Progress callback: prints to stderr so it doesn't interfere with pipeline stdout.
|
||||
from models import ProgressBar
|
||||
progress_bar = ProgressBar()
|
||||
last_print = {"t": 0.0}
|
||||
def _progress(current: int, total: int) -> None:
|
||||
try:
|
||||
now = time.monotonic()
|
||||
# Throttle to avoid spamming.
|
||||
if now - float(last_print.get("t", 0.0)) < 0.25 and current < total:
|
||||
return
|
||||
last_print["t"] = now
|
||||
|
||||
pct = ""
|
||||
try:
|
||||
if total and total > 0:
|
||||
pct = f" {min(100.0, (current / total) * 100.0):5.1f}%"
|
||||
except Exception:
|
||||
pct = ""
|
||||
|
||||
line = f"[telegram] Downloading{pct} ({_format_bytes(current)}/{_format_bytes(total)})"
|
||||
sys.stderr.write("\r" + line)
|
||||
sys.stderr.flush()
|
||||
except Exception:
|
||||
now = time.monotonic()
|
||||
# Throttle to avoid spamming.
|
||||
if now - float(last_print.get("t", 0.0)) < 0.25 and current < total:
|
||||
return
|
||||
last_print["t"] = now
|
||||
progress_bar.update(downloaded=int(current), total=int(total), label="telegram", file=sys.stderr)
|
||||
|
||||
part_kb = self._resolve_part_size_kb(file_size)
|
||||
try:
|
||||
@@ -502,11 +491,7 @@ class Telegram(Provider):
|
||||
except TypeError:
|
||||
# Older/newer Telethon versions may not accept part_size_kb on download_media.
|
||||
downloaded = _resolve(client.download_media(message, file=str(output_dir), progress_callback=_progress))
|
||||
try:
|
||||
sys.stderr.write("\n")
|
||||
sys.stderr.flush()
|
||||
except Exception:
|
||||
pass
|
||||
progress_bar.finish()
|
||||
if not downloaded:
|
||||
raise Exception("Telegram download returned no file")
|
||||
downloaded_path = Path(str(downloaded))
|
||||
|
||||
Reference in New Issue
Block a user