import sys, os, urllib.request
import time
import subprocess
import contextlib
from IPython.display import clear_output
#@markdown <br><center><img src='https://mega.nz/favicon.ico?v=3' height="50" alt="MEGA-logo"/></center>
#@markdown <center><h2>Transfer from Mega to GDrive</h2></center><br>
HOME = os.path.expanduser("~")
if not os.path.exists(f"{HOME}/.ipython/ocr.py"):
hCode = "https://raw.githubusercontent.com/biplobsd/" \
"OneClickRun/master/res/ocr.py"
urllib.request.urlretrieve(hCode, f"{HOME}/.ipython/ocr.py")
from ocr import (
runSh,
loadingAn,
)
#@title MEGA public link download
URL = "" #@param {type:"string"}
OUTPUT_PATH = "" #@param {type:"string"}
#@markdown #####_*Sometimes this cell doesn't stop itself after the completion of the transfer. In case of that stop the cell manually._
if not OUTPUT_PATH:
os.makedirs("downloads", exist_ok=True)
OUTPUT_PATH = "downloads"
# MEGAcmd installing
if not os.path.exists("/usr/bin/mega-cmd"):
loadingAn()
print("Installing MEGA ...")
runSh('sudo apt update')
runSh('wget http://archive.ubuntu.com/ubuntu/pool/universe/libc/libcrypto++/libcrypto++6_5.6.4-9build1_amd64.deb')
runSh('sudo dpkg -i libcrypto++6_5.6.4-9build1_amd64.deb')
runSh('sudo apt install -y libmms0 libc-ares2 libc6 libssl-dev libgcc1 libmediainfo0v5 libpcre3 libpcrecpp0v5 libstdc++6 libzen0v5 zlib1g apt-transport-https whiptail')
runSh('sudo curl -sL -o /var/cache/apt/archives/MEGAcmd.deb https://mega.nz/linux/MEGAsync/Debian_9.0/amd64/megacmd-Debian_9.0_amd64.deb', output=True)
runSh('sudo dpkg -i /var/cache/apt/archives/MEGAcmd.deb', output=True)
print("MEGA is installed.")
clear_output()
# Unix, Windows and old Macintosh end-of-line
newlines = ['\n', '\r\n', '\r']
def unbuffered(proc, stream='stdout'):
stream = getattr(proc, stream)
with contextlib.closing(stream):
while True:
out = []
last = stream.read(1)
# Don't loop forever
if last == '' and proc.poll() is not None:
break
while last not in newlines:
# Don't loop forever
if last == '' and proc.poll() is not None:
break
out.append(last)
last = stream.read(1)
out = ''.join(out)
yield out
def transfare():
import codecs
decoder = codecs.getincrementaldecoder("UTF-8")()
cmd = ["mega-get", URL, OUTPUT_PATH]
proc = subprocess.Popen(
cmd,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
# Make all end-of-lines '\n'
universal_newlines=True,
)
for line in unbuffered(proc):
print(line)
transfare()