Пример #1
0
#-*- encoding:utf-8 -*-
__author__ = ''
import sys
import os
from pySmartDL import SmartDL


dirs = "E:\\coral reefs data\\reef genome sumup\\"
urls = "http://mirror.ufs.ac.za/7zip/9.20/7za920.zip"
#sys.path.append('../')
# from my_lib import download_kits
# state_d = download_kits.download(urls,dirs)
obj = SmartDL(urls, dirs)
obj.start()
path = obj.get_dest()
Пример #2
0
async def _(event):
    if event.fwd_from:
        return
    mone = await event.reply("Processing ...")
    input_str = event.pattern_match.group(1)
    if not os.path.isdir(Config.TMP_DOWNLOAD_DIRECTORY):
        os.makedirs(Config.TMP_DOWNLOAD_DIRECTORY)
    if event.reply_to_msg_id:
        start = datetime.now()
        reply_message = await event.get_reply_message()
        try:
            c_time = time.time()
            downloaded_file_name = await borg.download_media(
                reply_message,
                Config.TMP_DOWNLOAD_DIRECTORY,
                progress_callback=lambda d, t: asyncio.get_event_loop().
                create_task(progress(d, t, mone, c_time, "trying to download"))
            )
        except Exception as e:  # pylint:disable=C0103,W0703
            await mone.edit(str(e))
        else:
            end = datetime.now()
            ms = (end - start).seconds
            await mone.edit("Downloaded to `{}` in {} seconds.".format(
                downloaded_file_name, ms))
    elif input_str:
        start = datetime.now()
        url = input_str
        file_name = os.path.basename(url)
        to_download_directory = Config.TMP_DOWNLOAD_DIRECTORY
        if "|" in input_str:
            url, file_name = input_str.split("|")
        url = url.strip()
        file_name = file_name.strip()
        downloaded_file_name = os.path.join(to_download_directory, file_name)
        downloader = SmartDL(url, downloaded_file_name, progress_bar=False)
        downloader.start(blocking=False)
        c_time = time.time()
        while not downloader.isFinished():
            total_length = downloader.filesize if downloader.filesize else None
            downloaded = downloader.get_dl_size()
            display_message = ""
            now = time.time()
            diff = now - c_time
            percentage = downloader.get_progress() * 100
            speed = downloader.get_speed()
            elapsed_time = round(diff) * 1000
            progress_str = "{0}{1}\nProgress: {2}%".format(
                ''.join(["█" for i in range(math.floor(percentage / 5))]),
                ''.join(["░" for i in range(20 - math.floor(percentage / 5))]),
                round(percentage, 2))
            estimated_total_time = downloader.get_eta(human=True)
            try:
                current_message = f"trying to download\nURL: {url}\nFile Name: {file_name}\n{progress_str}\n{humanbytes(downloaded)} of {humanbytes(total_length)}\nETA: {estimated_total_time}"
                if round(diff %
                         10.00) == 0 and current_message != display_message:
                    await mone.edit(current_message)
                    display_message = current_message
            except Exception as e:
                logger.info(str(e))
        end = datetime.now()
        ms = (end - start).seconds
        if downloader.isSuccessful():
            await mone.edit(
                "lapnlbot has downloaded it to `{}` in {} seconds.".format(
                    downloaded_file_name, ms))
        else:
            await mone.edit("Incorrect URL\n {}".format(input_str))
    else:
        await mone.edit(
            "Reply to a message for lapnlbot to download to your local server."
        )
Пример #3
0
async def download(target_file):
    """ For .download command, download files to the userbot's server. """
    await target_file.edit("Processing ...")
    input_str = target_file.pattern_match.group(1)
    if not os.path.isdir(TEMP_DOWNLOAD_DIRECTORY):
        os.makedirs(TEMP_DOWNLOAD_DIRECTORY)
    if "|" in input_str:
        url, file_name = input_str.split("|")
        url = url.strip()
        # https://stackoverflow.com/a/761825/4723940
        file_name = file_name.strip()
        head, tail = os.path.split(file_name)
        if head:
            if not os.path.isdir(os.path.join(TEMP_DOWNLOAD_DIRECTORY, head)):
                os.makedirs(os.path.join(TEMP_DOWNLOAD_DIRECTORY, head))
                file_name = os.path.join(head, tail)
        downloaded_file_name = TEMP_DOWNLOAD_DIRECTORY + "" + file_name
        downloader = SmartDL(url, downloaded_file_name, progress_bar=False)
        downloader.start(blocking=False)
        c_time = time.time()
        display_message = None
        while not downloader.isFinished():
            status = downloader.get_status().capitalize()
            total_length = downloader.filesize if downloader.filesize else None
            downloaded = downloader.get_dl_size()
            now = time.time()
            diff = now - c_time
            percentage = downloader.get_progress() * 100
            speed = downloader.get_speed()
            progress_str = "[{0}{1}] `{2}%`".format(
                "".join(["●" for i in range(math.floor(percentage / 10))]),
                "".join(["○"
                         for i in range(10 - math.floor(percentage / 10))]),
                round(percentage, 2),
            )
            estimated_total_time = downloader.get_eta(human=True)
            try:
                current_message = (
                    f"`Name` : `{file_name}`\n"
                    "Status"
                    f"\n**{status}**... | {progress_str}"
                    f"\n{humanbytes(downloaded)} of {humanbytes(total_length)}"
                    f" @ {humanbytes(speed)}"
                    f"\n`ETA` -> {estimated_total_time}")

                if round(diff %
                         10.00) == 0 and current_message != display_message:
                    await target_file.edit(current_message)
                    display_message = current_message
            except Exception as e:
                LOGS.info(str(e))
        if downloader.isSuccessful():
            await target_file.edit("Downloaded to `{}` successfully !!".format(
                downloaded_file_name))
        else:
            await target_file.edit("Incorrect URL\n{}".format(url))
    elif target_file.reply_to_msg_id:
        try:
            replied = await target_file.get_reply_message()
            media = replied.media
            if hasattr(media, "document"):
                file = media.document
                mime_type = file.mime_type
                attribs = file.attributes
                for attr in attribs:
                    if isinstance(attr, DocumentAttributeFilename):
                        filename = attr.file_name
                    elif "audio" in mime_type:
                        filename = "audio-" + str(datetime.now()) + ".ogg"
                    elif "video" in mime_type:
                        filename = "video-" + str(datetime.now()) + ".mp4"
                outdir = TEMP_DOWNLOAD_DIRECTORY + filename
                c_time = time.time()
                start_time = datetime.now()
                with open(outdir, "wb") as f:
                    result = await download_file(
                        client=target_file.client,
                        location=file,
                        out=f,
                        progress_callback=lambda d, t: asyncio.get_event_loop(
                        ).create_task(
                            progress(d, t, target_file, c_time, "[DOWNLOAD]",
                                     input_str)),
                    )
            else:
                start_time = datetime.now()
                result = await target_file.client.download_media(
                    media, TEMP_DOWNLOAD_DIRECTORY)
            dl_time = (datetime.now() - start_time).seconds
        except Exception as e:  # pylint:disable=C0103,W0703
            await target_file.edit(str(e))
        else:
            try:
                await target_file.edit(
                    "Downloaded to `{}` in `{}` seconds.".format(
                        result.name, dl_time))
            except AttributeError:
                await target_file.edit(
                    "Downloaded to `{}` in `{}` seconds.".format(
                        result, dl_time))
    else:
        await target_file.edit(
            "Reply to a message to download to my local server.")
Пример #4
0
 async def upload(self) -> None:
     """Upload from file/folder/link/tg file to GDrive"""
     if not os.path.isdir(Config.DOWN_PATH):
         os.mkdir(Config.DOWN_PATH)
     replied = self._message.reply_to_message
     is_url = re.search(r"(?:https?|ftp)://[^\|\s]+\.[^\|\s]+",
                        self._message.input_str)
     dl_loc = None
     if replied and replied.media:
         await self._message.edit("`Downloading From TG...`")
         c_time = time.time()
         dl_loc = await userge.download_media(
             message=replied,
             file_name=Config.DOWN_PATH,
             progress=progress,
             progress_args=("trying to download", userge, self._message,
                            c_time))
         if self._message.process_is_canceled:
             await self._message.edit("`Process Canceled!`", del_in=5)
             return
         else:
             dl_loc = os.path.join(Config.DOWN_PATH,
                                   os.path.basename(dl_loc))
     elif is_url:
         await self._message.edit("`Downloading From URL...`")
         url = is_url[0]
         file_name = os.path.basename(url)
         if "|" in self._message.input_str:
             file_name = self._message.input_str.split("|")[1].strip()
         dl_loc = os.path.join(Config.DOWN_PATH, file_name)
         try:
             downloader = SmartDL(url, dl_loc, progress_bar=False)
             downloader.start(blocking=False)
             count = 0
             while not downloader.isFinished():
                 if self._message.process_is_canceled:
                     downloader.stop()
                     raise Exception('Process Canceled!')
                 total_length = downloader.filesize if downloader.filesize else 0
                 downloaded = downloader.get_dl_size()
                 percentage = downloader.get_progress() * 100
                 speed = downloader.get_speed(human=True)
                 estimated_total_time = downloader.get_eta(human=True)
                 progress_str = \
                     "__{}__\n" + \
                     "```[{}{}]```\n" + \
                     "**Progress** : `{}%`\n" + \
                     "**URL** : `{}`\n" + \
                     "**FILENAME** : `{}`\n" + \
                     "**Completed** : `{}`\n" + \
                     "**Total** : `{}`\n" + \
                     "**Speed** : `{}`\n" + \
                     "**ETA** : `{}`"
                 progress_str = progress_str.format(
                     "trying to download", ''.join(
                         ["█" for i in range(math.floor(percentage / 5))]),
                     ''.join([
                         "░" for i in range(20 - math.floor(percentage / 5))
                     ]), round(percentage,
                               2), url, file_name, humanbytes(downloaded),
                     humanbytes(total_length), speed, estimated_total_time)
                 count += 1
                 if count >= 5:
                     count = 0
                     await self._message.try_to_edit(
                         progress_str, disable_web_page_preview=True)
                 await asyncio.sleep(1)
         except Exception as d_e:
             await self._message.err(d_e)
             return
     upload_file_name = dl_loc if dl_loc else self._message.input_str
     if not os.path.exists(upload_file_name):
         await self._message.err("invalid file path provided?")
         return
     await self._message.edit("`Loading GDrive Upload...`")
     pool.submit_thread(self._upload, upload_file_name)
     start_t = datetime.now()
     count = 0
     while not self._is_finished:
         count += 1
         if self._message.process_is_canceled:
             self._cancel()
         if self._progress is not None and count >= 5:
             count = 0
             await self._message.try_to_edit(self._progress)
         await asyncio.sleep(1)
     if dl_loc and os.path.exists(dl_loc):
         os.remove(dl_loc)
     end_t = datetime.now()
     m_s = (end_t - start_t).seconds
     if isinstance(self._output, HttpError):
         out = f"**ERROR** : `{self._output._get_reason()}`"
     elif self._output is not None and not self._is_canceled:
         out = f"**Uploaded Successfully** __in {m_s} seconds__\n\n{self._output}"
     elif self._output is not None and self._is_canceled:
         out = self._output
     else:
         out = "`failed to upload.. check logs?`"
     await self._message.edit(out, disable_web_page_preview=True, log=True)
