Skip to content

Commit c7d943a

Browse files
Update compress.py
1 parent 956959c commit c7d943a

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

utils/compress.py

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import re
44
import time
55
import asyncio
6-
from pyrogram import Client, filters, enums
6+
from pyrogram import Client, filters
77
from pyrogram.types import Message
88

99
from subprocess import Popen, PIPE
@@ -26,6 +26,25 @@ async def compress(client: Client, message: Message):
2626
if not replied.media:
2727
await edit_or_reply(message, "<b>Please Reply To A Video</b>")
2828
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
2948
if replied.media:
3049
c_time = time.time()
3150
ms_ = await edit_or_reply(
@@ -34,9 +53,9 @@ async def compress(client: Client, message: Message):
3453
)
3554
file = await client.download_media(
3655
message=replied,
37-
file_name="resources/",
56+
file_name=f"resources/{file_name}",
3857
progress=pg,
39-
progress_args=(ms_, c_time, "`Downloading This File!`"),
58+
progress_args=(ms_, c_time, "<code>Downloading This File!</code>"),
4059
)
4160
# replied.media.duration
4261
# d_time = time.time()
@@ -54,7 +73,7 @@ async def compress(client: Client, message: Message):
5473
)
5574
stdout = cmd_obj.communicate(timeout=60)
5675
x, y = stdout
57-
if y and y.endswith("NOT_FOUND"):
76+
if y and y.endswith(("NOT_FOUND", "not found")):
5877
return await edit_or_reply(message, f"ERROR: `{y}`")
5978
total_frames = x.split(":")[1].split("\n")[0]
6079
try:
@@ -129,7 +148,7 @@ async def compress(client: Client, message: Message):
129148
message.chat.id,
130149
out_file,
131150
progress=pg,
132-
progress_args=(ms_, c_time, "`Uploading...`"),
151+
progress_args=(ms_, c_time, "<code>Uploading...</code>"),
133152
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>",
134153
reply_to_message_id=message.id,
135154
)
@@ -139,6 +158,7 @@ async def compress(client: Client, message: Message):
139158
f"<b>INFO:</b> <code>{e}</code>",
140159
)
141160
finally:
161+
await ms_.delete()
142162
os.remove(file)
143163
os.remove(out_file)
144164
os.remove(progress)

0 commit comments

Comments
 (0)