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)