Пример #5
0
def savndl(update, context):
    global res
    global input_url
    update.message.reply_text(text="⏳ Wait a beet...")
    # context.bot.send_message(chat_id= update.message.chat_id,text= '⏳ Wait a beet...')

    rawurl = update.message.text.strip()
    rawurl = rawurl.split()
    input_url = rawurl[-1]
    try:
        proxies, headers = setProxy()
        res = requests.get(input_url, proxies=proxies, headers=headers)
        # context.bot.send_message(chat_id= update.message.chat_id,text= 'Enter req Try .')
    except Exception as e:
        logger.error('Error accessing website error: ' + e)

    soup = BeautifulSoup(res.text, "lxml")

    #Not Working For single song
    try:
        getPlayListID = soup.select(".flip-layout")[0]["data-listid"]
        if getPlayListID is not None:
            print("Initiating PlayList Downloading")
            # context.bot.send_message(chat_id= update.message.chat_id,text= 'Initiating PlayList Downloading')
            downloadSongs(getPlayList(getPlayListID), update, context)
            try:
                # context.bot.send_message(chat_id= update.message.chat_id,text= 'Uploading Your File.....')
                context.bot.send_document(chat_id=update.message.chat_id,
                                          document=open(location, 'rb'),
                                          caption=filename)
                print("Trying To Remove File...")
                # try:
                #     os.remove(location)
                #     print("Playlist  cleaned")
                # except Exception as e:
                #     print("ERROR REMOVING : ",e)

            except Exception as e:
                context.bot.send_message(chat_id=update.message.chat_id,
                                         text="Uploaing Fail : \n" + e)

        print("done", filename)
        context.bot.send_message(chat_id=update.message.chat_id, text=filename)
    except Exception as e:
        print(
            'Download Error code 132x Playlist Id  not received (May Be its a single song):',
            e)

    #NoT WORKING  FOR SINGLE SONG
    try:
        getAlbumID = soup.select(".play")[0]["onclick"]
        getAlbumID = ast.literal_eval(
            re.search("\[(.*?)\]", getAlbumID).group())[1]
        if getAlbumID is not None:
            print("Initiating Album Downloading")
            # context.bot.send_message(chat_id= update.message.chat_id,text= 'Initiating Album Downloading')
            try:
                downloadSongs(getAlbum(getAlbumID), update, context)
            except Exception as e:
                print("ENTING DOWNLOADING Fun :" + e)
                downloadSongs(getAlbum(getAlbumID))
            # context.bot.send_message(chat_id=update.message.chat_id,text ="Downloading YoUr file : "+location+filename)
            try:
                ####uploading single file (now this uploading moved to download function)######

                # context.bot.send_message(chat_id = update.message.chat_id,message ="Uploading your Song")
                # context.bot.send_document(chat_id =update.message.chat_id,document=open(location, 'rb'),caption = filename)
                try:
                    os.remove(location)
                    print("File Clean")
                except Exception as e:
                    print("ERROR REMOVING : ", e)
            except Exception as e:
                print("UPLOADING ERROR : ", e)
                print(location)
                context.bot.send_message(chat_id=update.message.chat_id,
                                         text=e)
            # sys.exit()
        # context.bot.send_message(chat_id= update.message.chat_id,text= 'entered playlist 1 if DONE PART.')
    except Exception as e:
        print('ERROR 112X AlbumId  not received (Its may Be a single song):',
              e)

        proxy_ip = ''
        # set http_proxy from environment
        if ('http_proxy' in os.environ):
            proxy_ip = os.environ['http_proxy']

        proxies = {
            'http': proxy_ip,
            'https': proxy_ip,
        }
        # proxy setup end here

        headers = {
            'User-Agent':
            'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:49.0) Gecko/20100101 Firefox/49.0'
        }
        base_url = 'http://h.saavncdn.com'
        json_decoder = JSONDecoder()

        # Key and IV are coded in plaintext in the app when decompiled
        # and its preety insecure to decrypt urls to the mp3 at the client side
        # these operations should be performed at the server side.
        des_cipher = des(b"38346591",
                         ECB,
                         b"\0\0\0\0\0\0\0\0",
                         pad=None,
                         padmode=PAD_PKCS5)

        # raw_input =input
        # input_url = raw_input('Enter the song url:').strip()

        print(update.message.text)
        input_url = update.message.text.strip()

        try:
            res = requests.get(input_url, proxies=proxies, headers=headers)
        except Exception as e:
            print('Error accesssing website error: ' + e)
            sys.exit()

        soup = BeautifulSoup(res.text, "lxml")

        # Encrypted url to the mp3 are stored in the webpage
        songs_json = soup.find_all('div', {'class': 'hide song-json'})

        for song in songs_json:
            obj = json_decoder.decode(song.text)
            print(obj['album'], '-', obj['title'])
            filename = obj['title'] + '.mp3'
            filename = filename.replace("\"", "'")
            # print("ENC URL :",obj['url'])
            enc_url = base64.b64decode(obj['url'].strip())
            print("DEC URL :", enc_url)
            dec_url = des_cipher.decrypt(enc_url,
                                         padmode=PAD_PKCS5).decode('utf-8')
            print("DEC  :", dec_url)
            dec_url = base_url + dec_url.replace('mp3:audios', '') + '.mp3'
            print(dec_url, '\n')
            # context.bot.send_message(chat_id=update.message.chat_id, text=dec_url)
            print("Downloading %s" % filename)
            location = os.path.join(os.path.sep, os.getcwd(), "songs",
                                    filename)
            obj = SmartDL(dec_url, location)
            obj.start()
            context.bot.send_document(chat_id=update.message.chat_id,
                                      document=open(location, 'rb'),
                                      caption=filename)
            os.remove(location)
            break
async def download(target_file):
    """ For .download command, download files to the userbot's server. """
    if not target_file.text[0].isalpha() and target_file.text[0] not in ("/", "#", "@", "!"):
        if target_file.fwd_from:
            return
        await target_file.edit("Processing ...")
        input_str = target_file.pattern_match.group(1)
        if not os.path.isdir(TEMP_DOWNLOAD_DIRECTORY):
            os.makedirs(TEMP_DOWNLOAD_DIRECTORY)
        if "|" in input_str:
            start = datetime.now()
            url, file_name = input_str.split("|")
            url = url.strip()
            # https://stackoverflow.com/a/761825/4723940
            file_name = file_name.strip()
            head, tail = os.path.split(file_name)
            if head:
                if not os.path.isdir(os.path.join(TEMP_DOWNLOAD_DIRECTORY, head)):
                    os.makedirs(os.path.join(TEMP_DOWNLOAD_DIRECTORY, head))
                    file_name = os.path.join(head, tail)
            downloaded_file_name = TEMP_DOWNLOAD_DIRECTORY + "" + file_name
            downloader = SmartDL(url, downloaded_file_name, progress_bar=False)
            downloader.start(blocking=False)
            c_time = time.time()
            display_message = None
            while not downloader.isFinished():
                status = downloader.get_status().capitalize()
                total_length = downloader.filesize if downloader.filesize else None
                downloaded = downloader.get_dl_size()
                now = time.time()
                diff = now - c_time
                percentage = downloader.get_progress()*100
                speed = downloader.get_speed()
                elapsed_time = round(diff) * 1000
                progress_str = "[{0}{1}]\nProgress: {2}%".format(
                    ''.join(["█" for i in range(math.floor(percentage / 5))]),
                    ''.join(["░" for i in range(20 - math.floor(percentage / 5))]),
                    round(percentage, 2))
                estimated_total_time = downloader.get_eta(human=True)
                try:
                    current_message = f"{status}..\nURL: {url}\nFile Name: {file_name}\n{progress_str}\n{humanbytes(downloaded)} of {humanbytes(total_length)}\nETA: {estimated_total_time}"
                    if current_message != display_message:
                        await target_file.edit(current_message)
                        display_message = current_message
                        await asyncio.sleep(1)
                except Exception as e:
                    LOGS.info(str(e))
                    pass
            end = datetime.now()
            duration = (end - start).seconds
            if downloader.isSuccessful():
                await target_file.edit(
                    "Downloaded to `{}` in {} seconds.".format(
                        downloaded_file_name, duration)
                )
            else:
                await target_file.edit(
                    "Incorrect URL\n{}".format(url)
                )
        elif target_file.reply_to_msg_id:
            start = datetime.now()
            try:
                c_time = time.time()
                downloaded_file_name = await target_file.client.download_media(
                    await target_file.get_reply_message(),
                    TEMP_DOWNLOAD_DIRECTORY,
                    progress_callback=lambda d, t: asyncio.get_event_loop().create_task(
                        progress(d, t, target_file, c_time, "Downloading...")
                    )
                )
            except Exception as e: # pylint:disable=C0103,W0703
                await target_file.edit(str(e))
            else:
                end = datetime.now()
                duration = (end - start).seconds
                await target_file.edit(
                    "Downloaded to `{}` in {} seconds.".format(
                        downloaded_file_name, duration)
                )
        else:
            await target_file.edit("Reply to a message to download to my local server.")
Пример #7
0
def UPLOAD(update, context):

    url = update.message.text
    url = url.split()[-1]
    sent_message = context.bot.send_message(chat_id=update.message.chat_id,
                                            text=TEXT.PROCESSING)

    ID = update.message.chat_id
    ID = str(ID)
    os.path.isfile(ID)
    if os.path.isfile(ID):
        # Openlaod Stuffs

        # I will Add This Later
        if "openload" in url or "oload" in url:

            DownloadStatus = False
            sent_message.edit_text("Openload No longer avalible")
            return

            # Here is DropBox Stuffs
        elif 'dropbox.com' in url:

            url = DPBOX(url)
            filename = url.split("/")[-1]
            print("Dropbox link Downloading Started : {}".format(
                url.split("/")[-1]))
            sent_message.edit_text(TEXT.DP_DOWNLOAD)
            # filename = wget.download(url)
            filename = wget_dl(str(url))
            print("Downloading Complete : {}".format(filename))
            sent_message.edit_text(TEXT.DOWN_COMPLETE)
            DownloadStatus = True
        # Here IS Mega Links stuffs
        elif 'mega.nz' in url:

            try:
                print("Downlaoding Started")
                sent_message.edit_text(TEXT.DOWN_MEGA)
                m = Mega.from_credentials(TEXT.MEGA_EMAIL, TEXT.MEGA_PASSWORD)
                filename = m.download_from_url(url)
                print("Downloading Complete Mega :", filename)
                sent_message.edit_text(TEXT.DOWN_COMPLETE)

                DownloadStatus = True
            except Exception as e:
                print("Mega Downloding Error :", e)
                sent_message.edit_text("Mega Downloading Error !!")

        else:
            try:
                filename = url.split("/")[-1]

                print("Downloading Started : {}".format(url.split("/")[-1]))
                sent_message.edit_text(TEXT.DOWNLOAD)
                # filename = wget.download(url)
                filename = wget_dl(str(url))
                print("Downloading Complete : {}".format(filename))
                sent_message.edit_text(TEXT.DOWN_COMPLETE)
                DownloadStatus = True

            except Exception as e:
                # switch To second download(SmartDl Downloader) `You can activate it throungh TEXT file`
                if TEXT.DOWN_TWO:
                    print(TEXT.DOWN_TWO)
                    try:
                        sent_message.edit_text(
                            "Downloader 1 Error:{} \n\n Downloader 2 :Downloading Started..."
                            .format(e))

                        obj = SmartDL(url)
                        obj.start()
                        filename = obj.get_dest()
                        DownloadStatus = True
                    except Exception as e:
                        print(e)
                        sent_message.edit_text(
                            "Downloading error :{}".format(e))
                        DownloadStatus = False
                else:
                    print(e)
                    sent_message.edit_text("Downloading error :{}".format(e))
                    DownloadStatus = False

            # Checking Error Filename
        if "error" in filename:
            # print(filename)
            # print(filename[0],filename[-1],filename[1])
            sent_message.edit_text("Downloading Error !! ")
            os.remove(filename[-1])

            ##########Uploading part  ###################
        try:

            if DownloadStatus:
                sent_message.edit_text(TEXT.UPLOADING)

                SIZE = (os.path.getsize(filename)) / 1048576
                SIZE = round(SIZE)
                FILENAME = filename.split("/")[-1]
                try:
                    FILELINK = upload(filename, update, context,
                                      TEXT.drive_folder_name)
                except Exception as e:
                    print("error Code : UPX11", e)
                    sent_message.edit_text("Uploading fail :{}".format(e))

                sent_message.edit_text(TEXT.DOWNLOAD_URL.format(
                    FILENAME, SIZE, FILELINK),
                                       parse_mode=ParseMode.HTML)
                print(filename)
                try:
                    os.remove(filename)
                except Exception as e:
                    print(e)
        except Exception as e:
            print("Error code UXP12", e)
            if DownloadStatus:
                sent_message.edit_text("Uploading fail : {}".format(e))
                try:
                    os.remove(filename)
                except Exception as e:
                    print("Error code UXP13", e)
            else:
                sent_message.edit_text("Uploading fail :", e)

    else:
        context.bot.send_message(chat_id=update.message.chat_id,
                                 text=TEXT.NOT_AUTH)
