forked from MiyukiKun/Auto_Encodes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
147 lines (117 loc) · 4.28 KB
/
main.py
File metadata and controls
147 lines (117 loc) · 4.28 KB
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
from telethon import events
from config import app, bot, bot_username, BASE, FFMPEG, FFMPEGCMD, FFMPEGID, DESTINATION
from FastTelethonhelper import fast_upload, fast_download
import subprocess
import asyncio
import utils
import os
Locked = True
queue = []
loop = asyncio.get_event_loop()
async def dl_ffmpeg():
global Locked
message = "Starting up..."
a = await bot.send_message(BASE, "Starting up...")
r = await bot.send_message(BASE, "Downloading ffmpeg files now.....")
msgs = await bot.get_messages(FFMPEG, ids=FFMPEGID)
cmd = await bot.get_messages(FFMPEG, ids=FFMPEGCMD)
for msg in msgs:
s = await fast_download(bot, msg, r, "")
subprocess.call(f"chmod 777 ./{s}", shell=True)
message = f"{message}\n{s} Downloaded"
await a.edit(message)
await r.edit(f"FFMPEG download complete, and the active command is: \n\n`{cmd.text}`")
Locked = False
@bot.on(events.NewMessage(pattern=f"/encode{bot_username}"))
async def _(event):
global Locked
if Locked == False:
Locked = True
try:
msg = await event.get_reply_message()
cmd = await bot.get_messages(FFMPEG, ids=FFMPEGCMD)
e1080 = False
if '-1080' in event.text:
e1080 = True
await utils.encode(msg, cmd, e1080)
except:
pass
Locked = False
@bot.on(events.NewMessage(pattern=f"/start{bot_username}"))
async def _(event):
await event.reply("Im Alive")
@bot.on(events.NewMessage(pattern=f"/ls{bot_username}"))
async def _(event):
p = subprocess.Popen(f'ls -lh downloads', stdout=subprocess.PIPE, shell=True)
x = await event.reply(p.communicate()[0].decode("utf-8", "replace").strip())
await asyncio.sleep(15)
await x.delete()
@bot.on(events.NewMessage(pattern=f"/up{bot_username}"))
async def _(event):
path = event.raw_text.split(' ', 1)[-1]
r = await event.reply("Uploading...")
res_file = await fast_upload(bot, path, r)
try:
await bot.send_message(DESTINATION, file=res_file, force_document=True)
except:
await event.reply(file=res_file, force_document=True)
@bot.on(events.NewMessage(pattern=f"/del{bot_username}"))
async def _(event):
path = event.raw_text.split(' ', 1)[-1]
try:
os.remove(path)
await event.reply("Deleted")
except Exception as e:
await event.reply(str(e))
@bot.on(events.NewMessage(pattern=f"/addq{bot_username}"))
async def _(event):
global Locked
if Locked == True:
await event.reply("Cant update queue when encode is in progress.")
return
msg = await event.get_reply_message()
queue.append(msg.id)
await event.reply(f"Added to Queue \nQueue: {queue}")
@bot.on(events.NewMessage(pattern=f"/aq{bot_username}"))
async def _(event):
args = event.raw_text.split(" ")
msg = await event.get_reply_message()
if len(args) == 1:
args.append(5)
for i in range(msg.id, msg.id+int(args[1])):
queue.append(i)
await event.reply(f"Added to Queue \nQueue: {queue}")
@bot.on(events.NewMessage(pattern=f"/clearq{bot_username}"))
async def _(event):
global Locked
if Locked == True:
await event.reply("Cant update queue when encode is in progress.")
return
global queue
queue = []
await event.reply(f"Cleared")
@bot.on(events.NewMessage(pattern=f"/sq{bot_username}"))
async def _(event):
global Locked
if Locked == False:
global queue
Locked = True
for i in queue:
try:
msg = await bot.get_messages(event.chat_id, ids=i)
cmd = await bot.get_messages(FFMPEG, ids=FFMPEGCMD)
await utils.encode(msg, cmd)
except Exception as e:
await event.reply(f"[{i}] skipped due to error\n\n{e}")
queue = []
await event.reply("Queue cleared.")
Locked = False
@bot.on(events.NewMessage(pattern=f"/restart{bot_username}"))
async def _(event):
try:
app.restart()
except Exception as e:
await event.reply(e)
loop.run_until_complete(dl_ffmpeg())
bot.start()
bot.run_until_disconnected()