From 1a222a3cfc5fe5825d4bff961cf657efa36e8c87 Mon Sep 17 00:00:00 2001 From: Hafitz Setya <71178188+breakdowns@users.noreply.github.com> Date: Wed, 24 Mar 2021 07:24:16 +0700 Subject: [PATCH] v4.4.4 (#35) - cc after clone finish. Thanks to anasty17 - Change to yt-dlp --- README.md | 3 +- .../youtube_dl_download_helper.py | 2 +- .../mirror_utils/upload_utils/gdriveTools.py | 13 ++++----- bot/modules/clone.py | 29 ++++++++----------- requirements.txt | 2 +- 5 files changed, 21 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 07a10185181..860f1a347c5 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ [![Slam](https://telegra.ph/file/db03910496f06094f1f7a.jpg)](https://youtu.be/Pk_TthHfLeE) # Slam Mirror Bot -This is a telegram bot writen in python for mirroring files on the internet to our beloved Google Drive. This project is heavily inspired from @out386 's telegram bot which is written in JS. +This is a telegram bot writen in python for mirroring files on the internet to our beloved Google Drive. ## How to deploy? Deploying is pretty much straight forward and is divided into several steps as follows: @@ -170,6 +170,7 @@ where host is the name of extractor (eg. youtube, twitch). Multiple accounts of ## Credits Thanks to: +- [out386](https://github.com/out386) heavily inspired from telegram bot which is written in JS. - [Izzy12](https://github.com/lzzy12/) for original repo - [Dank-del](https://github.com/Dank-del/) for base repo - [magneto261290](https://github.com/magneto261290/) for some features diff --git a/bot/helper/mirror_utils/download_utils/youtube_dl_download_helper.py b/bot/helper/mirror_utils/download_utils/youtube_dl_download_helper.py index e4f87483421..6363c8a62a3 100644 --- a/bot/helper/mirror_utils/download_utils/youtube_dl_download_helper.py +++ b/bot/helper/mirror_utils/download_utils/youtube_dl_download_helper.py @@ -1,6 +1,6 @@ from .download_helper import DownloadHelper import time -from youtube_dl import YoutubeDL, DownloadError +from yt_dlp import YoutubeDL, DownloadError from bot import download_dict_lock, download_dict from ..status_utils.youtube_dl_download_status import YoutubeDLDownloadStatus import logging diff --git a/bot/helper/mirror_utils/upload_utils/gdriveTools.py b/bot/helper/mirror_utils/upload_utils/gdriveTools.py index c3869a1f97a..5a315f37b9a 100644 --- a/bot/helper/mirror_utils/upload_utils/gdriveTools.py +++ b/bot/helper/mirror_utils/upload_utils/gdriveTools.py @@ -269,7 +269,10 @@ def copyFile(self, file_id, dest_id): if err.resp.get('content-type', '').startswith('application/json'): reason = json.loads(err.content).get('error').get('errors')[0].get('reason') if reason == 'userRateLimitExceeded' or reason == 'dailyLimitExceeded': - raise err + if USE_SERVICE_ACCOUNTS: + self.switchServiceAccount() + LOGGER.info(f"Got: {reason}, Trying Again.") + return self.copyFile(file_id,dest_id) else: raise err @@ -368,13 +371,7 @@ def clone(self, link): err = err.last_attempt.exception() err = str(err).replace('>', '').replace('<', '') LOGGER.error(err) - if "User rate limit exceeded" in str(err): - msg = "User rate limit exceeded." - elif "File not found" in str(err): - msg = "File not found." - else: - msg = f"Error.\n{err}" - return msg, "" + return err, "" return msg, InlineKeyboardMarkup(buttons.build_menu(2)) def cloneFolder(self, name, local_path, folder_id, parent_id): diff --git a/bot/modules/clone.py b/bot/modules/clone.py index 418c5c4a4b5..5fc899235f4 100644 --- a/bot/modules/clone.py +++ b/bot/modules/clone.py @@ -4,33 +4,28 @@ from bot.helper.telegram_helper.filters import CustomFilters from bot.helper.telegram_helper.bot_commands import BotCommands from bot.helper.ext_utils.bot_utils import new_thread -from bot import dispatcher, LOGGER +from bot import dispatcher @new_thread def cloneNode(update,context): - if update.message.from_user.last_name: - last_name = f" {update.message.from_user.last_name}" - else: - last_name = "" + args = update.message.text.split(" ",maxsplit=1) if update.message.from_user.username: - username = f"@{update.message.from_user.username}" + uname = f"@{update.message.from_user.username}" else: - username = "" - name = f'{update.message.from_user.first_name}{last_name}' - - args = update.message.text.split(" ",maxsplit=1) + uname = f'{update.message.from_user.first_name}' + if uname is not None: + cc = f'\n\ncc: {uname}' if len(args) > 1: link = args[1] - msg = f'Cloning...\n' \ - f'User: {username}\n' \ - f'Link: {link}' - sendMessage(msg, context.bot, update) + msg = sendMessage(f"Cloning: {link}",context.bot,update) gd = GoogleDriveHelper() result, button = gd.clone(link) - LOGGER.info('ID: {} - Username: {} - Message: {}'.format(update.message.chat.id,update.message.chat.username,update.message.text)) - # deleteMessage(context.bot,msg) - sendMarkup(result,context.bot,update,button) + deleteMessage(context.bot,msg) + if button == "": + sendMessage(result,context.bot,update) + else: + sendMarkup(result + cc,context.bot,update,button) else: sendMessage("Provide G-Drive Shareable Link to Clone.",context.bot,update) diff --git a/requirements.txt b/requirements.txt index 267a98232f9..0f21557297f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -13,7 +13,7 @@ python-magic beautifulsoup4>=4.8.2,<4.8.10 pyrogram TgCrypto -youtube_dl +yt-dlp feedparser natsort heroku3