Пример #8
0
async def mega_downloader(_client, megadl):
    args = megadl.text.split(None, 1)
    await megadl.edit("`Processing...`")
    msg_link = await megadl.reply_to_message.text
    link = args[1]
    if link:
        pass
    elif msg_link:
        link = msg_link.text
    else:
        await megadl.edit("Usage: `.mega <mega url>`")
        return
    try:
        link = re.findall(r'\bhttps?://.*mega.*\.nz\S+', link)[0]
    except IndexError:
        await megadl.edit("`No MEGA.nz link found`\n")
        return
    cmd = f'bin/megadown -q -m {link}'
    result = await subprocess_run(cmd, megadl)
    try:
        data = json.loads(result[0])
    except json.JSONDecodeError:
        await megadl.edit("`Error: Can't extract the link`\n")
        return
    except TypeError:
        return
    except IndexError:
        return
    file_name = data["file_name"]
    file_url = data["url"]
    hex_key = data["hex_key"]
    hex_raw_key = data["hex_raw_key"]
    temp_file_name = file_name + ".temp"
    downloaded_file_name = "./" + "" + temp_file_name
    downloader = SmartDL(file_url, downloaded_file_name, progress_bar=False)
    display_message = None
    try:
        downloader.start(blocking=False)
    except HTTPError as e:
        await megadl.edit("`" + str(e) + "`")
        return
    while not downloader.isFinished():
        status = downloader.get_status().capitalize()
        total_length = downloader.filesize if downloader.filesize else None
        downloaded = downloader.get_dl_size()
        percentage = int(downloader.get_progress() * 100)
        progress = downloader.get_progress_bar()
        speed = downloader.get_speed(human=True)
        estimated_total_time = downloader.get_eta(human=True)
        try:
            current_message = (
                f"**{status}**..."
                f"\nFile Name: `{file_name}`\n"
                f"\n{progress} `{percentage}%`"
                f"\n{humanbytes(downloaded)} of {humanbytes(total_length)}"
                f" @ {speed}"
                f"\nETA: {estimated_total_time}")
            if status == "Downloading":
                await megadl.edit(current_message)
                time.sleep(0.2)
            elif status == "Combining":
                if display_message != current_message:
                    await megadl.edit(current_message)
                    display_message = current_message
        except Exception:
            pass
    if downloader.isSuccessful():
        download_time = downloader.get_dl_time(human=True)
        if exists(temp_file_name):
            await decrypt_file(file_name, temp_file_name, hex_key, hex_raw_key,
                               megadl)
            await megadl.edit(f"`{file_name}`\n\n"
                              "Successfully downloaded\n"
                              f"Download took: {download_time}")
    else:
        await megadl.edit("Failed to download, check heroku Log for details")
        for e in downloader.get_errors():
            megadl.edit(str(e))
    return
Пример #9
0
async def download(target_file):
    """ For .download command, download files to the userbot's server. """
    await target_file.edit("Processando ...")
    input_str = target_file.pattern_match.group(1)
    if not os.path.isdir(TEMP_DOWNLOAD_DIRECTORY):
        os.makedirs(TEMP_DOWNLOAD_DIRECTORY)
    if "|" in input_str:
        url, file_name = input_str.split("|")
        url = url.strip()
        # https://stackoverflow.com/a/761825/4723940
        file_name = file_name.strip()
        head, tail = os.path.split(file_name)
        if head:
            if not os.path.isdir(os.path.join(TEMP_DOWNLOAD_DIRECTORY, head)):
                os.makedirs(os.path.join(TEMP_DOWNLOAD_DIRECTORY, head))
                file_name = os.path.join(head, tail)
        downloaded_file_name = TEMP_DOWNLOAD_DIRECTORY + "/" + file_name
        downloader = SmartDL(url, downloaded_file_name, progress_bar=False)
        downloader.start(blocking=False)
        c_time = time.time()
        display_message = None
        while not downloader.isFinished():
            status = downloader.get_status().capitalize()
            total_length = downloader.filesize if downloader.filesize else None
            downloaded = downloader.get_dl_size()
            now = time.time()
            diff = now - c_time
            percentage = downloader.get_progress() * 100
            speed = downloader.get_speed()
            progress_str = "[{0}{1}] `{2}%`".format(
                "".join(["■" for i in range(math.floor(percentage / 10))]),
                "".join(["▨"
                         for i in range(10 - math.floor(percentage / 10))]),
                round(percentage, 2),
            )
            estimated_total_time = downloader.get_eta(human=True)
            try:
                current_message = (
                    f"`Nome` : `{file_name}`\n"
                    "Status"
                    f"\n**{status}**... | {progress_str}"
                    f"\n{humanbytes(downloaded)} of {humanbytes(total_length)}"
                    f" @ {speed}"
                    f"\n`Tempo Estimado` -> {estimated_total_time}")

                if round(diff %
                         10.00) == 0 and current_message != display_message:
                    await target_file.edit(current_message)
                    display_message = current_message
            except Exception as e:
                LOGS.info(str(e))
        if downloader.isSuccessful():
            await target_file.edit(
                "Baixado para `{}` com sucesso !!".format(downloaded_file_name)
            )
        else:
            await target_file.edit("URL incorreto\n{}".format(url))
    elif target_file.reply_to_msg_id:
        try:
            c_time = time.time()
            downloaded_file_name = await target_file.client.download_media(
                await target_file.get_reply_message(),
                TEMP_DOWNLOAD_DIRECTORY,
                progress_callback=lambda d, t: asyncio.get_event_loop().
                create_task(progress(d, t, target_file, c_time, "[DOWNLOAD]")),
            )
        except Exception as e:  # pylint:disable=C0103,W0703
            await target_file.edit(str(e))
        else:
            await target_file.edit(
                "Baixado para `{}` com sucesso !!".format(downloaded_file_name)
            )
    else:
        await target_file.edit(
            "Responda a uma mensagem para fazer o download no meu servidor local."
        )
Пример #10
0
async def mega_downloader(megadl):
    await megadl.edit("`Mengumpulkan informasi...`")
    if not os.path.isdir(TEMP_DOWNLOAD_DIRECTORY):
        os.makedirs(TEMP_DOWNLOAD_DIRECTORY)
    msg_link = await megadl.get_reply_message()
    link = megadl.pattern_match.group(1)
    if link:
        pass
    elif msg_link:
        link = msg_link.text
    else:
        return await megadl.edit("Usage: `.mega` **<MEGA.nz link>**")
    try:
        link = re.findall(r"\bhttps?://.*mega.*\.nz\S+", link)[0]
        """ - Mega changed their URL again - """
        if "file" in link:
            link = link.replace("#", "!").replace("file/", "#!")
        elif "folder" in link or "#F" in link or "#N" in link:
            await megadl.edit("`dukungan unduhan folder dihapus...`")
            return
    except IndexError:
        await megadl.edit("`Tautan MEGA.nz tidak ditemukan...`")
        return None
    cmd = f"bin/megadown -q -m {link}"
    result = await subprocess_run(megadl, cmd)
    try:
        data = json.loads(result[0])
    except json.JSONDecodeError:
        await megadl.edit("**JSONDecodeError**: `gagal mengekstrak tautan...`")
        return None
    except (IndexError, TypeError):
        return
    file_name = data["file_name"]
    file_url = data["url"]
    hex_key = data["hex_key"]
    hex_raw_key = data["hex_raw_key"]
    temp_file_name = file_name + ".temp"
    temp_file_path = TEMP_DOWNLOAD_DIRECTORY + temp_file_name
    file_path = TEMP_DOWNLOAD_DIRECTORY + file_name
    if os.path.isfile(file_path):
        try:
            raise FileExistsError(errno.EEXIST, os.strerror(errno.EEXIST), file_path)
        except FileExistsError as e:
            await megadl.edit(f"`{str(e)}`")
            return None
    downloader = SmartDL(file_url, temp_file_path, progress_bar=False)
    display_message = None
    try:
        downloader.start(blocking=False)
    except HTTPError as e:
        await megadl.edit(f"**HTTPError**: `{str(e)}`")
        return None
    start = time.time()
    while not downloader.isFinished():
        status = downloader.get_status().capitalize()
        total_length = downloader.filesize if downloader.filesize else None
        downloaded = downloader.get_dl_size()
        percentage = int(downloader.get_progress() * 100)
        speed = downloader.get_speed(human=True)
        estimated_total_time = round(downloader.get_eta())
        progress_str = "`{0}` | [{1}{2}] `{3}%`".format(
            status,
            "".join(["█" for i in range(math.floor(percentage / 10))]),
            "".join(["░" for i in range(10 - math.floor(percentage / 10))]),
            round(percentage, 2),
        )
        diff = time.time() - start
        try:
            current_message = (
                f"`{file_name}`\n"
                f"{progress_str}\n"
                f"`Ukuran:` {humanbytes(downloaded)} of {humanbytes(total_length)}\n"
                f"`Kecepatan:` {speed}\n"
                f"`ETA:` {time_formatter(estimated_total_time)}\n"
                f"`Durasi:` {time_formatter(round(diff))}"
            )
            if round(diff % 15.00) == 0 and (
                display_message != current_message or total_length == downloaded
            ):
                await megadl.edit(current_message)
                await asyncio.sleep(0.2)
                display_message = current_message
        except Exception:
            pass
        finally:
            if status == "Combining":
                wait = round(downloader.get_eta())
                await asyncio.sleep(wait)
    if downloader.isSuccessful():
        download_time = round(downloader.get_dl_time() + wait)
        try:
            P = multiprocessing.Process(
                target=await decrypt_file(
                    megadl, file_path, temp_file_path, hex_key, hex_raw_key
                ),
                name="Decrypt_File",
            )
            P.start()
            P.join()
        except FileNotFoundError as e:
            await megadl.edit(f"`{str(e)}`")
            return None
        else:
            await megadl.edit(
                f"`{file_name}`\n\n"
                f"Berhasil diunduh di: '`{file_path}`'.\n"
                f"Durasi download: {time_formatter(download_time)}."
            )
            return None
    else:
        await megadl.edit(
            "`Failed to download, " "periksa Log heroku untuk lebih jelasnya.`"
        )
        for e in downloader.get_errors():
            LOGS.info(str(e))
    return
Пример #11
0
async def mega_download(url, megadl):
    try:
        link = re.findall(r'\bhttps?://.*mega.*\.nz\S+', url)[0]
    except IndexError:
        await megadl.edit("`No MEGA.nz link found`\n")
        return
    cmd = f'bin/megadirect {link}'
    result = subprocess_run(cmd)
    try:
        data = json.loads(result[0])
    except json.JSONDecodeError:
        await megadl.edit("`Error: Can't extract the link`\n")
        return
    file_name = data['file_name']
    file_url = data['url']
    file_hex = data['hex']
    file_raw_hex = data['raw_hex']
    if exists(file_name):
        os.remove(file_name)
    if not exists(file_name):
        temp_file_name = file_name + ".temp"
        downloaded_file_name = "./" + "" + temp_file_name
        downloader = SmartDL(file_url, downloaded_file_name, progress_bar=False)
        display_message = None
        try:
            downloader.start(blocking=False)
        except HTTPError as e:
            await megadl.edit("`" + str(e) + "`")
            LOGS.info(str(e))
            return
        while not downloader.isFinished():
            status = downloader.get_status().capitalize()
            total_length = downloader.filesize if downloader.filesize else None
            downloaded = downloader.get_dl_size()
            percentage = int(downloader.get_progress() * 100)
            progress = downloader.get_progress_bar()
            speed = downloader.get_speed(human=True)
            estimated_total_time = downloader.get_eta(human=True)
            try:
                current_message = (
                    f"**{status}**..."
                    f"\nFile Name: `{file_name}`\n"
                    f"\n{progress} `{percentage}%`"
                    f"\n{humanbytes(downloaded)} of {humanbytes(total_length)}"
                    f" @ {speed}"
                    f"\nETA: {estimated_total_time}"
                )
                if status == "Downloading":
                    await megadl.edit(current_message)
                    time.sleep(0.2)
                elif status == "Combining":
                    if display_message != current_message:
                        await megadl.edit(current_message)
                        display_message = current_message
            except Exception as e:
                LOGS.info(str(e))
        if downloader.isSuccessful():
            download_time = downloader.get_dl_time(human=True)
            if exists(temp_file_name):
                await megadl.edit("Decrypting file...")
                decrypt_file(file_name, temp_file_name, file_hex, file_raw_hex)
                await megadl.edit(f"`{file_name}`\n\n"
                                  "Successfully downloaded\n"
                                  f"Download took: {download_time}")
        else:
            await megadl.edit("Failed to download...")
            for e in downloader.get_errors():
                LOGS.info(str(e))
    return
Пример #12
0
print('Fetched links from the root : ' + str(links))
links = links[:
              -1]  # removing the last link which points to some twitter page or sth
# print(links)

for i in range(len(links)):
    """
	The final download link is of the form https://books.goalkicker.com/DotNETFrameworkBook/DotNETFrameworkNotesForProfessionals.pdf
	we get that by combining 
	root_url : https://books.goalkicker.com/
	links[i] : DotNETFrameworkBook/

	The DotNETFrameworkNotesForProfessionals.pdf/ link is present in the page : root_url + links[i] : https://books.goalkicker.com/DotNETFrameworkBook/


	"""

    suburl = root_url + links[i]
    bookname = links[i][:-1] + '.pdf'  # remove the last character which is '/'
    pdflink = suburl + getLinks(
        suburl, count=1)[0]  # first link points to the pdf link

    if os.path.isfile(bookname):
        print(bookname + ' file already exists')
        continue
    print('Downloading ' + pdflink + ' ....')
    obj = SmartDL(
        pdflink,
        './' + bookname)  # download and save in the current working directory
    obj.start()
