Skip to content

Commit ebfaf5e

Browse files
authored
Merge pull request #18 from thehellruler/main
Upgrade MegaDL
2 parents f68251f + e1ce519 commit ebfaf5e

File tree

2 files changed

+21
-58
lines changed

2 files changed

+21
-58
lines changed

colab_leecher/downlader/mega.py

Lines changed: 20 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -6,77 +6,39 @@
66
from datetime import datetime
77
from colab_leecher.utility.helper import status_bar
88
from colab_leecher.utility.variables import BotTimes, Messages, Paths
9-
9+
from pymegatools import Megatools,MegaError
1010

1111
async def megadl(link: str, num: int):
1212

1313
global BotTimes, Messages
1414
BotTimes.task_start = datetime.now()
15+
mega= Megatools()
16+
try:
17+
await mega.async_download(link,progress=pro_for_mega,path= Paths.down_path)
18+
except MegaError as e:
19+
logging.error(f"An Error occured : {e}")
1520

16-
# TODO: Check the type of link and set the commands accordingly. i.e, Check if private or public, file or folder
17-
18-
# Create a command to run megadl with the link
19-
command = [
20-
"megadl",
21-
"--no-ask-password",
22-
"--path",
23-
Paths.down_path,
24-
link,
25-
]
26-
27-
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, bufsize=0)
28-
29-
while True:
30-
output = process.stdout.readline() # Read output line by line # type: ignore
31-
if output == b'' and process.poll() is not None:
32-
break # Exit loop when process terminates and output is empty
33-
34-
try:
35-
await extract_info(output.strip().decode("utf-8"))
36-
except Exception as e:
37-
logging.error(f"{e}")
38-
39-
40-
async def extract_info(line):
4121

42-
# Split the line by colon and space
43-
parts = line.split(": ")
44-
subparts = []
45-
# Split the second part by space
46-
if len(parts) > 1:
47-
subparts = parts[1].split()
48-
22+
async def pro_for_mega(stream, process):
23+
line =stream[-1]
4924
file_name = "N/A"
50-
progress = "N/A"
25+
percentage = 0
5126
downloaded_size = "N/A"
5227
total_size = "N/A"
5328
speed = "N/A"
54-
55-
if len(subparts) > 10:
56-
57-
try:
58-
# Get the file name from the first part
59-
file_name = parts[0]
60-
Messages.download_name = file_name
61-
# Get the progress from the first subpart
62-
progress = subparts[0][:-1]
63-
# Get the downloaded size and bytes from the subpart
64-
downloaded_size = f"{subparts[2]} {subparts[3]}"
65-
# downloaded_bytes = subparts[4][1:-1]
66-
# Get the total size from the subpart
67-
total_size = f"{subparts[7]} {subparts[8]}"
68-
# Get the speed from the subpart
69-
speed = f"{subparts[9][1:]} {subparts[10][:-1]}"
70-
except Exception:
71-
logging.error(f"Got this \n{parts}")
72-
29+
try :
30+
ok =line.split(":")
31+
file_name = ok[0]
32+
ok=ok[1].split()
33+
percentage = float(ok[0][:-1])
34+
downloaded_size = ok[2]+" "+ok[3]
35+
total_size = ok[7]+" "+ok[8]
36+
speed = ok[9][1:]+" "+ok[10][:-1]
37+
except Exception:
38+
pass
39+
Messages.download_name = file_name
7340
Messages.status_head = f"<b>📥 DOWNLOADING FROM MEGA » </b>\n\n<b>🏷️ Name » </b><code>{file_name}</code>\n"
7441

75-
try:
76-
percentage = round(float(progress))
77-
except Exception:
78-
percentage = 0
79-
8042
await status_bar(
8143
Messages.status_head,
8244
speed,

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ requests
1515
tgcrypto
1616
uvloop
1717
yt_dlp
18+
pymegatools

0 commit comments

Comments
 (0)