-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcb_data.py
More file actions
184 lines (174 loc) · 7.11 KB
/
Copy pathcb_data.py
File metadata and controls
184 lines (174 loc) · 7.11 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
from helper.progress import progress_for_pyrogram
from pyrogram import Client, filters
from pyrogram.types import ( InlineKeyboardButton, InlineKeyboardMarkup,ForceReply)
from hachoir.metadata import extractMetadata
from hachoir.parser import createParser
from helper.database import find
import os
from PIL import Image
import time
@Client.on_callback_query(filters.regex('cancel'))
async def cancel(bot,update):
try:
await update.message.delete()
except:
return
@Client.on_callback_query(filters.regex('rename'))
async def rename(bot,update):
user_id = update.message.chat.id
date = update.message.date
await update.message.delete()
await update.message.reply_text("__Please enter the new filename...__",
reply_to_message_id=update.message.reply_to_message.message_id,
reply_markup=ForceReply(True))
@Client.on_callback_query(filters.regex("doc"))
async def doc(bot,update):
new_name = update.message.text
name = new_name.split(":-")
new_filename = name[1]
file_path = f"downloads/{new_filename}"
file = update.message.reply_to_message
ms = await update.message.edit("``` Trying To Download...```")
c_time = time.time()
try:
path = await bot.download_media(message = file, progress=progress_for_pyrogram,progress_args=( "``` Trying To Download...```", ms, c_time ))
except Exception as e:
await ms.edit(e)
return
splitpath = path.split("/downloads/")
dow_file_name = splitpath[1]
old_file_name =f"downloads/{dow_file_name}"
os.rename(old_file_name,file_path)
user_id = int(update.message.chat.id)
thumb = find(user_id)
if thumb:
ph_path = await bot.download_media(thumb)
Image.open(ph_path).convert("RGB").save(ph_path)
img = Image.open(ph_path)
img.resize((320, 320))
img.save(ph_path, "JPEG")
c_time = time.time()
await ms.edit("```Trying To Uploading```")
c_time = time.time()
try:
await bot.send_document(update.message.chat.id,document = file_path,thumb=ph_path,caption = f"**{new_filename}**",progress=progress_for_pyrogram,progress_args=( "```Trying To Uploading```", ms, c_time ))
await ms.delete()
os.remove(file_path)
os.remove(ph_path)
except Exception as e:
await ms.edit(e)
os.remove(file_path)
os.remove(ph_path)
else:
await ms.edit("```Trying To Uploading```")
c_time = time.time()
try:
await bot.send_document(update.message.chat.id,document = file_path,caption = f"**{new_filename}**",progress=progress_for_pyrogram,progress_args=( "```Trying To Uploading```", ms, c_time ))
await ms.delete()
os.remove(file_path)
except Exception as e:
await ms.edit(e)
os.remove(file_path)
@Client.on_callback_query(filters.regex("vid"))
async def vid(bot,update):
new_name = update.message.text
name = new_name.split(":-")
new_filename = name[1]
file_path = f"downloads/{new_filename}"
file = update.message.reply_to_message
ms = await update.message.edit("``` Trying To Download...```")
c_time = time.time()
try:
path = await bot.download_media(message = file, progress=progress_for_pyrogram,progress_args=( "``` Trying To Download...```", ms, c_time ))
except Exception as e:
await ms.edit(e)
return
splitpath = path.split("/downloads/")
dow_file_name = splitpath[1]
old_file_name =f"downloads/{dow_file_name}"
os.rename(old_file_name,file_path)
duration = 0
metadata = extractMetadata(createParser(file_path))
if metadata.has("duration"):
duration = metadata.get('duration').seconds
user_id = int(update.message.chat.id)
thumb = find(user_id)
if thumb:
ph_path = await bot.download_media(thumb)
Image.open(ph_path).convert("RGB").save(ph_path)
img = Image.open(ph_path)
img.resize((320, 320))
img.save(ph_path, "JPEG")
c_time = time.time()
await ms.edit("```Trying To Uploading```")
c_time = time.time()
try:
await bot.send_video(update.message.chat.id,video = file_path,caption = f"**{new_filename}**",thumb=ph_path,duration =duration, progress=progress_for_pyrogram,progress_args=( "```Trying To Uploading```", ms, c_time ))
await ms.delete()
os.remove(file_path)
os.remove(ph_path)
except Exception as e:
await ms.edit(e)
os.remove(file_path)
os.remove(ph_path)
else:
await ms.edit("```Trying To Uploading```")
c_time = time.time()
try:
await bot.send_video(update.message.chat.id,video = file_path,caption = f"**{new_filename}**",duration = duration, progress=progress_for_pyrogram,progress_args=( "```Trying To Uploading```", ms, c_time ))
await ms.delete()
os.remove(file_path)
except Exception as e:
await ms.edit(e)
os.remove(file_path)
@Client.on_callback_query(filters.regex("aud"))
async def aud(bot,update):
new_name = update.message.text
name = new_name.split(":-")
new_filename = name[1]
file_path = f"downloads/{new_filename}"
file = update.message.reply_to_message
ms = await update.message.edit("``` Trying To Download...```")
c_time = time.time()
try:
path = await bot.download_media(message = file , progress=progress_for_pyrogram,progress_args=( "``` Trying To Download...```", ms, c_time ))
except Exception as e:
await ms.edit(e)
return
splitpath = path.split("/downloads/")
dow_file_name = splitpath[1]
old_file_name =f"downloads/{dow_file_name}"
os.rename(old_file_name,file_path)
duration = 0
metadata = extractMetadata(createParser(file_path))
if metadata.has("duration"):
duration = metadata.get('duration').seconds
user_id = int(update.message.chat.id)
thumb = find(user_id)
if thumb:
ph_path = await bot.download_media(thumb)
Image.open(ph_path).convert("RGB").save(ph_path)
img = Image.open(ph_path)
img.resize((320, 320))
img.save(ph_path, "JPEG")
await ms.edit("```Trying To Uploading```")
c_time = time.time()
try:
await bot.send_audio(update.message.chat.id,audio = file_path,caption = f"**{new_filename}**",thumb=ph_path,duration =duration, progress=progress_for_pyrogram,progress_args=( "```Trying To Uploading```", ms, c_time ))
await ms.delete()
os.remove(file_path)
os.remove(ph_path)
except Exception as e:
await ms.edit(e)
os.remove(file_path)
os.remove(ph_path)
else:
await ms.edit("```Trying To Uploading```")
c_time = time.time()
try:
await bot.send_audio(update.message.chat.id,audio = file_path,caption = f"**{new_filename}**",duration = duration, progress=progress_for_pyrogram,progress_args=( "```Trying To Uploading```", ms, c_time ))
await ms.delete()
os.remove(file_path)
except Exception as e:
await ms.edit(e)
os.remove(file_path)