Пример #13
0
async def down_load_media(message: Message):
    await message.edit("Trying to Download...")
    if not os.path.isdir(Config.DOWN_PATH):
        os.mkdir(Config.DOWN_PATH)
    if message.reply_to_message and message.reply_to_message.media:
        start_t = datetime.now()
        c_time = time.time()
        dl_loc = await userge.download_media(
            message=message.reply_to_message,
            file_name=Config.DOWN_PATH,
            progress=progress,
            progress_args=("trying to download", userge, message, c_time))
        if message.process_is_canceled:
            await message.edit("`Process Canceled!`", del_in=5)
        else:
            dl_loc = os.path.join(Config.DOWN_PATH, os.path.basename(dl_loc))
            end_t = datetime.now()
            m_s = (end_t - start_t).seconds
            await message.edit(f"Downloaded to `{dl_loc}` in {m_s} seconds")
    elif message.input_str:
        start_t = datetime.now()
        url = message.input_str
        custom_file_name = unquote_plus(os.path.basename(url))
        if "|" in url:
            url, custom_file_name = url.split("|")
            url = url.strip()
            custom_file_name = custom_file_name.strip()
        download_file_path = os.path.join(Config.DOWN_PATH, custom_file_name)
        try:
            downloader = SmartDL(url, download_file_path, progress_bar=False)
            downloader.start(blocking=False)
            count = 0
            while not downloader.isFinished():
                if message.process_is_canceled:
                    downloader.stop()
                    raise Exception('Process Canceled!')
                total_length = downloader.filesize if downloader.filesize else 0
                downloaded = downloader.get_dl_size()
                percentage = downloader.get_progress() * 100
                speed = downloader.get_speed(human=True)
                estimated_total_time = downloader.get_eta(human=True)
                progress_str = \
                    "__{}__\n" + \
                    "```[{}{}]```\n" + \
                    "**Progress** : `{}%`\n" + \
                    "**URL** : `{}`\n" + \
                    "**FILENAME** : `{}`\n" + \
                    "**Completed** : `{}`\n" + \
                    "**Total** : `{}`\n" + \
                    "**Speed** : `{}`\n" + \
                    "**ETA** : `{}`"
                progress_str = progress_str.format(
                    "trying to download", ''.join(
                        (Config.FINISHED_PROGRESS_STR
                         for i in range(math.floor(percentage / 5)))),
                    ''.join((Config.UNFINISHED_PROGRESS_STR
                             for i in range(20 - math.floor(percentage / 5)))),
                    round(percentage,
                          2), url, custom_file_name, humanbytes(downloaded),
                    humanbytes(total_length), speed, estimated_total_time)
                count += 1
                if count >= 5:
                    count = 0
                    await message.try_to_edit(progress_str,
                                              disable_web_page_preview=True)
                await asyncio.sleep(1)
        except Exception as e:
            await message.err(e)
        else:
            end_t = datetime.now()
            m_s = (end_t - start_t).seconds
            await message.edit(
                f"Downloaded to `{download_file_path}` in {m_s} seconds")
    else:
        await message.edit("Please read `.help download`", del_in=5)
Пример #14
0
async def download(target_file):
    await target_file.edit("```Processing ...```")
    input_str = target_file.pattern_match.group(1)
    if not os.path.isdir(TEMP_DOWNLOAD_DIRECTORY):
        os.makedirs(TEMP_DOWNLOAD_DIRECTORY)
    if "|" in input_str:
        url, file_name = input_str.split("|")
        url = url.strip()
        # https://stackoverflow.com/a/761825/4723940
        file_name = file_name.strip()
        head, tail = os.path.split(file_name)
        if head and not os.path.isdir(
                os.path.join(TEMP_DOWNLOAD_DIRECTORY, head)):
            os.makedirs(os.path.join(TEMP_DOWNLOAD_DIRECTORY, head))
            file_name = os.path.join(head, tail)
        downloaded_file_name = TEMP_DOWNLOAD_DIRECTORY + "" + file_name
        downloader = SmartDL(url, downloaded_file_name, progress_bar=False)
        downloader.start(blocking=False)
        c_time = time.time()
        display_message = None
        while not downloader.isFinished():
            status = downloader.get_status().capitalize()
            total_length = downloader.filesize or None
            downloaded = downloader.get_dl_size()
            now = time.time()
            diff = now - c_time
            percentage = downloader.get_progress() * 100
            speed = downloader.get_speed()
            progress_str = "[{0}{1}] `{2}%`".format(
                "".join(["●" for i in range(math.floor(percentage / 10))]),
                "".join(["○"
                         for i in range(10 - math.floor(percentage / 10))]),
                round(percentage, 2),
            )
            estimated_total_time = downloader.get_eta(human=True)
            try:
                current_message = (
                    f"{file_name} - {status}\n"
                    f"{progress_str}"
                    f"`Size:` {humanbytes(downloaded)} of {humanbytes(total_length)}"
                    f"`Speed:` {speed}"
                    f"\n`ETA:` {estimated_total_time}")

                if round(diff %
                         10.00) == 0 and current_message != display_message:
                    await target_file.edit(current_message)
                    display_message = current_message
            except Exception as e:
                LOGS.info(str(e))
        if downloader.isSuccessful():
            await target_file.edit("Downloaded to `{}` successfully !!".format(
                downloaded_file_name))
        else:
            await target_file.edit("Incorrect URL\n{}".format(url))
    elif target_file.reply_to_msg_id:
        try:
            c_time = time.time()
            downloaded_file_name = await target_file.client.download_media(
                await target_file.get_reply_message(),
                TEMP_DOWNLOAD_DIRECTORY,
                progress_callback=lambda d, t: asyncio.get_event_loop().
                create_task(progress(d, t, target_file, c_time, "[DOWNLOAD]")),
            )
        except Exception as e:  # pylint:disable=C0103,W0703
            await target_file.edit(str(e))
        else:
            await target_file.edit("Downloaded to `{}` successfully !!".format(
                downloaded_file_name))
    else:
        await target_file.edit(
            "Reply to a message to download to my local server.")
Пример #15
0
async def mega_downloader(megadl):
    await megadl.edit("`Mengumpulkan informasi...`")
    if not os.path.isdir(TEMP_DOWNLOAD_DIRECTORY):
        os.makedirs(TEMP_DOWNLOAD_DIRECTORY)
    msg_link = await megadl.get_reply_message()
    link = megadl.pattern_match.group(1)
    if link:
        pass
    elif msg_link:
        link = msg_link.text
        link_msg_id = msg_link.id
    else:
        return await megadl.edit("Usage: `.mega` **<MEGA.nz link>**")
    try:
        link = re.findall(r"\bhttps?://.*mega.*\.nz\S+", link)[0]
        """ - Mega changed their URL again - """
        if "file" in link:
            link = link.replace("#", "!").replace("file/", "#!")
        elif "folder" in link or "#F" in link or "#N" in link:
            await megadl.edit("`Folder Download dihapus...`")
            return
    except IndexError:
        await megadl.edit("`MEGA.nz link Tidak Ditemukan...`")
        return None
    cmd = f"bin/megadown -q -m {link}"
    result = await subprocess_run(megadl, cmd)
    try:
        data = json.loads(result[0])
    except json.JSONDecodeError:
        await megadl.edit("**JSONDecodeError**: `Gagal Mengekstrak Link...`")
        return None
    except (IndexError, TypeError):
        return
    file_name = data["file_name"]
    file_url = data["url"]
    hex_key = data["hex_key"]
    hex_raw_key = data["hex_raw_key"]
    temp_file_name = file_name + ".temp"
    temp_file_path = TEMP_DOWNLOAD_DIRECTORY + temp_file_name
    file_path = TEMP_DOWNLOAD_DIRECTORY + file_name
    mimeType = await get_mimeType(file_path)
    service = await create_app(megadl)
    if service is False:
        return None
    if os.path.isfile(file_path):
        try:
            raise FileExistsError(errno.EEXIST, os.strerror(errno.EEXIST), file_path)
        except FileExistsError as e:
            await megadl.edit(f"`{str(e)}`")
            return None
    downloader = SmartDL(file_url, temp_file_path, progress_bar=False)
    display_message = None
    try:
        downloader.start(blocking=False)
    except HTTPError as e:
        await megadl.edit(f"**HTTPError**: `{str(e)}`")
        return None
    start = time.time()
    while not downloader.isFinished():
        status = downloader.get_status().capitalize()
        total_length = downloader.filesize if downloader.filesize else None
        downloaded = downloader.get_dl_size()
        percentage = int(downloader.get_progress() * 100)
        speed = downloader.get_speed(human=True)
        estimated_total_time = round(downloader.get_eta())
        progress_str = "`{0}` | [{1}{2}] `{3}%`".format(
            status,
            "".join(["●" for i in range(math.floor(percentage / 10))]),
            "".join(["○" for i in range(10 - math.floor(percentage / 10))]),
            round(percentage, 2),
        )
        diff = time.time() - start
        try:
            current_message = (
                f"`{file_name}`\n\n"
                "Status\n"
                f"{progress_str}\n"
                f"`{humanbytes(downloaded)} of {humanbytes(total_length)}"
                f" @ {speed}`\n"
                f"`ETA` -> {time_formatter(estimated_total_time)}\n"
                f"`Duration` -> {time_formatter(round(diff))}"
            )
            if round(diff % 15.00) == 0 and (
                display_message != current_message or total_length == downloaded
            ):
                await megadl.edit(current_message)
                await asyncio.sleep(0.2)
                display_message = current_message
        except Exception:
            pass
        finally:
            if status == "Combining":
                wait = round(downloader.get_eta())
                await asyncio.sleep(wait)
    if downloader.isSuccessful():
        download_time = round(downloader.get_dl_time() + wait)
        try:
            P = multiprocessing.Process(
                target=await decrypt_file(
                    megadl, file_path, temp_file_path, hex_key, hex_raw_key
                ),
                name="Decrypt_File",
            )
            P.start()
            P.join()
        except FileNotFoundError as e:
            await megadl.edit(f"`{str(e)}`")
            return None
        else:
            await megadl.edit(
                f"`{file_name}`\n\n"
                f"Berhasil didownload di: '`{file_path}`'.\n"
                f"Download took: {time_formatter(download_time)}.",
            )

        try:
            resultgd = await upload(megadl, service, file_path, file_name, mimeType)
        except CancelProcess:
            megadl.respond(
                "`[FILE - CANCELLED]`\n\n"
                "`Status` : **OK** - Sinyal yang diterima dibatalkan."
            )
        if resultgd and msg_link:
            await megadl.respond(
                "`[FILE - UPLOAD]`\n\n"
                f"`Name   :` `{file_name}`\n"
                f"`Size   :` `{humanbytes(resultgd[0])}`\n"
                f"`Link   :` [{file_name}]({resultgd[1]})\n"
                "`Status :` **OK** - Berhasil diupload.\n",
                link_preview=False,
                reply_to=link_msg_id,
            )
            await megadl.delete()
        elif resultgd and link:
            await megadl.respond(
                "`[FILE - UPLOAD]`\n\n"
                f"`Name   :` `{file_name}`\n"
                f"`Size   :` `{humanbytes(resultgd[0])}`\n"
                f"`Link   :` [{file_name}]({resultgd[1]})\n"
                "`Status :` **OK** - Berhasil diupload.\n",
                link_preview=False,
            )
            await megadl.delete()

        if os.path.exists(file_path):
            os.remove(file_path)
        else:
            pass
    else:
        await megadl.edit(
            "`Gagal Mendownload, " "Check Log heroku untuk lebih jelasnya.`"
        )
        for e in downloader.get_errors():
            LOGS.info(str(e))
    return
