-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmega_manager.py
More file actions
30 lines (23 loc) · 877 Bytes
/
mega_manager.py
File metadata and controls
30 lines (23 loc) · 877 Bytes
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
import subprocess
import time
from pathlib import Path
from config import DOWNLOAD_DIR, MEGA_LINK, QUOTA_SLEEP_SECONDS
def download_with_quota_handling():
Path(DOWNLOAD_DIR).mkdir(parents=True, exist_ok=True)
while True:
print("Starting / resuming MEGA download...")
proc = subprocess.run(
["mega-get", MEGA_LINK, DOWNLOAD_DIR],
capture_output=True,
text=True
)
output = (proc.stdout + proc.stderr).lower()
if "quota" in output or "exceeded" in output:
print("MEGA quota reached. Waiting...")
time.sleep(QUOTA_SLEEP_SECONDS)
continue
if proc.returncode == 0:
print("MEGA download completed.")
break
print("Temporary MEGA error. Retrying in 10 minutes...")
time.sleep(600)