-
Notifications
You must be signed in to change notification settings - Fork 1
/
formatters.py
128 lines (113 loc) · 2.67 KB
/
formatters.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
127
128
from typing import Union
from pyrogram.types import Message
def get_readable_time(seconds: int) -> str:
count = 0
ping_time = ""
time_list = []
time_suffix_list = ["s", "m", "h", "days"]
while count < 4:
count += 1
if count < 3:
remainder, result = divmod(seconds, 60)
else:
remainder, result = divmod(seconds, 24)
if seconds == 0 and remainder == 0:
break
time_list.append(int(result))
seconds = int(remainder)
for i in range(len(time_list)):
time_list[i] = str(time_list[i]) + time_suffix_list[i]
if len(time_list) == 4:
ping_time += time_list.pop() + ", "
time_list.reverse()
ping_time += ":".join(time_list)
return ping_time
def convert_bytes(size: float) -> str:
"""humanize size"""
if not size:
return ""
power = 1024
t_n = 0
power_dict = {0: " ", 1: "Ki", 2: "Mi", 3: "Gi", 4: "Ti"}
while size > power:
size /= power
t_n += 1
return "{:.2f} {}B".format(size, power_dict[t_n])
async def int_to_alpha(user_id: int) -> str:
alphabet = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]
text = ""
user_id = str(user_id)
for i in user_id:
text += alphabet[int(i)]
return text
async def alpha_to_int(user_id_alphabet: str) -> int:
alphabet = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]
user_id = ""
for i in user_id_alphabet:
index = alphabet.index(i)
user_id += str(index)
user_id = int(user_id)
return user_id
def time_to_seconds(time):
stringt = str(time)
return sum(
int(x) * 60**i
for i, x in enumerate(reversed(stringt.split(":")))
)
def seconds_to_min(seconds):
if seconds is not None:
seconds = int(seconds)
d, h, m, s = (
seconds // (3600 * 24),
seconds // 3600 % 24,
seconds % 3600 // 60,
seconds % 3600 % 60,
)
if d > 0:
return "{:02d}:{:02d}:{:02d}:{:02d}".format(d, h, m, s)
elif h > 0:
return "{:02d}:{:02d}:{:02d}".format(h, m, s)
elif m > 0:
return "{:02d}:{:02d}".format(m, s)
elif s > 0:
return "00:{:02d}".format(s)
return "-"
formats = [
"webm",
"mkv",
"flv",
"vob",
"ogv",
"ogg",
"rrc",
"gifv",
"mng",
"mov",
"avi",
"qt",
"wmv",
"yuv",
"rm",
"asf",
"amv",
"mp4",
"m4p",
"m4v",
"mpg",
"mp2",
"mpeg",
"mpe",
"mpv",
"m4v",
"svi",
"3gp",
"3g2",
"mxf",
"roq",
"nsv",
"flv",
"f4v",
"f4p",
"f4a",
"f4b",
]