Пример #16
0
 async def upload(self) -> None:
     """ Upload from file/folder/link/tg file to GDrive """
     replied = self._message.reply_to_message
     is_url = re.search(
         r"(?:https?|ftp)://[^\|\s]+\.[^\|\s]+", self._message.input_str)
     dl_loc = None
     if replied and replied.media:
         await self._message.edit("`Downloading From TG...`")
         file_name = Config.DOWN_PATH
         if self._message.input_str:
             file_name = os.path.join(Config.DOWN_PATH, self._message.input_str)
         dl_loc = await self._message.client.download_media(
             message=replied,
             file_name=file_name,
             progress=progress,
             progress_args=(self._message, "trying to download")
         )
         if self._message.process_is_canceled:
             await self._message.edit("`Process Canceled!`", del_in=5)
             return
         dl_loc = os.path.join(Config.DOWN_PATH, os.path.basename(dl_loc))
     elif is_url:
         await self._message.edit("`Downloading From URL...`")
         url = is_url[0]
         file_name = unquote_plus(os.path.basename(url))
         if "|" in self._message.input_str:
             file_name = self._message.input_str.split("|")[1].strip()
         dl_loc = os.path.join(Config.DOWN_PATH, file_name)
         try:
             downloader = SmartDL(url, dl_loc, progress_bar=False)
             downloader.start(blocking=False)
             count = 0
             while not downloader.isFinished():
                 if self._message.process_is_canceled:
                     downloader.stop()
                     raise Exception('Process Canceled!')
                 total_length = downloader.filesize if downloader.filesize else 0
                 downloaded = downloader.get_dl_size()
                 percentage = downloader.get_progress() * 100
                 speed = downloader.get_speed(human=True)
                 estimated_total_time = downloader.get_eta(human=True)
                 progress_str = \
                     "__{}__\n" + \
                     "```[{}{}]```\n" + \
                     "**Progress** : `{}%`\n" + \
                     "**URL** : `{}`\n" + \
                     "**FILENAME** : `{}`\n" + \
                     "**Completed** : `{}`\n" + \
                     "**Total** : `{}`\n" + \
                     "**Speed** : `{}`\n" + \
                     "**ETA** : `{}`"
                 progress_str = progress_str.format(
                     "trying to download",
                     ''.join((Config.FINISHED_PROGRESS_STR
                              for i in range(math.floor(percentage / 5)))),
                     ''.join((Config.UNFINISHED_PROGRESS_STR
                              for i in range(20 - math.floor(percentage / 5)))),
                     round(percentage, 2),
                     url,
                     file_name,
                     humanbytes(downloaded),
                     humanbytes(total_length),
                     speed,
                     estimated_total_time)
                 count += 1
                 if count >= Config.EDIT_SLEEP_TIMEOUT:
                     count = 0
                     await self._message.try_to_edit(
                         progress_str, disable_web_page_preview=True)
                 await asyncio.sleep(1)
         except Exception as d_e:
             await self._message.err(d_e)
             return
     file_path = dl_loc if dl_loc else self._message.input_str
     if not os.path.exists(file_path):
         await self._message.err("invalid file path provided?")
         return
     if "|" in file_path:
         file_path, file_name = file_path.split("|")
         new_path = os.path.join(os.path.dirname(file_path.strip()), file_name.strip())
         os.rename(file_path.strip(), new_path)
         file_path = new_path
     await self._message.edit("`Loading GDrive Upload...`")
     pool.submit_thread(self._upload, file_path)
     start_t = datetime.now()
     count = 0
     while not self._is_finished:
         count += 1
         if self._message.process_is_canceled:
             self._cancel()
         if self._progress is not None and count >= Config.EDIT_SLEEP_TIMEOUT:
             count = 0
             await self._message.try_to_edit(self._progress)
         await asyncio.sleep(1)
     if dl_loc and os.path.exists(dl_loc):
         os.remove(dl_loc)
     end_t = datetime.now()
     m_s = (end_t - start_t).seconds
     if isinstance(self._output, HttpError):
         out = f"**ERROR** : `{self._output._get_reason()}`"  # pylint: disable=protected-access
     elif self._output is not None and not self._is_canceled:
         out = f"**Uploaded Successfully** __in {m_s} seconds__\n\n{self._output}\n\n📂 Index link: <a href='{Config.INDEX_LINK}/{file_name}'>Click here</a>"
     elif self._output is not None and self._is_canceled:
         out = self._output
     else:
         out = "`failed to upload.. check logs?`"
     await self._message.edit(out, disable_web_page_preview=True, log=__name__)
Пример #17
0
async def mega_downloader(megadl):
    await megadl.edit("`Processing...`")
    msg_link = await megadl.get_reply_message()
    link = megadl.pattern_match.group(1)
    if link:
        pass
    elif msg_link:
        link = msg_link.text
    else:
        return await megadl.edit("Usage: `.mega <MEGA.nz link>`")
    try:
        link = re.findall(r'\bhttps?://.*mega.*\.nz\S+', link)[0]
    except IndexError:
        return await megadl.edit("`No MEGA.nz link found`\n")
    if "#F" in link:
        await megadl.edit('`MEGA.nz link is a folder...`')
        await asyncio.sleep(2)
        return await mega_downloader_fallback(megadl, link)
    cmd = f'bin/megadown -q -m {link}'
    result = await subprocess_run(megadl, cmd)
    try:
        data = json.loads(result[0])
    except json.JSONDecodeError:
        return await megadl.edit("`Error: Can't extract the link`\n")
    except (IndexError, TypeError):
        return
    file_name = data["file_name"]
    file_url = data["url"]
    hex_key = data["hex_key"]
    hex_raw_key = data["hex_raw_key"]
    temp_file_name = file_name + ".temp"
    downloaded_file_name = "./" + "" + temp_file_name
    downloader = SmartDL(file_url, downloaded_file_name, progress_bar=False)
    display_message = None
    try:
        downloader.start(blocking=False)
    except HTTPError as e:
        return await megadl.edit("`" + str(e) + "`")
    while not downloader.isFinished():
        status = downloader.get_status().capitalize()
        total_length = downloader.filesize if downloader.filesize else None
        downloaded = downloader.get_dl_size()
        percentage = int(downloader.get_progress() * 100)
        progress = downloader.get_progress_bar()
        speed = downloader.get_speed(human=True)
        estimated_total_time = downloader.get_eta(human=True)
        try:
            current_message = (
                "File Name:"
                f"\n`{file_name}`\n\n"
                "Status:"
                f"\n**{status}** | {progress} `{percentage}%`"
                f"\n{humanbytes(downloaded)} of {humanbytes(total_length)}"
                f" @ {speed}"
                f"\nETA: {estimated_total_time}")
            if display_message != current_message:
                await megadl.edit(current_message)
                await asyncio.sleep(0.2)
                display_message = current_message
        except Exception:
            pass
        finally:
            if status == "Combining":
                await asyncio.sleep(float(downloader.get_eta()))
    if downloader.isSuccessful():
        download_time = downloader.get_dl_time(human=True)
        try:
            P = multiprocessing.Process(target=await
                                        decrypt_file(megadl, file_name,
                                                     temp_file_name, hex_key,
                                                     hex_raw_key),
                                        name="Decrypt_File")
            P.start()
            P.join()
        except FileNotFoundError as e:
            return await megadl.edit(str(e))
        else:
            return await megadl.edit(f"`{file_name}`\n\n"
                                     "Successfully downloaded\n"
                                     f"Download took: {download_time}")
    else:
        await megadl.edit("`Failed to download, "
                          "check heroku Logs for more details`")
        for e in downloader.get_errors():
            LOGS.info(str(e))
    return
Пример #18
0
async def _(event):  # sourcery no-metrics
    "To download the replied telegram file"
    mone = await edit_or_reply(event, "`Downloading....`")
    input_str = event.pattern_match.group(3)
    name = NAME
    path = None
    if not os.path.isdir(Config.TMP_DOWNLOAD_DIRECTORY):
        os.makedirs(Config.TMP_DOWNLOAD_DIRECTORY)
    reply = await event.get_reply_message()
    if reply:
        start = datetime.now()
        for attr in getattr(reply.document, "attributes", []):
            if isinstance(attr, types.DocumentAttributeFilename):
                name = attr.file_name
        if input_str:
            path = pathlib.Path(os.path.join(downloads, input_str.strip()))
        else:
            path = pathlib.Path(os.path.join(downloads, name))
        ext = get_extension(reply.document)
        if path and not path.suffix and ext:
            path = path.with_suffix(ext)
        if name == NAME:
            name += "_" + str(getattr(reply.document, "id", reply.id)) + ext
        if path and path.exists():
            if path.is_file():
                newname = f"{str(path.stem)}_OLD"
                path.rename(path.with_name(newname).with_suffix(path.suffix))
                file_name = path
            else:
                file_name = path / name
        elif path and not path.suffix and ext:
            file_name = downloads / path.with_suffix(ext)
        elif path:
            file_name = path
        else:
            file_name = downloads / name
        file_name.parent.mkdir(parents=True, exist_ok=True)
        c_time = time.time()
        if (
            not reply.document
            and reply.photo
            and file_name
            and file_name.suffix
            or not reply.document
            and not reply.photo
        ):
            await reply.download_media(
                file=file_name.absolute(),
                progress_callback=lambda d, t: asyncio.get_event_loop().create_task(
                    progress(d, t, mone, c_time, "trying to download")
                ),
            )
        elif not reply.document:
            file_name = await reply.download_media(
                file=downloads,
                progress_callback=lambda d, t: asyncio.get_event_loop().create_task(
                    progress(d, t, mone, c_time, "trying to download")
                ),
            )
        else:
            dl = io.FileIO(file_name.absolute(), "a")
            await event.client.fast_download_file(
                location=reply.document,
                out=dl,
                progress_callback=lambda d, t: asyncio.get_event_loop().create_task(
                    progress(d, t, mone, c_time, "trying to download")
                ),
            )
            dl.close()
        end = datetime.now()
        ms = (end - start).seconds
        await mone.edit(
            f"**•  Downloaded in {ms} seconds.**\n**•  Downloaded to :- **  `{os.path.relpath(file_name,os.getcwd())}`\n   "
        )
    elif input_str:
        start = datetime.now()
        if "|" in input_str:
            url, file_name = input_str.split("|")
        else:
            url = input_str
            file_name = None
        url = url.strip()
        file_name = os.path.basename(url) if file_name is None else file_name.strip()
        downloaded_file_name = pathlib.Path(os.path.join(downloads, file_name))
        if not downloaded_file_name.suffix:
            ext = os.path.splitext(url)[1]
            downloaded_file_name = downloaded_file_name.with_suffix(ext)
        downloader = SmartDL(url, str(downloaded_file_name), progress_bar=False)
        downloader.start(blocking=False)
        c_time = time.time()
        delay = 0
        oldmsg = ""
        while not downloader.isFinished():
            total_length = downloader.filesize or None
            downloaded = downloader.get_dl_size()
            now = time.time()
            delay = now - c_time
            percentage = downloader.get_progress() * 100
            dspeed = downloader.get_speed()
            progress_str = "`{0}{1} {2}`%".format(
                "".join("▰" for _ in range(math.floor(percentage / 5))),
                "".join("▱" for _ in range(20 - math.floor(percentage / 5))),
                round(percentage, 2),
            )

            estimated_total_time = downloader.get_eta(human=True)
            current_message = f"Downloading the file\
                                \n\n**URL : **`{url}`\
                                \n**File Name :** `{file_name}`\
                                \n{progress_str}\
                                \n`{humanbytes(downloaded)} of {humanbytes(total_length)} @ {humanbytes(dspeed)}`\
                                \n**ETA : **`{estimated_total_time}`"
            if oldmsg != current_message and delay > 5:
                await mone.edit(current_message)
                delay = 0
                c_time = time.time()
                oldmsg = current_message
            await asyncio.sleep(1)
        end = datetime.now()
        ms = (end - start).seconds
        if downloader.isSuccessful():
            await mone.edit(
                f"**•  Downloaded in {ms} seconds.**\n**•  Downloaded file location :- ** `{os.path.relpath(downloaded_file_name,os.getcwd())}`"
            )
        else:
            await mone.edit("Incorrect URL\n {}".format(input_str))
    else:
        await mone.edit("`Reply to a message to download to my local server.`")
Пример #19
0
async def download(target_file):
    """ For .dl command, download files to the userbot's server. """
    await target_file.edit("Processing using userbot server ( ◜‿◝ )♡")
    input_str = target_file.pattern_match.group(1)
    if not os.path.isdir(TEMP_DOWNLOAD_DIRECTORY):
        os.makedirs(TEMP_DOWNLOAD_DIRECTORY)
    if "|" in input_str:
        url, file_name = input_str.split("|")
        url = url.strip()
        # https://stackoverflow.com/a/761825/4723940
        file_name = file_name.strip()
        head, tail = os.path.split(file_name)
        if head:
            if not os.path.isdir(os.path.join(TEMP_DOWNLOAD_DIRECTORY, head)):
                os.makedirs(os.path.join(TEMP_DOWNLOAD_DIRECTORY, head))
                file_name = os.path.join(head, tail)
        downloaded_file_name = TEMP_DOWNLOAD_DIRECTORY + "" + file_name
        downloader = SmartDL(url, downloaded_file_name, progress_bar=False)
        downloader.start(blocking=False)
        c_time = time.time()
        display_message = None
        while not downloader.isFinished():
            status = downloader.get_status().capitalize()
            total_length = downloader.filesize if downloader.filesize else None
            downloaded = downloader.get_dl_size()
            now = time.time()
            diff = now - c_time
            percentage = downloader.get_progress() * 100
            downloader.get_speed()
            round(diff) * 1000
            progress_str = "[{0}{1}] {2}%".format(
                "".join(["▰" for i in range(math.floor(percentage / 10))]),
                "".join(["▱" for i in range(10 - math.floor(percentage / 10))]),
                round(percentage, 2),
            )
            estimated_total_time = downloader.get_eta(human=True)
            try:
                current_message = f"{status}..\
                \nFOR : F.R.I.D.A.Y™ AND INDIANBOT™\
                \nURL: {url}\
                \nFile Name: {file_name}\
                \n{progress_str}\
                \n{humanbytes(downloaded)} of {humanbytes(total_length)}\
                \nETA: {estimated_total_time}"

                if round(diff % 10.00) == 0 and current_message != display_message:
                    await target_file.edit(current_message)
                    display_message = current_message
            except Exception as e:
                LOGS.info(str(e))
        if downloader.isSuccessful():
            await target_file.edit(
                "Downloaded to `{}` successfully !!".format(downloaded_file_name)
            )
        else:
            await target_file.edit("Incorrect URL\n{}".format(url))
    elif target_file.reply_to_msg_id:
        try:
            c_time = time.time()
            downloaded_file_name = await target_file.client.download_media(
                await target_file.get_reply_message(),
                TEMP_DOWNLOAD_DIRECTORY,
                progress_callback=lambda d, t: asyncio.get_event_loop().create_task(
                    progress(d, t, target_file, c_time, "Downloading...")
                ),
            )
        except Exception as e:  # pylint:disable=C0103,W0703
            await target_file.edit(str(e))
        else:
            await target_file.edit(
                "Downloaded to `{}` successfully !!".format(downloaded_file_name)
            )
    else:
        await target_file.edit("Reply to a message to download to my local server.")
