forked from alreadydea/txt-to-vdo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
p_bar.py
127 lines (104 loc) ยท 4.57 KB
/
p_bar.py
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
# MIT License
#
# Copyright (c) 2019-present Dan <https://github.com/delivrance>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE
import time
import math
import os
from pyrogram.errors import FloodWait
class Timer:
def __init__(self, time_between=5):
self.start_time = time.time()
self.time_between = time_between
def can_send(self):
if time.time() > (self.start_time + self.time_between):
self.start_time = time.time()
return True
return False
from datetime import datetime,timedelta
#lets do calculations
def hrb(value, digits= 2, delim= "", postfix=""):
"""Return a human-readable file size.
"""
if value is None:
return None
chosen_unit = "B"
for unit in ("KiB", "MiB", "GiB", "TiB"):
if value > 1000:
value /= 1024
chosen_unit = unit
else:
break
return f"{value:.{digits}f}" + delim + chosen_unit + postfix
def hrt(seconds, precision = 0):
"""Return a human-readable time delta as a string.
"""
pieces = []
value = timedelta(seconds=seconds)
if value.days:
pieces.append(f"{value.days}d")
seconds = value.seconds
if seconds >= 3600:
hours = int(seconds / 3600)
pieces.append(f"{hours}h")
seconds -= hours * 3600
if seconds >= 60:
minutes = int(seconds / 60)
pieces.append(f"{minutes}m")
seconds -= minutes * 60
if seconds > 0 or not pieces:
pieces.append(f"{seconds}s")
if not precision:
return "".join(pieces)
return "".join(pieces[:precision])
timer = Timer()
# designed by ๐๐๐๐๐
async def progress_bar(current, total, reply, start):
if timer.can_send():
now = time.time()
diff = now - start
if diff < 1:
return
else:
perc = f"{current * 100 / total:.1f}%"
elapsed_time = round(diff)
speed = current / elapsed_time
remaining_bytes = total - current
if speed > 0:
eta_seconds = remaining_bytes / speed
eta = hrt(eta_seconds, precision=1)
else:
eta = "-"
sp = str(hrb(speed)) + "/s"
tot = hrb(total)
cur = hrb(current)
#don't even change anything till here
# Calculate progress bar dots
#ab mila dil ko sukun #by ๐๐๐๐๐
#change from here if you want
bar_length = 11
completed_length = int(current * bar_length / total)
remaining_length = bar_length - completed_length
progress_bar = "โ" * completed_length + "โ" * remaining_length
try:
await reply.edit(f'`โญโโโ๐ค ๐๐ฅ๐ก๐ค๐๐๐๐ฃ๐ ๐คโโโโฎ \nโ{progress_bar}\nโ ๐๐ฅ๐๐๐ ๐จ: {sp} \nโ ๐๐ง๐ค๐๐ง๐๐จ๐จ โณ: {perc} \nโ ๐๐ค๐๐๐๐ ๐: {cur}\nโ ๐๐๐ฏ๐ ๐ฟ: {tot} \nโ ๐๐๐ผ ๐: {eta} \nโฐโโโโโ T I G E R โโโโโโฏ`\n')
# await reply.edit(f'`โญโโโ๐ค ๐๐ฅ๐ก๐ค๐๐๐๐ฃ๐ ๐คโโโโฎ \nโ{progress_bar}\nโ ๐๐ฅ๐๐๐ : {sp} \nโ ๐๐ง๐ค๐๐ง๐๐จ๐จ : {perc} \nโ ๐๐ค๐๐๐๐ : {cur}\nโ ๐๐๐ฏ๐ : {tot} \nโ ๐๐๐ผ : {eta} \nโฐโโ ๐ฝ๐ค๐ฉ ๐๐๐๐ ๐๐ฎ ๐จโ ๐ดโ ๐ป ๐ฎ ๐ฉ โโโฏ`\n')
except FloodWait as e:
time.sleep(e.x)