Add tar/unzip limit and some updates (#251)

* Add tar/unzip limit and some updates

Signed-off-by: anas <e.anastayyar@gmail.com>
Co-authored-by: Hafitz Setya <hafitz666@outlook.co.id>
This commit is contained in:
Anas 2021-06-30 09:47:50 +03:00 committed by GitHub
parent 22b92e5ebd
commit 14a8287b04
Signed by untrusted user: GitHub
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 78 additions and 63 deletions

View File

@ -18,7 +18,7 @@
# Features supported:
## Additional Features
- Updater (**NOTE**: You must upload your **token.pickle** to Index and fill your **token.pickle** url to **TOKEN_PICKLE_URL**, because your **token.pickle** will deleted after update)
- Limiting size Torrent/Direct, Mega, cloning Google Drive support
- Limiting size Torrent/Direct, Tar/Unzip, Mega, cloning Google Drive support
- Get detailed info about replied media (Only for Telegram file)
- Stop duplicate cloning Google Drive & mirroring Mega support
- Tar/Unzip Google Drive link support
@ -156,6 +156,7 @@ Fill up rest of the fields. Meaning of each fields are discussed below:
- **CLONE_LIMIT**: To limit cloning Google Drive (leave space between number and unit, Available units is (gb or GB, tb or TB).
- **MEGA_LIMIT**: To limit downloading Mega (leave space between number and unit, Available units is (gb or GB, tb or TB).
- **TORRENT_DIRECT_LIMIT**: To limit the Torrent/Direct mirror size, Leave space between number and unit. Available units is (gb or GB, tb or TB).
- **TAR_UNZIP_LIMIT**: To limit mirroring as Tar or unzipmirror. Available units is (gb or GB, tb or TB).
- **IMAGE_URL**: Show Image/Logo in /start message. Fill value of image your link image, use telegra.ph or any direct link image.
- **VIEW_LINK**: View Link button to open file Index Link in browser instead of direct download link, you can figure out if it's compatible with your Index code or not, open any video from you Index and check if the END of link from browser link bar is `?a=view`, if yes make it `True` it will work (Compatible with [Bhadoo Index](https://gitlab.com/ParveenBhadooOfficial/Google-Drive-Index) Code)
- **UPTOBOX_TOKEN**: Uptobox token to mirror uptobox links. Get it from [Uptobox Premium Account](https://uptobox.com/my_account).

View File

@ -112,6 +112,10 @@
"description": "To limit the Torrent/Direct mirror size, Leave space between number and unit. Available units is (gb or GB, tb or TB).",
"required": false
},
"TAR_UNZIP_LIMIT": {
"description": "To limit mirroring as Tar or unzipmirror. Available units is (gb or GB, tb or TB).",
"required": false
},
"CLONE_LIMIT": {
"description": "To limit cloning Google Drive (leave space between number and unit, Available units is (gb or GB, tb or TB).",
"required": false

View File

@ -189,6 +189,12 @@ try:
MEGA_LIMIT = None
except KeyError:
MEGA_LIMIT = None
try:
TAR_UNZIP_LIMIT = getConfig('TAR_UNZIP_LIMIT')
if len(TAR_UNZIP_LIMIT) == 0:
TAR_UNZIP_LIMIT = None
except KeyError:
TAR_UNZIP_LIMIT = None
try:
BUTTON_FOUR_NAME = getConfig('BUTTON_FOUR_NAME')
BUTTON_FOUR_URL = getConfig('BUTTON_FOUR_URL')

View File

@ -1,4 +1,4 @@
from bot import aria2, download_dict_lock, STOP_DUPLICATE_MIRROR, TORRENT_DIRECT_LIMIT
from bot import aria2, download_dict_lock, STOP_DUPLICATE_MIRROR, TORRENT_DIRECT_LIMIT, TAR_UNZIP_LIMIT
from bot.helper.mirror_utils.upload_utils.gdriveTools import GoogleDriveHelper
from bot.helper.ext_utils.bot_utils import *
from .download_helper import DownloadHelper
@ -16,7 +16,7 @@ class AriaDownloadHelper(DownloadHelper):
@new_thread
def __onDownloadStarted(self, api, gid):
if STOP_DUPLICATE_MIRROR or TORRENT_DIRECT_LIMIT is not None:
if STOP_DUPLICATE_MIRROR or TORRENT_DIRECT_LIMIT is not None or TAR_UNZIP_LIMIT is not None:
sleep(0.5)
dl = getDownloadByGid(gid)
download = api.get_download(gid)
@ -38,23 +38,31 @@ class AriaDownloadHelper(DownloadHelper):
sendMarkup("Here are the search results:", dl.getListener().bot, dl.getListener().update, button)
return
if TORRENT_DIRECT_LIMIT is not None:
LOGGER.info(f"Checking File/Folder Size...")
sleep(1.5)
size = aria2.get_download(gid).total_length
limit = TORRENT_DIRECT_LIMIT
limit = limit.split(' ', maxsplit=1)
limitint = int(limit[0])
if 'GB' in limit or 'gb' in limit:
if size > limitint * 1024**3:
aria2.remove([download])
dl.getListener().onDownloadError(f'Torrent/Direct limit is {TORRENT_DIRECT_LIMIT}.\nYour File/Folder size is {get_readable_file_size(size)}')
return
elif 'TB' in limit or 'tb' in limit:
if size > limitint * 1024**4:
aria2.remove([download])
dl.getListener().onDownloadError(f'Torrent/Direct limit is {TORRENT_DIRECT_LIMIT}.\nYour File/Folder size is {get_readable_file_size(size)}')
return
if TORRENT_DIRECT_LIMIT is not None or TAR_UNZIP_LIMIT is not None:
limit = None
if TAR_UNZIP_LIMIT is not None and (self.listener.isTar or self.listener.extract):
LOGGER.info(f"Checking File/Folder Size...")
limit = TAR_UNZIP_LIMIT
mssg = f'Tar/Unzip limit is {TAR_UNZIP_LIMIT}'
elif TORRENT_DIRECT_LIMIT is not None and limit is None:
LOGGER.info(f"Checking File/Folder Size...")
limit = TORRENT_DIRECT_LIMIT
mssg = f'Torrent/Direct limit is {TORRENT_DIRECT_LIMIT}'
if limit is not None:
sleep(1.5)
size = aria2.get_download(gid).total_length
limit = limit.split(' ', maxsplit=1)
limitint = int(limit[0])
if 'G' in limit[1] or 'g' in limit[1]:
if size > limitint * 1024**3:
aria2.remove([download])
dl.getListener().onDownloadError(f'{mssg}.\nYour File/Folder size is {get_readable_file_size(size)}')
return
elif 'T' in limit[1] or 't' in limit[1]:
if size > limitint * 1024**4:
aria2.remove([download])
dl.getListener().onDownloadError(f'{mssg}.\nYour File/Folder size is {get_readable_file_size(size)}')
return
update_all_messages()
def __onDownloadComplete(self, api: API, gid):

View File

@ -6,7 +6,7 @@ import os
from bot.helper.ext_utils.bot_utils import new_thread, get_mega_link_type, get_readable_file_size
from bot.helper.mirror_utils.status_utils.mega_download_status import MegaDownloadStatus
from bot.helper.mirror_utils.upload_utils.gdriveTools import GoogleDriveHelper
from bot import MEGA_LIMIT, STOP_DUPLICATE_MEGA
from bot import MEGA_LIMIT, STOP_DUPLICATE_MEGA, TAR_UNZIP_LIMIT
import random
import string
@ -164,8 +164,6 @@ class MegaDownloadHelper:
node = folder_api.authorizeNode(mega_listener.node)
if mega_listener.error is not None:
return listener.onDownloadError(str(mega_listener.error))
if STOP_DUPLICATE_MEGA or MEGA_LIMIT is not None:
msg = sendMessage('Checking Your Link...', listener.bot, listener.update)
if STOP_DUPLICATE_MEGA:
LOGGER.info(f'Checking File/Folder if already in Drive')
mname = node.getName()
@ -177,34 +175,29 @@ class MegaDownloadHelper:
gd = GoogleDriveHelper()
smsg, button = gd.drive_list(mname)
if smsg:
deleteMessage(listener.bot, msg)
msg1 = "File/Folder is already available in Drive.\nHere are the search results:"
sendMarkup(msg1, listener.bot, listener.update, button)
return
else:
if MEGA_LIMIT is None:
deleteMessage(listener.bot, msg)
if MEGA_LIMIT is not None:
if MEGA_LIMIT is not None or TAR_UNZIP_LIMIT is not None:
limit = None
LOGGER.info(f'Checking File/Folder Size')
limit = MEGA_LIMIT
limit = limit.split(' ', maxsplit=1)
limitint = int(limit[0])
msg3 = f'Failed, Mega limit is {MEGA_LIMIT}.\nYour File/Folder size is {get_readable_file_size(api.getSize(node))}.'
if 'GB' in limit or 'gb' in limit:
if api.getSize(node) > limitint * 1024**3:
deleteMessage(listener.bot, msg)
sendMessage(msg3, listener.bot, listener.update)
return
else:
deleteMessage(listener.bot, msg)
elif 'TB' in limit or 'tb' in limit:
if api.getSize(node) > limitint * 1024**4:
deleteMessage(listener.bot, msg)
sendMessage(msg3, listener.bot, listener.update)
return
else:
deleteMessage(listener.bot, msg)
if TAR_UNZIP_LIMIT is not None and (listener.isTar or listener.extract):
limit = TAR_UNZIP_LIMIT
msg3 = f'Failed, Tar/Unzip limit is {TAR_UNZIP_LIMIT}.\nYour File/Folder size is {get_readable_file_size(api.getSize(node))}.'
elif MEGA_LIMIT is not None and limit is None:
limit = MEGA_LIMIT
msg3 = f'Failed, Mega limit is {MEGA_LIMIT}.\nYour File/Folder size is {get_readable_file_size(api.getSize(node))}.'
if limit is not None:
limit = limit.split(' ', maxsplit=1)
limitint = int(limit[0])
if 'G' in limit[1] or 'g' in limit[1]:
if api.getSize(node) > limitint * 1024**3:
sendMessage(msg3, listener.bot, listener.update)
return
elif 'T' in limit[1] or 't' in limit[1]:
if api.getSize(node) > limitint * 1024**4:
sendMessage(msg3, listener.bot, listener.update)
return
with download_dict_lock:
download_dict[listener.uid] = MegaDownloadStatus(mega_listener, listener)
os.makedirs(path)

View File

@ -13,43 +13,31 @@ def cloneNode(update, context):
link = args[1]
gd = GoogleDriveHelper()
if CLONE_LIMIT is not None or STOP_DUPLICATE_CLONE:
msg1 = sendMessage(f"Checking Your Link...", context.bot, update)
res, clonesize, name = gd.clonehelper(link)
if res != "":
deleteMessage(context.bot, msg1)
sendMessage(res, context.bot, update)
return
if STOP_DUPLICATE_CLONE:
LOGGER.info(f"Checking File/Folder if already in Drive...")
smsg, button = gd.drive_list(name)
if smsg:
deleteMessage(context.bot, msg1)
msg3 = "File/Folder is already available in Drive.\nHere are the search results:"
sendMarkup(msg3, context.bot, update, button)
return
else:
if CLONE_LIMIT is None:
deleteMessage(context.bot, msg1)
if CLONE_LIMIT is not None:
LOGGER.info(f"Checking File/Folder Size...")
limit = CLONE_LIMIT
limit = limit.split(' ', maxsplit=1)
limitint = int(limit[0])
msg2 = f'Failed, Clone limit is {CLONE_LIMIT}.\nYour File/Folder size is {get_readable_file_size(clonesize)}.'
if 'GB' in limit or 'gb' in limit:
if 'G' in limit[1] or 'g' in limit[1]:
if clonesize > limitint * 1024**3:
deleteMessage(context.bot, msg1)
sendMessage(msg2, context.bot, update)
return
else:
deleteMessage(context.bot, msg1)
elif 'TB' in limit or 'tb' in limit:
elif 'T' in limit[1] or 't' in limit[1]:
if clonesize > limitint * 1024**4:
deleteMessage(context.bot, msg1)
sendMessage(msg2, context.bot, update)
return
else:
deleteMessage(context.bot, msg1)
return
msg = sendMessage(f"Cloning: <code>{link}</code>", context.bot, update)
result, button = gd.clone(link)
deleteMessage(context.bot, msg)

View File

@ -3,7 +3,7 @@ from telegram.ext import CommandHandler
from telegram import InlineKeyboardMarkup
from bot import Interval, INDEX_URL, BUTTON_FOUR_NAME, BUTTON_FOUR_URL, BUTTON_FIVE_NAME, BUTTON_FIVE_URL, BUTTON_SIX_NAME, BUTTON_SIX_URL, BLOCK_MEGA_FOLDER, BLOCK_MEGA_LINKS, VIEW_LINK
from bot import dispatcher, DOWNLOAD_DIR, DOWNLOAD_STATUS_UPDATE_INTERVAL, download_dict, download_dict_lock, SHORTENER, SHORTENER_API
from bot import dispatcher, DOWNLOAD_DIR, DOWNLOAD_STATUS_UPDATE_INTERVAL, download_dict, download_dict_lock, SHORTENER, SHORTENER_API, TAR_UNZIP_LIMIT
from bot.helper.ext_utils import fs_utils, bot_utils
from bot.helper.ext_utils.bot_utils import setInterval, get_mega_link_type
from bot.helper.ext_utils.exceptions import DirectDownloadLinkException, NotSupportedExtractionArchive
@ -305,6 +305,20 @@ def _mirror(bot, update, isTar=False, extract=False):
if res != "":
sendMessage(res, bot, update)
return
if TAR_UNZIP_LIMIT is not None:
LOGGER.info(f'Checking File/Folder Size')
limit = TAR_UNZIP_LIMIT
limit = limit.split(' ', maxsplit=1)
limitint = int(limit[0])
msg = f'Failed, Tar/Unzip limit is {TAR_UNZIP_LIMIT}.\nYour File/Folder size is {get_readable_file_size(size)}.'
if 'G' in limit[1] or 'g' in limit[1]:
if size > limitint * 1024**3:
sendMessage(msg, listener.bot, listener.update)
return
elif 'T' in limit[1] or 't' in limit[1]:
if size > limitint * 1024**4:
sendMessage(msg, listener.bot, listener.update)
return
LOGGER.info(f"Download Name : {name}")
drive = gdriveTools.GoogleDriveHelper(name, listener)
gid = ''.join(random.SystemRandom().choices(string.ascii_letters + string.digits, k=12))

View File

@ -37,6 +37,7 @@ ACCOUNTS_ZIP_URL = ""
TOKEN_PICKLE_URL = ""
# To use limit leave space between number and unit. Available units is (gb or GB, tb or TB)
TORRENT_DIRECT_LIMIT = ""
TAR_UNZIP_LIMIT = ""
CLONE_LIMIT = ""
MEGA_LIMIT = ""
# Fill only if you deploying with heroku-cli and Goorm IDE