forked from vasusen-code/VIDEOconvertor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
480 lines (447 loc) · 19.7 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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
# This file is part of the VIDEOconvertor distribution.
# Copyright (c) 2021 vasusen-code ; All rights reserved.
#
# 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/vasusen-code/VIDEOconvertor/blob/public/LICENSE> .
import os, time, asyncio
from telethon import events, Button
from telethon.tl.types import DocumentAttributeVideo
from ethon.telefunc import fast_download
from ethon.pyfunc import video_metadata
from .. import Drone, LOG_CHANNEL, FORCESUB_UN, MONGODB_URI, ACCESS_CHANNEL
from main.plugins.rename import media_rename
from main.plugins.compressor import compress
from main.plugins.trimmer import trim
from main.plugins.convertor import mp3, flac, wav, mp4, mkv, webm, file, video
from main.Database.database import Database
from main.plugins.actions import force_sub
from main.plugins.encoder import encode
from main.plugins.ssgen import screenshot
from LOCAL.localisation import source_text, SUPPORT_LINK
#Don't be a MF by stealing someone's hardwork.
forcesubtext = f"Hey there!To use this bot you've to join @{FORCESUB_UN}.\n\nAlso join @DroneBots."
@Drone.on(events.NewMessage(incoming=True,func=lambda e: e.is_private))
async def compin(event):
db = Database(MONGODB_URI, 'videoconvertor')
if event.is_private:
media = event.media
if media:
yy = await force_sub(event.sender_id)
if yy is True:
return await event.reply(forcesubtext)
banned = await db.is_banned(event.sender_id)
if banned is True:
return await event.reply(f'you are Banned to use me!\n\ncontact [SUPPORT]({SUPPORT_LINK})', link_preview=False)
video = event.file.mime_type
if 'video' in video:
await event.reply("📽",
buttons=[
[Button.inline("ENCODE", data="encode"),
Button.inline("COMPRESS", data="compress")],
[Button.inline("CONVERT", data="convert"),
Button.inline("RENAME", data="rename")],
[Button.inline("SSHOTS", data="sshots"),
Button.inline("TRIM", data="trim")]
])
elif 'png' in video:
return
elif 'jpeg' in video:
return
elif 'jpg' in video:
return
else:
await event.reply('📦',
buttons=[
[Button.inline("RENAME", data="rename")]])
await event.forward_to(int(ACCESS_CHANNEL))
@Drone.on(events.callbackquery.CallbackQuery(data="encode"))
async def _encode(event):
await event.edit("**🔀ENCODE**",
buttons=[
[Button.inline("240p", data="240"),
Button.inline("360p", data="360")],
[Button.inline("480p", data="480"),
Button.inline("720p", data="720")],
[Button.inline("x264", data="264"),
Button.inline("x265", data="265")],
[Button.inline("BACK", data="back")]])
@Drone.on(events.callbackquery.CallbackQuery(data="compress"))
async def _compress(event):
await event.edit("**🗜COMPRESS**",
buttons=[
[Button.inline("HEVC COMPRESS", data="hcomp"),
Button.inline("FAST COMPRESS", data="fcomp")],
[Button.inline("BACK", data="back")]])
@Drone.on(events.callbackquery.CallbackQuery(data="convert"))
async def convert(event):
button = await event.get_message()
msg = await button.get_reply_message()
await event.edit("🔃**CONVERT**",
buttons=[
[Button.inline("MP3", data="mp3"),
Button.inline("FLAC", data="flac"),
Button.inline("WAV", data="wav")],
[Button.inline("MP4", data="mp4"),
Button.inline("WEBM", data="webm"),
Button.inline("MKV", data="mkv")],
[Button.inline("FILE", data="file"),
Button.inline("VIDEO", data="video")],
[Button.inline("BACK", data="back")]])
@Drone.on(events.callbackquery.CallbackQuery(data="back"))
async def back(event):
await event.edit("📽", buttons=[
[Button.inline("ENCODE", data="encode"),
Button.inline("COMPRESS", data="compress")],
[Button.inline("CONVERT", data="convert"),
Button.inline("RENAME", data="rename")],
[Button.inline("SSHOTS", data="sshots"),
Button.inline("TRIM", data="trim")]])
#-----------------------------------------------------------------------------------------
process1 = []
timer = []
#Set timer to avoid spam
async def set_timer(event, list1, list2):
now = time.time()
list2.append(f'{now}')
list1.append(f'{event.sender_id}')
await event.client.send_message(event.chat_id, 'You can start a new process again after 5 minutes.')
await asyncio.sleep(300)
list2.pop(int(timer.index(f'{now}')))
list1.pop(int(process1.index(f'{event.sender_id}')))
#check time left in timer
async def check_timer(event, list1, list2):
if f'{event.sender_id}' in list1:
index = list1.index(f'{event.sender_id}')
last = list2[int(index)]
present = time.time()
return False, f"You have to wait {300-round(present-float(last))} seconds more to start a new process!"
else:
return True, None
@Drone.on(events.callbackquery.CallbackQuery(data="mp3"))
async def vtmp3(event):
yy = await force_sub(event.sender_id)
if yy is True:
return await event.reply(forcesubtext)
button = await event.get_message()
msg = await button.get_reply_message()
if not os.path.isdir("audioconvert"):
await event.delete()
os.mkdir("audioconvert")
await mp3(event, msg)
os.rmdir("audioconvert")
else:
await event.edit("Another process in progress!")
@Drone.on(events.callbackquery.CallbackQuery(data="flac"))
async def vtflac(event):
yy = await force_sub(event.sender_id)
if yy is True:
return await event.reply(forcesubtext)
button = await event.get_message()
msg = await button.get_reply_message()
if not os.path.isdir("audioconvert"):
await event.delete()
os.mkdir("audioconvert")
await flac(event, msg)
os.rmdir("audioconvert")
else:
await event.edit("Another process in progress!")
@Drone.on(events.callbackquery.CallbackQuery(data="wav"))
async def vtwav(event):
yy = await force_sub(event.sender_id)
if yy is True:
return await event.reply(forcesubtext)
button = await event.get_message()
msg = await button.get_reply_message()
if not os.path.isdir("audioconvert"):
await event.delete()
os.mkdir("audioconvert")
await wav(event, msg)
os.rmdir("audioconvert")
else:
await event.edit("Another process in progress!")
@Drone.on(events.callbackquery.CallbackQuery(data="mp4"))
async def vtmp4(event):
yy = await force_sub(event.sender_id)
if yy is True:
return await event.reply(forcesubtext)
button = await event.get_message()
msg = await button.get_reply_message()
await event.delete()
await mp4(event, msg)
@Drone.on(events.callbackquery.CallbackQuery(data="mkv"))
async def vtmkv(event):
yy = await force_sub(event.sender_id)
if yy is True:
return await event.reply(forcesubtext)
button = await event.get_message()
msg = await button.get_reply_message()
await event.delete()
await mkv(event, msg)
@Drone.on(events.callbackquery.CallbackQuery(data="webm"))
async def vtwebm(event):
yy = await force_sub(event.sender_id)
if yy is True:
return await event.reply(forcesubtext)
button = await event.get_message()
msg = await button.get_reply_message()
await event.delete()
await webm(event, msg)
@Drone.on(events.callbackquery.CallbackQuery(data="file"))
async def vtfile(event):
yy = await force_sub(event.sender_id)
if yy is True:
return await event.reply(forcesubtext)
button = await event.get_message()
msg = await button.get_reply_message()
await event.delete()
await file(event, msg)
@Drone.on(events.callbackquery.CallbackQuery(data="video"))
async def ftvideo(event):
yy = await force_sub(event.sender_id)
if yy is True:
return await event.reply(forcesubtext)
button = await event.get_message()
msg = await button.get_reply_message()
await event.delete()
await video(event, msg)
@Drone.on(events.callbackquery.CallbackQuery(data="rename"))
async def rename(event):
yy = await force_sub(event.sender_id)
if yy is True:
return await event.reply(forcesubtext)
button = await event.get_message()
msg = await button.get_reply_message()
await event.delete()
markup = event.client.build_reply_markup(Button.force_reply())
async with Drone.conversation(event.chat_id) as conv:
cm = await conv.send_message("Send me a new name for the file as a `reply` to this message.\n\n**NOTE:** `.ext` is not required.", buttons=markup)
try:
m = await conv.get_reply()
new_name = m.text
await cm.delete()
if not m:
return await cm.edit("No response found.")
except Exception as e:
print(e)
return await cm.edit("An error occured while waiting for the response.")
await media_rename(event, msg, new_name)
@Drone.on(events.callbackquery.CallbackQuery(data="fcomp"))
async def fcomp(event):
yy = await force_sub(event.sender_id)
if yy is True:
return await event.reply(forcesubtext)
if f'{event.sender_id}' in process1:
index = process1.index(f'{event.sender_id}')
last = timer[int(index)]
present = time.time()
return await event.answer(f"You have to wait {300-round(present-float(last))} seconds more to start a new process!", alert=True)
button = await event.get_message()
msg = await button.get_reply_message()
if not os.path.isdir("encodemedia"):
await event.delete()
os.mkdir("encodemedia")
await compress(event, msg, ffmpeg_cmd=2)
os.rmdir("encodemedia")
now = time.time()
timer.append(f'{now}')
process1.append(f'{event.sender_id}')
await event.client.send_message(event.chat_id, 'You can start a new process again after 5 minutes.')
await asyncio.sleep(300)
timer.pop(int(timer.index(f'{now}')))
process1.pop(int(process1.index(f'{event.sender_id}')))
else:
await event.edit(f"Another process in progress!\n\n**[LOG CHANNEL](https://t.me/{LOG_CHANNEL})**", link_preview=False)
@Drone.on(events.callbackquery.CallbackQuery(data="hcomp"))
async def hcomp(event):
yy = await force_sub(event.sender_id)
if yy is True:
return await event.reply(forcesubtext)
if f'{event.sender_id}' in process1:
index = process1.index(f'{event.sender_id}')
last = timer[int(index)]
present = time.time()
return await event.answer(f"You have to wait {300-round(present-float(last))} seconds more to start a new process!", alert=True)
button = await event.get_message()
msg = await button.get_reply_message()
if not os.path.isdir("encodemedia"):
await event.delete()
os.mkdir("encodemedia")
await compress(event, msg, ffmpeg_cmd=1)
os.rmdir("encodemedia")
now = time.time()
timer.append(f'{now}')
process1.append(f'{event.sender_id}')
await event.client.send_message(event.chat_id, 'You can start a new process again after 5 minutes.')
await asyncio.sleep(300)
timer.pop(int(timer.index(f'{now}')))
process1.pop(int(process1.index(f'{event.sender_id}')))
else:
await event.edit(f"Another process in progress!\n\n**[LOG CHANNEL](https://t.me/{LOG_CHANNEL})**", link_preview=False)
@Drone.on(events.callbackquery.CallbackQuery(data="264"))
async def _264(event):
yy = await force_sub(event.sender_id)
if yy is True:
return await event.reply(forcesubtext)
s, t = await check_timer(event, process1, timer)
if s == False:
return await event.answer(t, alert=True)
button = await event.get_message()
msg = await button.get_reply_message()
if not os.path.isdir("encodemedia"):
await event.delete()
os.mkdir("encodemedia")
await compress(event, msg, ffmpeg_cmd=4, ps_name="**ENCODING:**")
os.rmdir("encodemedia")
await set_timer(event, process1, timer)
else:
await event.edit(f"Another process in progress!\n\n**[LOG CHANNEL](https://t.me/{LOG_CHANNEL})**", link_preview=False)
@Drone.on(events.callbackquery.CallbackQuery(data="265"))
async def _265(event):
yy = await force_sub(event.sender_id)
if yy is True:
return await event.reply(forcesubtext)
s, t = await check_timer(event, process1, timer)
if s == False:
return await event.answer(t, alert=True)
button = await event.get_message()
msg = await button.get_reply_message()
if not os.path.isdir("encodemedia"):
await event.delete()
os.mkdir("encodemedia")
await compress(event, msg, ffmpeg_cmd=3, ps_name="**ENCODING:**")
os.rmdir("encodemedia")
await set_timer(event, process1, timer)
else:
await event.edit(f"Another process in progress!\n\n**[LOG CHANNEL](https://t.me/{LOG_CHANNEL})**", link_preview=False)
@Drone.on(events.callbackquery.CallbackQuery(data="240"))
async def _240(event):
yy = await force_sub(event.sender_id)
if yy is True:
return await event.reply(forcesubtext)
s, t = await check_timer(event, process1, timer)
if s == False:
return await event.answer(t, alert=True)
button = await event.get_message()
msg = await button.get_reply_message()
if not os.path.isdir("encodemedia"):
await event.delete()
os.mkdir("encodemedia")
await encode(event, msg, scale=240)
os.rmdir("encodemedia")
await set_timer(event, process1, timer)
else:
await event.edit(f"Another process in progress!\n\n**[LOG CHANNEL](https://t.me/{LOG_CHANNEL})**", link_preview=False)
@Drone.on(events.callbackquery.CallbackQuery(data="360"))
async def _360(event):
yy = await force_sub(event.sender_id)
if yy is True:
return await event.reply(forcesubtext)
s, t = await check_timer(event, process1, timer)
if s == False:
return await event.answer(t, alert=True)
button = await event.get_message()
msg = await button.get_reply_message()
if not os.path.isdir("encodemedia"):
await event.delete()
os.mkdir("encodemedia")
await encode(event, msg, scale=360)
os.rmdir("encodemedia")
await set_timer(event, process1, timer)
else:
await event.edit(f"Another process in progress!\n\n**[LOG CHANNEL](https://t.me/{LOG_CHANNEL})**", link_preview=False)
@Drone.on(events.callbackquery.CallbackQuery(data="480"))
async def _480(event):
yy = await force_sub(event.sender_id)
if yy is True:
return await event.reply(forcesubtext)
s, t = await check_timer(event, process1, timer)
if s == False:
return await event.answer(t, alert=True)
button = await event.get_message()
msg = await button.get_reply_message()
if not os.path.isdir("encodemedia"):
await event.delete()
os.mkdir("encodemedia")
await encode(event, msg, scale=480)
os.rmdir("encodemedia")
await set_timer(event, process1, timer)
else:
await event.edit(f"Another process in progress!\n\n**[LOG CHANNEL](https://t.me/{LOG_CHANNEL})**", link_preview=False)
@Drone.on(events.callbackquery.CallbackQuery(data="720"))
async def _720(event):
yy = await force_sub(event.sender_id)
if yy is True:
return await event.reply(forcesubtext)
s, t = await check_timer(event, process1, timer)
if s == False:
return await event.answer(t, alert=True)
button = await event.get_message()
msg = await button.get_reply_message()
if not os.path.isdir("encodemedia"):
await event.delete()
os.mkdir("encodemedia")
await encode(event, msg, scale=720)
os.rmdir("encodemedia")
await set_timer(event, process1, timer)
else:
await event.edit(f"Another process in progress!\n\n**[LOG CHANNEL](https://t.me/{LOG_CHANNEL})**", link_preview=False)
@Drone.on(events.callbackquery.CallbackQuery(data="sshots"))
async def ss_(event):
yy = await force_sub(event.sender_id)
if yy is True:
return await event.reply(forcesubtext)
if f'{event.sender_id}' in process1:
index = process1.index(f'{event.sender_id}')
last = timer[int(index)]
present = time.time()
return await event.answer(f"You have to wait {120-round(present-float(last))} seconds more to start a new process!", alert=True)
button = await event.get_message()
msg = await button.get_reply_message()
await event.delete()
await screenshot(event, msg)
now = time.time()
timer.append(f'{now}')
process1.append(f'{event.sender_id}')
await event.client.send_message(event.chat_id, 'You can start a new process again after 2 minutes.')
await asyncio.sleep(120)
timer.pop(int(timer.index(f'{now}')))
process1.pop(int(process1.index(f'{event.sender_id}')))
@Drone.on(events.callbackquery.CallbackQuery(data="trim"))
async def vtrim(event):
yy = await force_sub(event.sender_id)
if yy is True:
return await event.reply(forcesubtext)
button = await event.get_message()
msg = await button.get_reply_message()
await event.delete()
markup = event.client.build_reply_markup(Button.force_reply())
async with Drone.conversation(event.chat_id) as conv:
try:
xx = await conv.send_message("send me the start time of the video you want to trim from as a reply to this. \n\nIn format hh:mm:ss , for eg: `01:20:69` ", buttons=markup)
x = await conv.get_reply()
st = x.text
await xx.delete()
if not st:
return await xx.edit("No response found.")
except Exception as e:
print(e)
return await xx.edit("An error occured while waiting for the response.")
try:
xy = await conv.send_message("send me the end time of the video you want to trim till as a reply to this. \n\nIn format hh:mm:ss , for eg: `01:20:69` ", buttons=markup)
y = await conv.get_reply()
et = y.text
await xy.delete()
if not et:
return await xy.edit("No response found.")
except Exception as e:
print(e)
return await xy.edit("An error occured while waiting for the response.")
await trim(event, msg, st, et)