forked from 1Danish-00/CompressorQueue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__main__.py
211 lines (169 loc) · 6.61 KB
/
__main__.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
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# This file is part of the Compressor distribution.
# Copyright (c) 2021 Danish_00
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# License can be found in
# <https://github.com/1Danish-00/CompressorQueue/blob/main/License> .
from . import *
from .devtools import *
LOGS.info("Starting...")
######## Connect ########
try:
bot.start(bot_token=BOT_TOKEN)
except Exception as er:
LOGS.info(er)
####### GENERAL CMDS ########
@bot.on(events.NewMessage(pattern="/start"))
async def _(e):
await start(e)
@bot.on(events.NewMessage(pattern="/ping"))
async def _(e):
await up(e)
@bot.on(events.NewMessage(pattern="/help"))
async def _(e):
await help(e)
@bot.on(events.NewMessage(pattern="/link"))
async def _(e):
await dl_link(e)
######## Callbacks #########
@bot.on(events.callbackquery.CallbackQuery(data=re.compile(b"stats(.*)")))
async def _(e):
await stats(e)
@bot.on(events.callbackquery.CallbackQuery(data=re.compile(b"skip(.*)")))
async def _(e):
await skip(e)
@bot.on(events.callbackquery.CallbackQuery(data=re.compile("ihelp")))
async def _(e):
await ihelp(e)
@bot.on(events.callbackquery.CallbackQuery(data=re.compile("beck")))
async def _(e):
await beck(e)
########## Direct ###########
@bot.on(events.NewMessage(pattern="/eval"))
async def _(e):
await eval(e)
@bot.on(events.NewMessage(pattern="/bash"))
async def _(e):
await bash(e)
########## AUTO ###########
@bot.on(events.NewMessage(incoming=True))
async def _(e):
await encod(e)
async def something():
for i in itertools.count():
try:
if not WORKING and QUEUE:
user = int(OWNER.split()[0])
e = await bot.send_message(user, "Downloding Queue Files")
s = dt.now()
try:
if isinstance(QUEUE[list(QUEUE.keys())[0]], str):
dl = await fast_download(
e, list(QUEUE.keys())[0], QUEUE[list(QUEUE.keys())[0]]
)
else:
dl, file = QUEUE[list(QUEUE.keys())[0]]
tt = time.time()
dl = "downloads/" + dl
with open(dl, "wb") as f:
ok = await download_file(
client=bot,
location=file,
out=f,
progress_callback=lambda d, t: asyncio.get_event_loop().create_task(
progress(
d,
t,
e,
tt,
"Downloading",
)
),
)
except Exception as r:
LOGS.info(r)
WORKING.clear()
QUEUE.pop(list(QUEUE.keys())[0])
es = dt.now()
kk = dl.split("/")[-1]
aa = kk.split(".")[-1]
rr = "encode"
bb = kk.replace(f".{aa}", " compressed.mkv")
out = f"{rr}/{bb}"
thum = "thumb.jpg"
dtime = ts(int((es - s).seconds) * 1000)
hehe = f"{out};{dl};{list(QUEUE.keys())[0]}"
wah = code(hehe)
nn = await e.edit(
"`Compressing..`",
buttons=[
[Button.inline("STATS", data=f"stats{wah}")],
[Button.inline("CANCEL PROCESS", data=f"skip{wah}")],
],
)
cmd = FFMPEG.format(dl, out)
process = await asyncio.create_subprocess_shell(
cmd, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE
)
stdout, stderr = await process.communicate()
er = stderr.decode()
try:
if er:
await e.edit(str(er) + "\n\n**ERROR** Contact @danish_00")
QUEUE.pop(list(QUEUE.keys())[0])
os.remove(dl)
os.remove(out)
continue
except BaseException:
pass
ees = dt.now()
ttt = time.time()
await nn.delete()
nnn = await e.client.send_message(e.chat_id, "`Uploading...`")
with open(out, "rb") as f:
ok = await upload_file(
client=e.client,
file=f,
name=out,
progress_callback=lambda d, t: asyncio.get_event_loop().create_task(
progress(d, t, nnn, ttt, "uploading..")
),
)
ds = await e.client.send_file(
e.chat_id, file=ok, force_document=True, thumb=thum
)
await nnn.delete()
org = int(Path(dl).stat().st_size)
com = int(Path(out).stat().st_size)
pe = 100 - ((com / org) * 100)
per = str(f"{pe:.2f}") + "%"
eees = dt.now()
x = dtime
xx = ts(int((ees - es).seconds) * 1000)
xxx = ts(int((eees - ees).seconds) * 1000)
a1 = await info(dl, e)
a2 = await info(out, e)
dk = await ds.reply(
f"Original Size : {hbs(org)}\nCompressed Size : {hbs(com)}\nCompressed Percentage : {per}\n\nMediainfo: [Before]({a1})//[After]({a2})\n\nDownloaded in {x}\nCompressed in {xx}\nUploaded in {xxx}",
link_preview=False,
)
QUEUE.pop(list(QUEUE.keys())[0])
os.remove(dl)
os.remove(out)
else:
await asyncio.sleep(3)
except Exception as err:
LOGS.info(err)
########### Start ############
LOGS.info("Bot has started.")
with bot:
bot.loop.run_until_complete(something())
bot.loop.run_forever()