3
3
import re
4
4
import time
5
5
import asyncio
6
- from pyrogram import Client , filters , enums
6
+ from pyrogram import Client , filters
7
7
from pyrogram .types import Message
8
8
9
9
from subprocess import Popen , PIPE
@@ -26,6 +26,25 @@ async def compress(client: Client, message: Message):
26
26
if not replied .media :
27
27
await edit_or_reply (message , "<b>Please Reply To A Video</b>" )
28
28
return
29
+
30
+ media_type = replied .media .name
31
+ if media_type == "VIDEO" :
32
+ media = replied .video
33
+ elif media_type == "DOCUMENT" :
34
+ media = replied .document
35
+ mime_type = media .mime_type
36
+ if not mime_type .startswith ("video/" ):
37
+ await edit_or_reply (message , "<b>Unsupported media type</b>" )
38
+ return
39
+ else :
40
+ await edit_or_reply (message , "<b>Unsupported media type</b>" )
41
+ return
42
+
43
+ if media :
44
+ file_name = media .file_name .strip ().replace ("," , "" ).replace ("|" , "" )
45
+ else :
46
+ await edit_or_reply (message , f"<b>Unsupported media type</b>" )
47
+ return
29
48
if replied .media :
30
49
c_time = time .time ()
31
50
ms_ = await edit_or_reply (
@@ -34,9 +53,9 @@ async def compress(client: Client, message: Message):
34
53
)
35
54
file = await client .download_media (
36
55
message = replied ,
37
- file_name = "resources/" ,
56
+ file_name = f "resources/{ file_name } " ,
38
57
progress = pg ,
39
- progress_args = (ms_ , c_time , "` Downloading This File!` " ),
58
+ progress_args = (ms_ , c_time , "<code> Downloading This File!</code> " ),
40
59
)
41
60
# replied.media.duration
42
61
# d_time = time.time()
@@ -54,7 +73,7 @@ async def compress(client: Client, message: Message):
54
73
)
55
74
stdout = cmd_obj .communicate (timeout = 60 )
56
75
x , y = stdout
57
- if y and y .endswith ("NOT_FOUND" ):
76
+ if y and y .endswith (( "NOT_FOUND" , "not found" ) ):
58
77
return await edit_or_reply (message , f"ERROR: `{ y } `" )
59
78
total_frames = x .split (":" )[1 ].split ("\n " )[0 ]
60
79
try :
@@ -129,7 +148,7 @@ async def compress(client: Client, message: Message):
129
148
message .chat .id ,
130
149
out_file ,
131
150
progress = pg ,
132
- progress_args = (ms_ , c_time , "` Uploading...` " ),
151
+ progress_args = (ms_ , c_time , "<code> Uploading...</code> " ),
133
152
caption = f"<b>Original Size:</b> <code>{ humanbytes (file_size )} MB</code>\n <b>Compressed Size:</b> <code>{ humanbytes (out_file_size )} </code>\n <b>Compression Ratio:</b> <code>{ differ :.2f} %</code>\n <b>Time Taken To Compress:</b> <code>{ difff } </code>" ,
134
153
reply_to_message_id = message .id ,
135
154
)
@@ -139,6 +158,7 @@ async def compress(client: Client, message: Message):
139
158
f"<b>INFO:</b> <code>{ e } </code>" ,
140
159
)
141
160
finally :
161
+ await ms_ .delete ()
142
162
os .remove (file )
143
163
os .remove (out_file )
144
164
os .remove (progress )
0 commit comments