-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathmain.py
More file actions
258 lines (219 loc) · 9.07 KB
/
Copy pathmain.py
File metadata and controls
258 lines (219 loc) · 9.07 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
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
import telethon
import requests
from telethon import events
from config import bot, bot_username, BASE, FFMPEG, FFMPEGCMD, FFMPEGID, DESTINATION, API_KEY, FOLDER_URL, FILE_URL
from FastTelethonhelper import fast_upload, fast_download
import subprocess
import asyncio
import utils
import os
Locked = True
queue = []
loop = asyncio.get_event_loop()
telethon.errors.rpc_errors_re += (('FLOOD_PREMIUM_WAIT_(\\d+)', telethon.errors.FloodWaitError),)
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:
name = event.raw_text.split(" ", 1)
if len(name) == 1:
name = None
else:
name = name[-1]
msg = await event.get_reply_message()
cmd = await bot.get_messages(FFMPEG, ids=FFMPEGCMD)
if '-1080' in event.text:
res = 1080
elif '-720' in event.text:
res = 720
elif '-360' in event.text:
res = 360
else:
res = "all"
r = await msg.reply("Downloading...")
file = await fast_download(client = bot, msg = msg, reply = r, download_folder = "./downloads/")
pfile = file.split("/")[-1]
if res == "all":
await utils.encode(msg, r, pfile, cmd, 1080, name.replace("RES", "1080p"))
await utils.encode(msg, r, pfile, cmd, 720, name.replace("RES", "720p"))
await utils.encode(msg, r, pfile, cmd, 360, name.replace("RES", "360p"))
else:
await utils.encode(msg, r, pfile, cmd, res, name)
os.remove(file)
await r.delete()
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((event.chat_id, msg.id))
await event.reply(f"Added to Queue \nQueue: {queue}")
@bot.on(events.NewMessage(pattern=f"/aq{bot_username}"))
async def _(event):
data = event.raw_text.split("\n")
start = int(data[1].split("/")[-1])
end = int(data[2].split("/")[-1])
chid = int(data[1].split("/")[-2])
for i in range(start, end+1):
queue.append((int(f"-100{chid}"), 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
name_format = event.raw_text.split("\n")[1]
start_ep = int(event.raw_text.split("\n")[2])
count = 0
for i in queue:
try:
msg = await bot.get_messages(i[0], ids=i[1])
cmd = await bot.get_messages(FFMPEG, ids=FFMPEGCMD)
r = await event.reply("Downloading...")
file = await fast_download(client = bot, msg = msg, reply = r, download_folder = "./downloads/")
pfile = file.split("/")[-1]
name = name_format.replace("UwU", str(start_ep + count))
count += 1
await utils.encode(msg, r, pfile, cmd, 360, name.replace("RES", "360p"))
await utils.encode(msg, r, pfile, cmd, 720, name.replace("RES", "720p"))
await utils.encode(msg, r, pfile, cmd, 1080, name.replace("RES", "1080p"))
os.remove(file)
await r.delete()
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"/download{bot_username}"))
async def _(event):
data = event.text.split(" ")
if "magnet" in data[1] or "torrent" in data[1]:
r = await event.reply("Downloading...")
f = await utils.download_torrent(data[1], r)
for root, subdirectories, files in os.walk('./downloads'):
for file in files:
f = os.path.join(root, file)
file = await fast_upload(bot, f, r)
await bot.send_message(event.chat_id, f, file=file, force_document= True)
utils.delete_files('downloads')
await r.delete()
elif "folder" in data[1]:
folder_id = data[1].split("/")[-1]
url = FOLDER_URL
url = url.replace("[FOLDER_ID]", folder_id)
r = requests.get(f"{url}{API_KEY}")
j = r.json()
main = await event.reply("STATUS:")
items = j['items'][::-1]
for i in items:
name = i['title']
file_id = i['id']
url = FILE_URL
url = url.replace("[FILE_ID]", file_id)
url = f"{url}{API_KEY}"
reply = await event.reply("Downloading...")
await main.edit(f"STATUS:\n`Downloading {name}`")
f = await utils.download_file(url, reply, file_name=name)
await main.edit(f"STATUS:\n`Uploading {name}`")
file = await fast_upload(bot, f"./downloads/{f}", reply)
await bot.send_message(event.chat_id, f, file=file, force_document= True)
await reply.delete()
os.remove(f"./downloads/{f}")
await main.edit("ALL FILES UPLOADED")
elif "file" in data[1]:
file_id = data[1].split("/")[-1]
url = FILE_URL
url = url.replace("[FILE_ID]", file_id)
url = f"{url}{API_KEY}"
info_url = FILE_URL
info_url = info_url.replace("[FILE_ID]", file_id)
info_url = info_url.replace("alt=media&", "")
r = requests.get(f"{info_url}{API_KEY}")
j = r.json()
name = j['name']
reply = await event.reply("Downloading...")
f = await utils.download_file(url, reply, file_name=name)
file = await fast_upload(bot, f"./downloads/{f}", reply)
await bot.send_message(event.chat_id, f, file=file, force_document= True)
await reply.delete()
os.remove(f"./downloads/{f}")
@bot.on(events.NewMessage(pattern=f"/sthumb{bot_username}"))
async def thumb(event):
x = await event.get_reply_message()
thumb = await bot.download_media(x.photo)
with open(thumb, "rb") as f:
pic = f.read()
with open("thumb.png", "wb") as f:
f.write(pic)
await event.reply("Set as default thumbnail")
@bot.on(events.NewMessage(pattern=f"/cthumb{bot_username}"))
async def clear_thumb(event):
with open("thumb.png", "w") as f:
f.write("")
await event.reply("cleared thumbnail")
@bot.on(events.NewMessage(pattern=f"/vthumb{bot_username}"))
async def view(event):
try:
await event.reply("current default thumbnail", file="thumb.png")
except:
await event.reply("No default thumbnail set")
loop.run_until_complete(dl_ffmpeg())
bot.start()
bot.run_until_disconnected()