Пример #20
0
async def _(event):
    if event.fwd_from:
        return
    if not os.path.isdir(Config.TMP_DOWNLOAD_DIRECTORY):
        os.makedirs(Config.TMP_DOWNLOAD_DIRECTORY)
    thumb = None
    if os.path.exists(thumb_image_path):
        thumb = thumb_image_path
    start = datetime.now()
    input_str = event.pattern_match.group(1)
    url = input_str
    file_name = os.path.basename(url)
    to_download_directory = Config.TMP_DOWNLOAD_DIRECTORY
    if "|" in input_str:
        url, file_name = input_str.split("|")
    url = url.strip()
    file_name = file_name.strip()
    downloaded_file_name = os.path.join(to_download_directory, file_name)
    downloader = SmartDL(url, downloaded_file_name, progress_bar=False)
    downloader.start(blocking=False)
    display_message = ""
    c_time = time.time()
    while not downloader.isFinished():
        total_length = downloader.filesize if downloader.filesize else None
        downloaded = downloader.get_dl_size()
        now = time.time()
        diff = now - c_time
        percentage = downloader.get_progress() * 100
        speed = downloader.get_speed()
        elapsed_time = round(diff) * 1000
        progress_str = "[{0}{1}]\nProgress: {2}%".format(
            ''.join(["█" for i in range(math.floor(percentage / 5))]),
            ''.join(["░" for i in range(20 - math.floor(percentage / 5))]),
            round(percentage, 2))
        estimated_total_time = downloader.get_eta(human=True)
        try:
            current_message = f"trying to download\n"
            current_message += f"URL: {url}\n"
            current_message += f"File Name: {file_name}\n"
            current_message += f"{progress_str}\n"
            current_message += f"{humanbytes(downloaded)} of {humanbytes(total_length)}\n"
            current_message += f"ETA: {estimated_total_time}"
            if round(diff % 10.00) == 0 and current_message != display_message:
                await event.edit(current_message)
                display_message = current_message
        except Exception as e:
            logger.info(str(e))
    end = datetime.now()
    ms_dl = (end - start).seconds
    if downloader.isSuccessful():
        await event.edit("Downloaded to `{}` in {} seconds.".format(
            downloaded_file_name, ms_dl))
        if os.path.exists(downloaded_file_name):
            c_time = time.time()
            await borg.send_file(
                event.chat_id,
                downloaded_file_name,
                force_document=True,
                supports_streaming=False,
                allow_cache=False,
                reply_to=event.message.id,
                thumb=thumb,
                progress_callback=lambda d, t: asyncio.get_event_loop().
                create_task(progress(d, t, event, c_time, "trying to upload")))
            end_two = datetime.now()
            os.remove(downloaded_file_name)
            ms_two = (end_two - end).seconds
            await event.edit(
                "Downloaded in {} seconds. Uploaded in {} seconds.".format(
                    ms_dl, ms_two))
        else:
            await event.edit("File Not Found {}".format(input_str))
    else:
        await event.edit("Incorrect URL\n {}".format(input_str))
Пример #21
0
async def _(event):
    if event.fwd_from:
        return
    mone = await edit_or_reply(event, "`Processing ...`")
    input_str = event.pattern_match.group(1)
    if not os.path.isdir(Config.TMP_DOWNLOAD_DIRECTORY):
        os.makedirs(Config.TMP_DOWNLOAD_DIRECTORY)
    if event.reply_to_msg_id:
        start = datetime.now()
        reply_message = await event.get_reply_message()
        try:
            c_time = time.time()
            downloaded_file_name = await event.client.download_media(
                reply_message,
                Config.TMP_DOWNLOAD_DIRECTORY,
                progress_callback=lambda d, t: asyncio.get_event_loop(
                ).create_task(
                    progress(d, t, mone, c_time, "trying to download")),
            )
        except Exception as e:
            await mone.edit(str(e))
        else:
            end = datetime.now()
            ms = (end - start).seconds
            await mone.edit(
                f"**  •  Downloaded in {ms} seconds.**\n**  •  Downloaded to :- ** `{downloaded_file_name}`\n**  •  Downloaded by :-** {DEFAULTUSER}"
            )
    elif input_str:
        start = datetime.now()
        url = input_str
        file_name = os.path.basename(url)
        to_download_directory = Config.TMP_DOWNLOAD_DIRECTORY
        if "|" in input_str:
            url, file_name = input_str.split("|")
        url = url.strip()
        file_name = file_name.strip()
        downloaded_file_name = os.path.join(to_download_directory, file_name)
        downloader = SmartDL(url, downloaded_file_name, progress_bar=False)
        downloader.start(blocking=False)
        c_time = time.time()
        while not downloader.isFinished():
            total_length = downloader.filesize or None
            downloaded = downloader.get_dl_size()
            display_message = ""
            now = time.time()
            diff = now - c_time
            percentage = downloader.get_progress() * 100
            downloader.get_speed()
            progress_str = "`{0}{1} {2}`%".format(
                "".join(["▰" for i in range(math.floor(percentage / 5))]),
                "".join(["▱" for i in range(20 - math.floor(percentage / 5))]),
                round(percentage, 2),
            )
            estimated_total_time = downloader.get_eta(human=True)
            try:
                current_message = f"Downloading the file\
                                \n\n**URL : **`{url}`\
                                \n**File Name :** `{file_name}`\
                                \n{progress_str}\
                                \n`{humanbytes(downloaded)} of {humanbytes(total_length)}`\
                                \n**ETA : **`{estimated_total_time}``"

                if round(diff %
                         10.00) == 0 and current_message != display_message:
                    await mone.edit(current_message)
                    display_message = current_message
            except Exception as e:
                logger.info(str(e))
        end = datetime.now()
        ms = (end - start).seconds
        if downloader.isSuccessful():
            await mone.edit(
                f"**  •  Downloaded in {ms} seconds.**\n**  •  Downloaded to :- ** `{downloaded_file_name}`"
            )
        else:
            await mone.edit("Incorrect URL\n {}".format(input_str))
    else:
        await mone.edit("Reply to a message to download to my local server.")
Пример #22
0
async def down_load_media(message: Message):
    await message.edit("Trying to Download...")
    if message.reply_to_message is not None:
        start_t = datetime.now()
        c_time = time.time()

        the_real_download_location = await userge.download_media(
            message=message.reply_to_message,
            file_name=Config.DOWN_PATH,
            progress=progress,
            progress_args=("trying to download", userge, message, c_time))
        # await userge.send_chat_action(message.chat.id, "cancel")

        if message.process_is_canceled:
            await message.edit("`Process Canceled!`", del_in=5)

        else:
            end_t = datetime.now()
            ms = (end_t - start_t).seconds
            await message.edit(
                f"Downloaded to `{the_real_download_location}` in {ms} seconds"
            )

    elif message.input_str:
        start_t = datetime.now()
        url = message.input_str
        custom_file_name = os.path.basename(url)

        if "|" in url:
            url, custom_file_name = url.split("|")
            url = url.strip()
            custom_file_name = custom_file_name.strip()

        download_file_path = os.path.join(Config.DOWN_PATH, custom_file_name)
        downloader = SmartDL(url, download_file_path, progress_bar=False)
        downloader.start(blocking=False)
        c_time = time.time()

        while not downloader.isFinished():
            total_length = downloader.filesize if downloader.filesize else None
            downloaded = downloader.get_dl_size()
            display_message = ""
            now = time.time()
            diff = now - c_time
            percentage = downloader.get_progress() * 100
            # speed = downloader.get_speed()
            # elapsed_time = round(diff) * 1000

            progress_str = "[{0}{1}]\nProgress: {2}%".format(
                ''.join(["█" for i in range(math.floor(percentage / 5))]),
                ''.join(["░" for i in range(20 - math.floor(percentage / 5))]),
                round(percentage, 2))
            estimated_total_time = downloader.get_eta(human=True)

            try:
                current_message = f"trying to download\n"
                current_message += f"URL: {url}\n"
                current_message += f"File Name: {custom_file_name}\n"
                current_message += f"{progress_str}\n"
                current_message += f"{humanbytes(downloaded)} of {humanbytes(total_length)}\n"
                current_message += f"ETA: {estimated_total_time}"

                if round(diff %
                         10.00) == 0 and current_message != display_message:
                    await message.try_to_edit(text=current_message,
                                              disable_web_page_preview=True)

                    # display_message = current_message
                    await asyncio.sleep(10)

            except Exception as e:
                LOGGER.info(e)

        if os.path.exists(download_file_path):
            end_t = datetime.now()
            ms = (end_t - start_t).seconds

            await message.edit(
                f"Downloaded to `{download_file_path}` in {ms} seconds")

        else:
            await message.edit(f"`Something went wrong!`", del_in=3)

    else:
        await message.edit(
            "Reply to a Telegram Media, to download it to local server.",
            del_in=3)
Пример #23
0
async def gdrive_upload_function(dryb):
    """ For .gdrive command, upload files to google drive. """
    await dryb.edit("Processing ...")
    input_str = dryb.pattern_match.group(1)
    if CLIENT_ID is None or CLIENT_SECRET is None:
        return
    if not os.path.isdir(TEMP_DOWNLOAD_DIRECTORY):
        os.makedirs(TEMP_DOWNLOAD_DIRECTORY)
        required_file_name = None
    if "|" in input_str:
        url, file_name = input_str.split("|")
        url = url.strip()
        # https://stackoverflow.com/a/761825/4723940
        file_name = file_name.strip()
        head, tail = os.path.split(file_name)
        if head:
            if not os.path.isdir(os.path.join(TEMP_DOWNLOAD_DIRECTORY, head)):
                os.makedirs(os.path.join(TEMP_DOWNLOAD_DIRECTORY, head))
                file_name = os.path.join(head, tail)
        downloaded_file_name = TEMP_DOWNLOAD_DIRECTORY + "" + file_name
        downloader = SmartDL(url, downloaded_file_name, progress_bar=False)
        downloader.start(blocking=False)
        c_time = time.time()
        display_message = None
        while not downloader.isFinished():
            status = downloader.get_status().capitalize()
            total_length = downloader.filesize if downloader.filesize else None
            downloaded = downloader.get_dl_size()
            now = time.time()
            diff = now - c_time
            percentage = downloader.get_progress() * 100
            speed = downloader.get_speed()
            elapsed_time = round(diff) * 1000
            progress_str = "[{0}{1}] {2}%".format(
                ''.join(["█" for i in range(math.floor(percentage / 10))]),
                ''.join(["░"
                         for i in range(10 - math.floor(percentage / 10))]),
                round(percentage, 2))
            estimated_total_time = downloader.get_eta(human=True)
            try:
                current_message = f"{status}...\
                \nURL: {url}\
                \nFile Name: {file_name}\
                \n{progress_str}\
                \n{humanbytes(downloaded)} of {humanbytes(total_length)}\
                \nETA: {estimated_total_time}"

                if round(diff %
                         10.00) == 0 and current_message != display_message:
                    await dryb.edit(current_message)
                    display_message = current_message
            except Exception as e:
                LOGS.info(str(e))
                pass
        if downloader.isSuccessful():
            await dryb.edit(
                "Downloaded to `{}` successfully !!\nInitiating Upload to Google Drive.."
                .format(downloaded_file_name))
            required_file_name = downloaded_file_name
        else:
            await dryb.edit("Incorrect URL\n{}".format(url))
    elif input_str:
        input_str = input_str.strip()
        if os.path.exists(input_str):
            required_file_name = input_str
            await dryb.edit(
                "Found `{}` in local server, Initiating Upload to Google Drive.."
                .format(input_str))
        else:
            await dryb.edit(
                "File not found in local server. Give me a valid file path !")
            return False
    elif dryb.reply_to_msg_id:
        try:
            c_time = time.time()
            downloaded_file_name = await dryb.client.download_media(
                await dryb.get_reply_message(),
                TEMP_DOWNLOAD_DIRECTORY,
                progress_callback=lambda d, t: asyncio.get_event_loop(
                ).create_task(progress(d, t, dryb, c_time, "Downloading...")))
        except Exception as e:
            await dryb.edit(str(e))
        else:
            required_file_name = downloaded_file_name
            await dryb.edit(
                "Downloaded to `{}` Successfully !!\nInitiating Upload to Google Drive.."
                .format(downloaded_file_name))
    if required_file_name:
        if G_DRIVE_AUTH_TOKEN_DATA is not None:
            with open(G_DRIVE_TOKEN_FILE, "w") as t_file:
                t_file.write(G_DRIVE_AUTH_TOKEN_DATA)
        # Check if token file exists, if not create it by requesting
        # authorization code
        if not os.path.isfile(G_DRIVE_TOKEN_FILE):
            storage = await create_token_file(G_DRIVE_TOKEN_FILE, dryb)
            http = authorize(G_DRIVE_TOKEN_FILE, storage)
        # Authorize, get file parameters, upload file and print out result URL
        # for download
        http = authorize(G_DRIVE_TOKEN_FILE, None)
        file_name, mime_type = file_ops(required_file_name)
        # required_file_name will have the full path
        # Sometimes API fails to retrieve starting URI, we wrap it.
        try:
            g_drive_link = await upload_file(http, required_file_name,
                                             file_name, mime_type, dryb,
                                             parent_id)
            await dryb.edit(
                f"File:`{required_file_name}`\nwas Successfully Uploaded to [Google Drive]({g_drive_link})!"
            )
        except Exception as e:
            await dryb.edit(
                f"Error while Uploading to Google Drive\nError Code:\n`{e}`")
