-
Notifications
You must be signed in to change notification settings - Fork 3k
Expand file tree
/
Copy pathpyroplug.py
More file actions
217 lines (208 loc) · 9.24 KB
/
pyroplug.py
File metadata and controls
217 lines (208 loc) · 9.24 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
#Github.com-Vasusen-code
import asyncio, time, os
from .. import bot as Drone
from main.plugins.progress import progress_for_pyrogram
from main.plugins.helpers import screenshot
from pyrogram import Client, filters
from pyrogram.errors import ChannelBanned, ChannelInvalid, ChannelPrivate, ChatIdInvalid, ChatInvalid, PeerIdInvalid
from pyrogram.enums import MessageMediaType
from ethon.pyfunc import video_metadata
from ethon.telefunc import fast_upload
from telethon.tl.types import DocumentAttributeVideo
from telethon import events
def thumbnail(sender):
if os.path.exists(f'{sender}.jpg'):
return f'{sender}.jpg'
else:
return None
async def get_msg(userbot, client, bot, sender, edit_id, msg_link, i):
""" userbot: PyrogramUserBot
client: PyrogramBotClient
bot: TelethonBotClient """
edit = ""
chat = ""
round_message = False
if "?single" in msg_link:
msg_link = msg_link.split("?single")[0]
msg_id = int(msg_link.split("/")[-1]) + int(i)
height, width, duration, thumb_path = 90, 90, 0, None
if 't.me/c/' in msg_link or 't.me/b/' in msg_link:
if 't.me/b/' in msg_link:
chat = str(msg_link.split("/")[-2])
else:
chat = int('-100' + str(msg_link.split("/")[-2]))
file = ""
try:
msg = await userbot.get_messages(chat, msg_id)
if msg.media:
if msg.media==MessageMediaType.WEB_PAGE:
edit = await client.edit_message_text(sender, edit_id, "Cloning.")
await client.send_message(sender, msg.text.markdown)
await edit.delete()
return
if not msg.media:
if msg.text:
edit = await client.edit_message_text(sender, edit_id, "Cloning.")
await client.send_message(sender, msg.text.markdown)
await edit.delete()
return
edit = await client.edit_message_text(sender, edit_id, "Trying to Download.")
file = await userbot.download_media(
msg,
progress=progress_for_pyrogram,
progress_args=(
client,
"**DOWNLOADING:**\n",
edit,
time.time()
)
)
print(file)
await edit.edit('Preparing to Upload!')
caption = None
if msg.caption is not None:
caption = msg.caption
if msg.media==MessageMediaType.VIDEO_NOTE:
round_message = True
print("Trying to get metadata")
data = video_metadata(file)
height, width, duration = data["height"], data["width"], data["duration"]
print(f'd: {duration}, w: {width}, h:{height}')
try:
thumb_path = await screenshot(file, duration, sender)
except Exception:
thumb_path = None
await client.send_video_note(
chat_id=sender,
video_note=file,
length=height, duration=duration,
thumb=thumb_path,
progress=progress_for_pyrogram,
progress_args=(
client,
'**UPLOADING:**\n',
edit,
time.time()
)
)
elif msg.media==MessageMediaType.VIDEO and msg.video.mime_type in ["video/mp4", "video/x-matroska"]:
print("Trying to get metadata")
data = video_metadata(file)
height, width, duration = data["height"], data["width"], data["duration"]
print(f'd: {duration}, w: {width}, h:{height}')
try:
thumb_path = await screenshot(file, duration, sender)
except Exception:
thumb_path = None
await client.send_video(
chat_id=sender,
video=file,
caption=caption,
supports_streaming=True,
height=height, width=width, duration=duration,
thumb=thumb_path,
progress=progress_for_pyrogram,
progress_args=(
client,
'**UPLOADING:**\n',
edit,
time.time()
)
)
elif msg.media==MessageMediaType.PHOTO:
await edit.edit("Uploading photo.")
await bot.send_file(sender, file, caption=caption)
else:
thumb_path=thumbnail(sender)
await client.send_document(
sender,
file,
caption=caption,
thumb=thumb_path,
progress=progress_for_pyrogram,
progress_args=(
client,
'**UPLOADING:**\n',
edit,
time.time()
)
)
try:
os.remove(file)
if os.path.isfile(file) == True:
os.remove(file)
except Exception:
pass
await edit.delete()
except (ChannelBanned, ChannelInvalid, ChannelPrivate, ChatIdInvalid, ChatInvalid):
await client.edit_message_text(sender, edit_id, "Have you joined the channel?")
return
except PeerIdInvalid:
chat = msg_link.split("/")[-3]
try:
int(chat)
new_link = f"t.me/c/{chat}/{msg_id}"
except:
new_link = f"t.me/b/{chat}/{msg_id}"
return await get_msg(userbot, client, bot, sender, edit_id, msg_link, i)
except Exception as e:
print(e)
if "messages.SendMedia" in str(e) \
or "SaveBigFilePartRequest" in str(e) \
or "SendMediaRequest" in str(e) \
or str(e) == "File size equals to 0 B":
try:
if msg.media==MessageMediaType.VIDEO and msg.video.mime_type in ["video/mp4", "video/x-matroska"]:
UT = time.time()
uploader = await fast_upload(f'{file}', f'{file}', UT, bot, edit, '**UPLOADING:**')
attributes = [DocumentAttributeVideo(duration=duration, w=width, h=height, round_message=round_message, supports_streaming=True)]
await bot.send_file(sender, uploader, caption=caption, thumb=thumb_path, attributes=attributes, force_document=False)
elif msg.media==MessageMediaType.VIDEO_NOTE:
uploader = await fast_upload(f'{file}', f'{file}', UT, bot, edit, '**UPLOADING:**')
attributes = [DocumentAttributeVideo(duration=duration, w=width, h=height, round_message=round_message, supports_streaming=True)]
await bot.send_file(sender, uploader, caption=caption, thumb=thumb_path, attributes=attributes, force_document=False)
else:
UT = time.time()
uploader = await fast_upload(f'{file}', f'{file}', UT, bot, edit, '**UPLOADING:**')
await bot.send_file(sender, uploader, caption=caption, thumb=thumb_path, force_document=True)
if os.path.isfile(file) == True:
os.remove(file)
except Exception as e:
print(e)
await client.edit_message_text(sender, edit_id, f'Failed to save: `{msg_link}`\n\nError: {str(e)}')
try:
os.remove(file)
except Exception:
return
return
else:
await client.edit_message_text(sender, edit_id, f'Failed to save: `{msg_link}`\n\nError: {str(e)}')
try:
os.remove(file)
except Exception:
return
return
try:
os.remove(file)
if os.path.isfile(file) == True:
os.remove(file)
except Exception:
pass
await edit.delete()
else:
edit = await client.edit_message_text(sender, edit_id, "Cloning.")
chat = msg_link.split("t.me")[1].split("/")[1]
try:
msg = await client.get_messages(chat, msg_id)
if msg.empty:
new_link = f't.me/b/{chat}/{int(msg_id)}'
#recurrsion
return await get_msg(userbot, client, bot, sender, edit_id, new_link, i)
await client.copy_message(sender, chat, msg_id)
except Exception as e:
print(e)
return await client.edit_message_text(sender, edit_id, f'Failed to save: `{msg_link}`\n\nError: {str(e)}')
await edit.delete()
async def get_bulk_msg(userbot, client, sender, msg_link, i):
x = await client.send_message(sender, "Processing!")
await get_msg(userbot, client, Drone, sender, x.id, msg_link, i)