Spaces:
Running
Running
File size: 7,222 Bytes
7b8e3ba f913c73 bf1c6f2 f913c73 bf1c6f2 f913c73 bf1c6f2 f913c73 bf1c6f2 f913c73 bf1c6f2 f913c73 bf1c6f2 7b8e3ba bf1c6f2 f913c73 bf1c6f2 f913c73 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | """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)
|