Пример #24
0
def UPLOAD(update, context):

    url = update.message.text
    url = url.split()[-1]
    sent_message = context.bot.send_message(chat_id=update.message.chat_id,
                                            text=TEXT.PROCESSING)

    ID = update.message.chat_id
    ID = str(ID)
    os.path.isfile(ID)
    if os.path.isfile(ID):
        try:
            filename = url.split("/")[-1]

            print("Downloading Started : {}".format(url.split("/")[-1]))
            sent_message.edit_text(TEXT.DOWNLOAD)
            # filename = wget.download(url)
            filename = wget_dl(str(url))
            print("Downloading Complete : {}".format(filename))
            sent_message.edit_text(TEXT.DOWN_COMPLETE)
            DownloadStatus = True

        except Exception as e:
            # switch To second download(SmartDl Downloader) `You can activate it throungh TEXT file`
            if TEXT.DOWN_TWO:
                print(TEXT.DOWN_TWO)
                try:
                    sent_message.edit_text(
                        "Downloader 1 Error:{} \n\n Downloader 2 :Downloading Started..."
                        .format(e))

                    obj = SmartDL(url)
                    obj.start()
                    filename = obj.get_dest()
                    DownloadStatus = True
                except Exception as e:
                    print(e)
                    sent_message.edit_text("Downloading error :{}".format(e))
                    DownloadStatus = False
            else:
                print(e)
                sent_message.edit_text("Downloading error :{}".format(e))
                DownloadStatus = False

            # Checking Error Filename
        if "error" in filename:
            # print(filename)
            # print(filename[0],filename[-1],filename[1])
            sent_message.edit_text("Downloading Error !! ")
            os.remove(filename[-1])

            ##########Uploading part  ###################
        try:

            if DownloadStatus:
                sent_message.edit_text(TEXT.UPLOADING)

                SIZE = (os.path.getsize(filename)) / 1048576
                SIZE = round(SIZE)
                FILENAME = filename.split("/")[-1]
                try:
                    FILELINK = upload(filename, update, context,
                                      TEXT.drive_folder_name)
                except Exception as e:
                    print("error Code : UPX11", e)
                    sent_message.edit_text("Uploading fail :{}".format(e))

                sent_message.edit_text(TEXT.DOWNLOAD_URL.format(
                    FILENAME, SIZE, FILELINK),
                                       parse_mode=ParseMode.HTML)
                print(filename)
                try:
                    os.remove(filename)
                except Exception as e:
                    print(e)
        except Exception as e:
            print("Error code UXP12", e)
            if DownloadStatus:
                sent_message.edit_text("Uploading fail : {}".format(e))
                try:
                    os.remove(filename)
                except Exception as e:
                    print("Error code UXP13", e)
            else:
                sent_message.edit_text("Uploading fail :", e)

    else:
        context.bot.send_message(chat_id=update.message.chat_id,
                                 text=TEXT.NOT_AUTH)
Пример #25
0
async def mega_downloader(megadl):
    await megadl.edit("`Collecting information...`")
    if not os.path.isdir(TEMP_DOWNLOAD_DIRECTORY):
        os.makedirs(TEMP_DOWNLOAD_DIRECTORY)
    msg_link = await megadl.get_reply_message()
    link = megadl.pattern_match.group(1)
    if link:
        pass
    elif msg_link:
        link = msg_link.text
    else:
        return await megadl.edit("Usage: `.mega` **<MEGA.nz link>**")
    try:
        link = re.findall(r'\bhttps?://.*mega.*\.nz\S+', link)[0]
        """ - Mega changed their URL again - """
        if "file" in link:
            link = link.replace("#", "!").replace("file/", "#!")
        elif "folder" in link or "#F" in link or "#N" in link:
            await megadl.edit("`folder download support are removed...`")
            return
    except IndexError:
        return await megadl.edit("`MEGA.nz link not found...`")
    cmd = f'bin/megadown -q -m {link}'
    result = await subprocess_run(megadl, cmd)
    try:
        data = json.loads(result[0])
    except json.JSONDecodeError:
        return await megadl.edit("`Err: failed to extract link...`\n")
    except (IndexError, TypeError):
        return
    file_name = data["file_name"]
    file_url = data["url"]
    hex_key = data["hex_key"]
    hex_raw_key = data["hex_raw_key"]
    temp_file_name = file_name + ".temp"
    temp_file_path = TEMP_DOWNLOAD_DIRECTORY + temp_file_name
    file_path = TEMP_DOWNLOAD_DIRECTORY + file_name
    if os.path.isfile(file_path):
        try:
            raise FileExistsError(errno.EEXIST, os.strerror(errno.EEXIST),
                                  file_path)
        except FileExistsError as e:
            return await megadl.edit(f"`{str(e)}`")
    downloader = SmartDL(file_url, temp_file_path, progress_bar=False)
    display_message = None
    try:
        downloader.start(blocking=False)
    except HTTPError as e:
        return await megadl.edit(f"`Err: {str(e)}`")
    start = time.time()
    while not downloader.isFinished():
        status = downloader.get_status().capitalize()
        total_length = downloader.filesize if downloader.filesize else None
        downloaded = downloader.get_dl_size()
        percentage = int(downloader.get_progress() * 100)
        speed = downloader.get_speed(human=True)
        estimated_total_time = round(downloader.get_eta())
        progress_str = "`{0}` | [{1}{2}] `{3}%`".format(
            status, ''.join("●" for i in range(math.floor(percentage / 10))),
            ''.join("○" for i in range(10 - math.floor(percentage / 10))),
            round(percentage, 2))
        diff = time.time() - start
        try:
            current_message = (
                f"`{file_name}`\n\n"
                "Status\n"
                f"{progress_str}\n"
                f"`{humanbytes(downloaded)} of {humanbytes(total_length)}"
                f" @ {speed}`\n"
                f"`ETA` -> {time_formatter(estimated_total_time)}\n"
                f"`Duration` -> {time_formatter(round(diff))}")
            if round(diff % 10.00) == 0 and (display_message != current_message
                                             or total_length == downloaded):
                await megadl.edit(current_message)
                await asyncio.sleep(0.2)
                display_message = current_message
        except Exception:
            pass
        finally:
            if status == "Combining":
                wait = round(downloader.get_eta())
                await asyncio.sleep(wait)
    if downloader.isSuccessful():
        download_time = round(downloader.get_dl_time() + wait)
        try:
            P = multiprocessing.Process(target=await
                                        decrypt_file(megadl, file_path,
                                                     temp_file_path, hex_key,
                                                     hex_raw_key),
                                        name="Decrypt_File")
            P.start()
            P.join()
        except FileNotFoundError as e:
            return await megadl.edit(f"`{str(e)}`")
        else:
            return await megadl.edit(
                f"`{file_name}`\n\n"
                f"Successfully downloaded in: `{file_path}`.\n\n"
                f"Download took: {time_formatter(download_time)}.")
    else:
        await megadl.edit("`Failed to download, "
                          "check heroku Logs for more details`.")
        for e in downloader.get_errors():
            LOGS.info(str(e))
    return
Пример #26
0
async def gdrive_upload_function(dryb):
    """ .gdrive komutu dosyalarınızı Google Drive'a uploadlar. """
    await dryb.edit("İşleniyor ...")
    input_str = dryb.pattern_match.group(1)
    if CLIENT_ID is None or CLIENT_SECRET is None:
        return
    if not os.path.isdir(TEMP_DOWNLOAD_DIRECTORY):
        os.makedirs(TEMP_DOWNLOAD_DIRECTORY)
        required_file_name = None
    if "|" in input_str:
        url, file_name = input_str.split("|")
        url = url.strip()
        # https://stackoverflow.com/a/761825/4723940
        file_name = file_name.strip()
        head, tail = os.path.split(file_name)
        if head:
            if not os.path.isdir(os.path.join(TEMP_DOWNLOAD_DIRECTORY, head)):
                os.makedirs(os.path.join(TEMP_DOWNLOAD_DIRECTORY, head))
                file_name = os.path.join(head, tail)
        downloaded_file_name = TEMP_DOWNLOAD_DIRECTORY + "" + file_name
        downloader = SmartDL(url, downloaded_file_name, progress_bar=False)
        downloader.start(blocking=False)
        c_time = time.time()
        display_message = None
        while not downloader.isFinished():
            status = downloader.get_status().capitalize()
            total_length = downloader.filesize if downloader.filesize else None
            downloaded = downloader.get_dl_size()
            now = time.time()
            diff = now - c_time
            percentage = downloader.get_progress() * 100
            speed = downloader.get_speed()
            elapsed_time = round(diff) * 1000
            progress_str = "[{0}{1}] {2}%".format(
                ''.join(["▰" for i in range(math.floor(percentage / 10))]),
                ''.join(["▱"
                         for i in range(10 - math.floor(percentage / 10))]),
                round(percentage, 2))
            estimated_total_time = downloader.get_eta(human=True)
            try:
                current_message = f"{status}...\
                \nURL: {url}\
                \nDosya adı: {file_name}\
                \n{progress_str}\
                \n{humanbytes(downloaded)} of {humanbytes(total_length)}\
                \nBitiş: {estimated_total_time}"

                if round(diff %
                         10.00) == 0 and current_message != display_message:
                    await dryb.edit(current_message)
                    display_message = current_message
            except Exception as e:
                LOGS.info(str(e))
                pass
        if downloader.isSuccessful():
            await dryb.edit(
                "`{}` dizinine indirme başarılı. \nGoogle Drive'a yükleme başlatılıyor.."
                .format(downloaded_file_name))
            required_file_name = downloaded_file_name
        else:
            await dryb.edit("Geçersiz URL\n{}".format(url))
    elif input_str:
        input_str = input_str.strip()
        if os.path.exists(input_str):
            required_file_name = input_str
            await dryb.edit(
                "`{}` dosyası sunucuda bulundu. Google Drive'a yükleme başlatılıyor.."
                .format(input_str))
        else:
            await dryb.edit(
                "Sunucuda dosya bulunamadı. Lütfen doğru dosya konumunu belirtin."
            )
            return False
    elif dryb.reply_to_msg_id:
        try:
            c_time = time.time()
            downloaded_file_name = await dryb.client.download_media(
                await dryb.get_reply_message(),
                TEMP_DOWNLOAD_DIRECTORY,
                progress_callback=lambda d, t: asyncio.get_event_loop(
                ).create_task(progress(d, t, dryb, c_time, "İndiriliyor...")))
        except Exception as e:
            await dryb.edit(str(e))
        else:
            required_file_name = downloaded_file_name
            await dryb.edit(
                "`{}` dizinine indirme başarrılı. \nGoogle Drive'a yükleme başlatılıyor.."
                .format(downloaded_file_name))
    if required_file_name:
        if G_DRIVE_AUTH_TOKEN_DATA is not None:
            with open(G_DRIVE_TOKEN_FILE, "w") as t_file:
                t_file.write(G_DRIVE_AUTH_TOKEN_DATA)
        # Token dosyasının olup olmadığını kontrol eder, eğer yoksa yetkilendirme kodu ile oluşturur.
        if not os.path.isfile(G_DRIVE_TOKEN_FILE):
            storage = await create_token_file(G_DRIVE_TOKEN_FILE, dryb)
            http = authorize(G_DRIVE_TOKEN_FILE, storage)
        # Yetkilendirir, dosya parametrelerini edinir, dosyayı uploadlar ve URL'yi indirme için paylaşır.
        http = authorize(G_DRIVE_TOKEN_FILE, None)
        file_name, mime_type = file_ops(required_file_name)
        # required_file_name tam dosya yoluna sahiptir.
        # Bazen API başlangıç URI'sini geri alırken hatayla karşılaşır.
        try:
            g_drive_link = await upload_file(http, required_file_name,
                                             file_name, mime_type, dryb,
                                             parent_id)
            await dryb.edit(
                f"Dosya :`{required_file_name}`\nUpload başarılı! \nİndirme linki: [Google Drive]({g_drive_link})!"
            )
        except Exception as e:
            await dryb.edit(
                f"Google Drive'a yükleme başarısız.\nHata kodu:\n`{e}`")
