Skip to content
This repository was archived by the owner on Sep 29, 2021. It is now read-only.

Commit 9a34ae2

Browse files
committed
Issue: Fixed mega corupt file not shown
Huge thanks @adekmaulana for fixing Signed-off-by: MoveAngel <[email protected]>
1 parent 9bd313f commit 9a34ae2

File tree

2 files changed

+24
-16
lines changed

2 files changed

+24
-16
lines changed

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,4 @@ urbandict>=0.5
4444
wikipedia>=1.4.0
4545
coffeehouse
4646
wget
47+
python-dateutil

userbot/modules/mega_downloader.py

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,24 @@
2626
import wget
2727
import os
2828

29+
from os.path import exists
30+
2931
from userbot import CMD_HELP
3032
from userbot.events import register
3133

3234

3335
def subprocess_run(cmd):
36+
reply = ''
3437
subproc = Popen(cmd, stdout=PIPE, stderr=PIPE,
3538
shell=True, universal_newlines=True)
3639
talk = subproc.communicate()
3740
exitCode = subproc.returncode
3841
if exitCode != 0:
39-
print('An error was detected while running the subprocess:\n'
40-
'exit code: %d\n'
41-
'stdout: %s\n'
42-
'stderr: %s' % (exitCode, talk[0], talk[1]))
42+
reply += ('An error was detected while running the subprocess:\n'
43+
f'exit code: {exitCode}\n'
44+
f'stdout: {talk[0]}\n'
45+
f'stderr: {talk[1]}')
46+
return reply
4347
return talk
4448

4549

@@ -75,7 +79,6 @@ def mega_download(url: str) -> str:
7579
result = subprocess_run(cmd)
7680
try:
7781
data = json.loads(result[0])
78-
print(data)
7982
except json.JSONDecodeError:
8083
reply += "`Error: Can't extract the link`\n"
8184
return reply
@@ -84,22 +87,26 @@ def mega_download(url: str) -> str:
8487
file_url = data['url']
8588
file_hex = data['hex']
8689
file_raw_hex = data['raw_hex']
87-
if wget.download(file_url, out=file_name):
88-
encrypt_file(file_name, file_hex, file_raw_hex)
89-
reply += (f"`{file_name}`\n"
90-
f"Size: {file_size}\n"
91-
"\n"
92-
"Successfully downloaded...")
93-
else:
94-
reply += "Failed to download..."
90+
if exists(file_name):
91+
os.remove(file_name)
92+
if not exists(file_name):
93+
wget.download(file_url, out=file_name)
94+
if exists(file_name):
95+
encrypt_file(file_name, file_hex, file_raw_hex)
96+
reply += (f"`{file_name}`\n"
97+
f"Size: {file_size}\n\n"
98+
"Successfully downloaded...")
99+
else:
100+
reply += "Failed to download..."
95101
return reply
96102

97103

98104
def encrypt_file(file_name, file_hex, file_raw_hex):
99-
os.rename(file_name, f"old_{file_name}")
100-
cmd = f"cat old_{file_name} | openssl enc -d -aes-128-ctr -K {file_hex} -iv {file_raw_hex} > {file_name}"
105+
os.rename(file_name, r"old_{}".format(file_name))
106+
cmd = ("cat 'old_{}' | openssl enc -d -aes-128-ctr -K {} -iv {} > '{}'"
107+
.format(file_name, file_hex, file_raw_hex, file_name))
101108
subprocess_run(cmd)
102-
os.remove(f"old_{file_name}")
109+
os.remove(r"old_{}".format(file_name))
103110
return
104111

105112

0 commit comments

Comments
 (0)