Spaces:
Running
Running
KHALED-ALIM
โก ุชุณุฑูุน ูู ุงูุนู
ููุงุช + ุชุทููุฑ ุดุงู
ู ููุฑุณุงุฆู ูุงูุฃุฒุฑุงุฑ
bf1c6f2 | """Build detailed progress messages shown to the admin in Telegram โ per-stage.""" | |
| from __future__ import annotations | |
| from models.schemas import DownloadProgress | |
| from utils.file_utils import format_size as _fmt_size | |
| _PROGRESS_BAR_LENGTH = 20 | |
| def _bar(percent: float) -> str: | |
| filled = int(percent / 100 * _PROGRESS_BAR_LENGTH) | |
| empty = _PROGRESS_BAR_LENGTH - filled | |
| return "โ" * filled + "โ" * empty | |
| def _eta(seconds: float) -> str: | |
| m, s = divmod(int(seconds), 60) | |
| h, m = divmod(m, 60) | |
| if h: | |
| return f"{h}h {m}m" | |
| if m: | |
| return f"{m}m {s}s" | |
| return f"{s}s" | |
| def _speed_line(bps: float) -> str: | |
| mb_s = bps / 1_048_576 | |
| return f"{mb_s:.1f} MB/s ({mb_s * 8:.1f} Mbps)" | |
| def _header(status: str) -> str: | |
| headers = { | |
| "downloading": "โฌ๏ธ **ุชุญู ูู ุงูู ูู ู ู ุชูุบุฑุงู **", | |
| "processing": "๐ **ู ุนุงูุฌุฉ ุงูููุฏูู (FFmpeg)**", | |
| "uploading": "โ๏ธ **ุฑูุน ุงูู ูู ุฅูู StreamTape**", | |
| "telegram_upload": "๐ค **ุฑูุน ูุณุฎ ุงุญุชูุงุทูุฉ ุฅูู ุชูุบุฑุงู **", | |
| "archiving": "๐๏ธ **ุฃุฑุดูุฉ ูู ูุงุนุฏุฉ ุงูุจูุงูุงุช**", | |
| "done": "โ **ุงูุชู ู ุจูุฌุงุญ! ๐**", | |
| "error": "โ **ุญุฏุซ ุฎุทุฃ!**", | |
| } | |
| return headers.get(status, "โณ **ุฌุงุฑู ุงูุนู ู...**") | |
| def format_progress_message(p: DownloadProgress) -> str: | |
| title = _header(p.status) | |
| lines: list[str] = [ | |
| "โ" * 28, | |
| title, | |
| "โ" * 28, | |
| ] | |
| # โโ downloading โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ | |
| if p.status == "downloading": | |
| lines.append("") | |
| lines.append(f"๐ฆ **ุงูุญุฌู ุงูููู:** `{_fmt_size(p.total)}`") | |
| if p.downloaded > 0: | |
| lines.append(f"โฌ๏ธ **ุชู ุงูุชุญู ูู:** `{_fmt_size(p.downloaded)}` ู ู `{_fmt_size(p.total)}`") | |
| if p.total > 0: | |
| lines.append(f"\n๐ `{_bar(p.percent)}` `{p.percent:.1f}%`") | |
| if p.speed > 0: | |
| lines.append(f"๐ **ุงูุณุฑุนุฉ:** `{_speed_line(p.speed)}`") | |
| lines.append(f"โฑ๏ธ **ุงูููุช ุงูู ุชุจูู:** ~`{_eta(p.eta_seconds)}`") | |
| if p.elapsed > 0: | |
| lines.append(f"โฑ๏ธ **ุงูููุช ุงูู ููุถู:** `{_eta(p.elapsed)}`") | |
| if p.bandwidth_total > 0: | |
| lines.append("") | |
| lines.append("โ" * 28) | |
| lines.append(f"๐ **ุฅุฌู ุงูู ุงูุจุงูุฏููุซ:** `{_fmt_size(p.bandwidth_total)}`") | |
| # โโ processing โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ | |
| elif p.status == "processing": | |
| lines.append("") | |
| lines.append(f"๐ฆ **ุงูุญุฌู ุงูููู:** `{_fmt_size(p.total)}`") | |
| if p.stage_detail: | |
| lines.append(f"๐ง **ู ุฑุญูุฉ FFmpeg:** `{p.stage_detail}`") | |
| if p.sub_stage: | |
| lines.append(f"โ๏ธ **ุงูุนู ููุฉ:** `{p.sub_stage}`") | |
| if p.total > 0: | |
| lines.append(f"\n๐ `{_bar(p.percent)}` `{p.percent:.1f}%`") | |
| if p.elapsed > 0: | |
| lines.append(f"โฑ๏ธ **ุงูููุช ุงูู ููุถู:** `{_eta(p.elapsed)}`") | |
| # โโ uploading (StreamTape) โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ | |
| elif p.status == "uploading": | |
| lines.append("") | |
| lines.append(f"๐ฆ **ุงูุญุฌู ุงูููู:** `{_fmt_size(p.total)}`") | |
| if p.stage_detail: | |
| lines.append(f"๐ค **ุงูุญุณุงุจ:** `{p.stage_detail}`") | |
| if p.sub_stage: | |
| lines.append(f"โ๏ธ **ุงูู ุฑุญูุฉ ุงููุฑุนูุฉ:** `{p.sub_stage}`") | |
| if p.total_items > 0: | |
| cur = p.current_item | |
| tot = p.total_items | |
| lines.append(f"๐ **ุชูุฏู ุงูุญุณุงุจุงุช:** `{cur}` ู ู `{tot}`") | |
| pct = cur / tot * 100 | |
| lines.append(f"\n๐ `{_bar(pct)}` `{pct:.1f}%`") | |
| if p.elapsed > 0: | |
| lines.append(f"โฑ๏ธ **ุงูููุช ุงูู ููุถู:** `{_eta(p.elapsed)}`") | |
| # โโ telegram_upload โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ | |
| elif p.status == "telegram_upload": | |
| lines.append("") | |
| lines.append(f"๐ฆ **ุงูุญุฌู ุงูููู:** `{_fmt_size(p.total)}`") | |
| if p.total_items > 0: | |
| cur = p.current_item | |
| tot = p.total_items | |
| lines.append(f"๐ค **ุงููุณุฎุฉ:** `{cur}/{tot}`") | |
| pct = cur / tot * 100 | |
| lines.append(f"\n๐ `{_bar(pct)}` `{pct:.1f}%`") | |
| if p.elapsed > 0: | |
| lines.append(f"โฑ๏ธ **ุงูููุช ุงูู ููุถู:** `{_eta(p.elapsed)}`") | |
| # โโ archiving โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ | |
| elif p.status == "archiving": | |
| lines.append("") | |
| if p.stage_detail: | |
| lines.append(f"๐๏ธ **ุงูุฌุฏูู:** `{p.stage_detail}`") | |
| if p.sub_stage: | |
| lines.append(f"โ **ุงูุญุงูุฉ:** `{p.sub_stage}`") | |
| if p.total_items > 0: | |
| lines.append(f"๐ **ุงูุชูุฏู :** `{p.current_item}` ู ู `{p.total_items}`") | |
| lines.append("") | |
| lines.append("โ **ุชู ุช ุงูุฃุฑุดูุฉ ุจูุฌุงุญ!**") | |
| lines.append("") | |
| lines.append("โ" * 28) | |
| lines.append("โ **ุชู ุช ุงูุนู ููุฉ ุจูุฌุงุญ!**") | |
| return "\n".join(lines) | |
| # โโ done โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ | |
| elif p.status == "done": | |
| lines.append("") | |
| lines.append("๐ **๐ ุชู ุจูุฌุงุญ! ๐**") | |
| lines.append("") | |
| lines.append(f"๐ฆ **ุงูุญุฌู ุงูููู:** `{_fmt_size(p.total)}`") | |
| if p.elapsed > 0: | |
| lines.append(f"โฑ๏ธ **ุงูููุช ุงูู ุณุชุบุฑู:** `{_eta(p.elapsed)}`") | |
| if p.bandwidth_total > 0: | |
| lines.append(f"๐ **ุฅุฌู ุงูู ุงูุจุงูุฏููุซ:** `{_fmt_size(p.bandwidth_total)}`") | |
| lines.append("") | |
| lines.append("โ" * 28) | |
| lines.append("โ **ุชู ุช ุงูุนู ููุฉ ุจูุฌุงุญ!**") | |
| return "\n".join(lines) | |
| # โโ error โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ | |
| elif p.status == "error": | |
| lines.append("") | |
| if p.stage_detail: | |
| lines.append(f"โ ๏ธ **ุงูู ุฑุญูุฉ:** `{p.stage_detail}`") | |
| if p.sub_stage: | |
| lines.append(f"๐ด **ุงูุฎุทุฃ:** `{p.sub_stage}`") | |
| lines.append("") | |
| lines.append("โ" * 28) | |
| lines.append("โ **ูุดูุช ุงูุนู ููุฉ!**") | |
| return "\n".join(lines) | |
| lines.append("") | |
| lines.append("โ" * 28) | |
| lines.append("โณ **ูุฑุฌู ุงูุงูุชุธุงุฑ...**") | |
| return "\n".join(lines) | |