Пример #27
0
    PLACEHOLDER = None

# Setting Up CloudMail.ru and MEGA.nz extractor binaries,
# and giving them correct perms to work properly.
if not os.path.exists('bin'):
    os.mkdir('bin')

binaries = {
    "https://raw.githubusercontent.com/yshalsager/megadown/master/megadown":
    "bin/megadown",
    "https://raw.githubusercontent.com/yshalsager/cmrudl.py/master/cmrudl.py":
    "bin/cmrudl"
}

for binary, path in binaries.items():
    downloader = SmartDL(binary, path, progress_bar=False)
    downloader.start()
    os.chmod(path, 0o755)

# Global Variables
COUNT_MSG = 0
USERS = {}
COUNT_PM = {}
LASTMSG = {}
CMD_HELP = {}
ISAFK = False
AFKREASON = None
SUDO_LIST = {}

from userbot.helpers import *
from userbot.helpers import functions as helldef
Пример #28
0
async def download(target_file):
    """ .download komutu userbot sunucusuna dosya indirmenizi sağlar. """
    await target_file.edit(LANG['DOWNLOADING'])
    input_str = target_file.pattern_match.group(1)
    if not os.path.isdir(TEMP_DOWNLOAD_DIRECTORY):
        os.makedirs(TEMP_DOWNLOAD_DIRECTORY)
    if "|" in input_str:
        url, file_name = input_str.split("|")
        url = url.strip()
        # https://stackoverflow.com/a/761825/4723940
        file_name = file_name.strip()
        head, tail = os.path.split(file_name)
        if head:
            if not os.path.isdir(os.path.join(TEMP_DOWNLOAD_DIRECTORY, head)):
                os.makedirs(os.path.join(TEMP_DOWNLOAD_DIRECTORY, head))
                file_name = os.path.join(head, tail)
        downloaded_file_name = TEMP_DOWNLOAD_DIRECTORY + "" + file_name
        downloader = SmartDL(url, downloaded_file_name, progress_bar=False)
        downloader.start(blocking=False)
        c_time = time.time()
        display_message = None
        while not downloader.isFinished():
            status = downloader.get_status().capitalize()
            total_length = downloader.filesize if downloader.filesize else None
            downloaded = downloader.get_dl_size()
            now = time.time()
            diff = now - c_time
            percentage = downloader.get_progress() * 100
            progress_str = "[{0}{1}] {2}%".format(
                ''.join(["▰" for i in range(math.floor(percentage / 10))]),
                ''.join(["▱"
                         for i in range(10 - math.floor(percentage / 10))]),
                round(percentage, 2))
            estimated_total_time = downloader.get_eta(human=True)
            try:
                current_message = f"{status}..\
                \n{LANG['URL']}: {url}\
                \n{LANG['FILENAME']}: {file_name}\
                \n{progress_str}\
                \n{humanbytes(downloaded)} of {humanbytes(total_length)}\
                \n{LANG['ETA']}: {estimated_total_time}"

                if round(diff %
                         10.00) == 0 and current_message != display_message:
                    await target_file.edit(current_message)
                    display_message = current_message
            except Exception as e:
                LOGS.info(str(e))
        if downloader.isSuccessful():
            await target_file.edit(
                LANG['SUCCESSFULLY'].format(downloaded_file_name))
        else:
            await target_file.edit(LANG['INVALID_URL'].format(url))
    elif target_file.reply_to_msg_id:
        try:
            c_time = time.time()
            downloaded_file_name = await target_file.client.download_media(
                await target_file.get_reply_message(),
                TEMP_DOWNLOAD_DIRECTORY,
                progress_callback=lambda d, t: asyncio.get_event_loop(
                ).create_task(
                    progress(d, t, target_file, c_time, LANG['DOWNLOADING'])))
        except Exception as e:  # pylint:disable=C0103,W0703
            await target_file.edit(str(e))
        else:
            await target_file.edit(
                LANG['SUCCESSFULLY'].format(downloaded_file_name))
    else:
        await target_file.edit(LANG['NEED_REPLY'])
Пример #29
0
async def download(dryb):
    """ For .gdrive command, upload files to google drive. """
    if not dryb.text[0].isalpha() and dryb.text[0] not in ("/", "#", "@", "!"):
        if dryb.fwd_from:
            return
        await dryb.edit("Processing ...")
        input_str = dryb.pattern_match.group(1)
        if CLIENT_ID is None or CLIENT_SECRET is None:
            return false
        if not os.path.isdir(Config.TMP_DOWNLOAD_DIRECTORY):
            os.makedirs(Config.TMP_DOWNLOAD_DIRECTORY)
            required_file_name = None
        elif input_str:
            start = datetime.now()
            url = input_str
            file_name = os.path.basename(url)
            if "|" in input_str:
                url, file_name = input_str.split("|")
            url = url.strip()
            file_name = file_name.strip()
            downloaded_file_name = Config.TMP_DOWNLOAD_DIRECTORY + "" + file_name
            downloader = SmartDL(url, downloaded_file_name, progress_bar=False)
            downloader.start(blocking=False)
            c_time = time.time()
            display_message = None
            while not downloader.isFinished():
                status = downloader.get_status().capitalize()
                total_length = downloader.filesize if downloader.filesize else None
                downloaded = downloader.get_dl_size()
                now = time.time()
                diff = now - c_time
                percentage = downloader.get_progress() * 100
                downloader.get_speed()
                round(diff) * 1000
                progress_str = "[{0}{1}]\nProgress: {2}%".format(
                    "".join(["●" for i in range(math.floor(percentage / 5))]),
                    "".join(["○" for i in range(20 - math.floor(percentage / 5))]),
                    round(percentage, 2),
                )
                estimated_total_time = downloader.get_eta(human=True)
                try:
                    current_message = f"{status}...\nURL: {url}\nFile Name: {file_name}\n{progress_str}\n{humanbytes(downloaded)} of {humanbytes(total_length)}\nETA: {estimated_total_time}"
                    if current_message != display_message:
                        await dryb.edit(current_message)
                        display_message = current_message
                        await asyncio.sleep(3)
                except Exception as e:
                    logger.info(str(e))
            end = datetime.now()
            ms = (end - start).seconds
            if downloader.isSuccessful():
                await dryb.edit(
                    "Downloaded to `{}` in {} seconds.\nNow Uploading to Google Drive...".format(
                        downloaded_file_name, ms
                    )
                )
                required_file_name = downloaded_file_name
            else:
                await dryb.edit("Incorrect URL\n{}".format(url))
        elif dryb.reply_to_msg_id:
            start = datetime.now()
            try:
                c_time = time.time()
                downloaded_file_name = await dryb.client.download_media(
                    await dryb.get_reply_message(),
                    Config.TMP_DOWNLOAD_DIRECTORY,
                    progress_callback=lambda d, t: asyncio.get_event_loop().create_task(
                        progress(d, t, dryb, c_time, "Downloading...")
                    ),
                )
            except Exception as e:  # pylint:disable=C0103,W0703
                await dryb.edit(str(e))
            else:
                end = datetime.now()
                required_file_name = downloaded_file_name
                ms = (end - start).seconds
                await dryb.edit(
                    "Downloaded to `{}` in {} seconds.\nNow Uploading to GDrive...".format(
                        required_file_name, ms
                    )
                )

    if required_file_name:
        #
        if Config.G_DRIVE_AUTH_TOKEN_DATA is not None:
            with open(G_DRIVE_TOKEN_FILE, "w") as t_file:
                t_file.write(Config.G_DRIVE_AUTH_TOKEN_DATA)
        # Check if token file exists, if not create it by requesting
        # authorization code
        if not os.path.isfile(G_DRIVE_TOKEN_FILE):
            storage = await create_token_file(G_DRIVE_TOKEN_FILE, dryb)
            http = authorize(G_DRIVE_TOKEN_FILE, storage)
        # Authorize, get file parameters, upload file and print out result URL
        # for download
        http = authorize(G_DRIVE_TOKEN_FILE, None)
        file_name, mime_type = file_ops(required_file_name)
        # required_file_name will have the full path
        # Sometimes API fails to retrieve starting URI, we wrap it.
        try:
            g_drive_link = await upload_file(
                http, required_file_name, file_name, mime_type, dryb
            )
            await dryb.edit(
                f"File:`{required_file_name}`\nHas Successfully Uploaded to : [Google Drive]({g_drive_link})"
            )
        except Exception as e:
            await dryb.edit(
                f"Error while uploading to Google Drive\nError Code:\n`{e}`"
            )
Пример #30
0
async def uploadtotg(message: Message):
    """ upload to telegram """
    flags = message.flags
    path_ = message.filtered_input_str
    if not path_:
        await message.edit("invalid input!, check `.help .upload`", del_in=5)
        return
    is_url = re.search(r"(?:https?|ftp)://[^|\s]+\.[^|\s]+", path_)
    del_path = False
    if is_url:
        del_path = True
        await message.edit("`Downloading From URL...`")
        if not os.path.isdir(Config.DOWN_PATH):
            os.mkdir(Config.DOWN_PATH)
        url = is_url[0]
        file_name = unquote_plus(os.path.basename(url))
        if "|" in path_:
            file_name = path_.split("|")[1].strip()
        path_ = os.path.join(Config.DOWN_PATH, file_name)
        try:
            downloader = SmartDL(url, path_, progress_bar=False)
            downloader.start(blocking=False)
            count = 0
            while not downloader.isFinished():
                if message.process_is_canceled:
                    downloader.stop()
                    raise Exception('Process Canceled!')
                total_length = downloader.filesize if downloader.filesize else 0
                downloaded = downloader.get_dl_size()
                percentage = downloader.get_progress() * 100
                speed = downloader.get_speed(human=True)
                estimated_total_time = downloader.get_eta(human=True)
                progress_str = \
                    "__{}__\n" + \
                    "```[{}{}]```\n" + \
                    "**Progress** : `{}%`\n" + \
                    "**URL** : `{}`\n" + \
                    "**FILENAME** : `{}`\n" + \
                    "**Completed** : `{}`\n" + \
                    "**Total** : `{}`\n" + \
                    "**Speed** : `{}`\n" + \
                    "**ETA** : `{}`"
                progress_str = progress_str.format(
                    "trying to download", ''.join(
                        (Config.FINISHED_PROGRESS_STR
                         for i in range(math.floor(percentage / 5)))),
                    ''.join((Config.UNFINISHED_PROGRESS_STR
                             for i in range(20 - math.floor(percentage / 5)))),
                    round(percentage,
                          2), url, file_name, humanbytes(downloaded),
                    humanbytes(total_length), speed, estimated_total_time)
                count += 1
                if count >= 5:
                    count = 0
                    await message.try_to_edit(progress_str,
                                              disable_web_page_preview=True)
                await asyncio.sleep(1)
        except Exception as d_e:
            await message.err(d_e)
            return
    if "|" in path_:
        path_, file_name = path_.split("|")
        path_ = path_.strip()
        if os.path.isfile(path_):
            new_path = os.path.join(Config.DOWN_PATH, file_name.strip())
            os.rename(path_, new_path)
            path_ = new_path
    try:
        string = Path(path_)
    except IndexError:
        await message.edit("wrong syntax\n`.upload [path]`")
    else:
        await message.delete()
        await explorer(string, message.chat.id, flags, del_path)