stop duplicate clone, view link optional and some changes (#147)
This commit is contained in:
parent
e805e7728f
commit
8694f9bb12
|
|
@ -219,6 +219,22 @@ try:
|
|||
STOP_DUPLICATE_MIRROR = False
|
||||
except KeyError:
|
||||
STOP_DUPLICATE_MIRROR = False
|
||||
try:
|
||||
VIEW_LINK = getConfig('VIEW_LINK')
|
||||
if VIEW_LINK.lower() == 'true':
|
||||
VIEW_LINK = True
|
||||
else:
|
||||
VIEW_LINK = False
|
||||
except KeyError:
|
||||
VIEW_LINK = False
|
||||
try:
|
||||
STOP_DUPLICATE_CLONE = getConfig('STOP_DUPLICATE_CLONE')
|
||||
if STOP_DUPLICATE_CLONE.lower() == 'true':
|
||||
STOP_DUPLICATE_CLONE = True
|
||||
else:
|
||||
STOP_DUPLICATE_CLONE = False
|
||||
except KeyError:
|
||||
STOP_DUPLICATE_CLONE = False
|
||||
try:
|
||||
IS_TEAM_DRIVE = getConfig('IS_TEAM_DRIVE')
|
||||
if IS_TEAM_DRIVE.lower() == 'true':
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ class YoutubeDLHelper(DownloadHelper):
|
|||
self.__listener.onDownloadError(error)
|
||||
|
||||
def extractMetaData(self, link, qual, name):
|
||||
if "hotstar" or "sonyliv" in link:
|
||||
if "hotstar" in link or "sonyliv" in link:
|
||||
self.opts['geo_bypass_country'] = 'IN'
|
||||
|
||||
with YoutubeDL(self.opts) as ydl:
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ from telegram import InlineKeyboardMarkup
|
|||
from bot.helper.telegram_helper import button_build
|
||||
from telegraph import Telegraph
|
||||
from bot import parent_id, DOWNLOAD_DIR, IS_TEAM_DRIVE, INDEX_URL, \
|
||||
USE_SERVICE_ACCOUNTS, download_dict, telegraph_token, BUTTON_FOUR_NAME, BUTTON_FOUR_URL, BUTTON_FIVE_NAME, BUTTON_FIVE_URL, BUTTON_SIX_NAME, BUTTON_SIX_URL, SHORTENER, SHORTENER_API, IMAGE_URL
|
||||
USE_SERVICE_ACCOUNTS, download_dict, telegraph_token, BUTTON_FOUR_NAME, BUTTON_FOUR_URL, BUTTON_FIVE_NAME, BUTTON_FIVE_URL, BUTTON_SIX_NAME, BUTTON_SIX_URL, SHORTENER, SHORTENER_API, IMAGE_URL, VIEW_LINK
|
||||
from bot.helper.ext_utils.bot_utils import *
|
||||
from bot.helper.ext_utils.fs_utils import get_mime_type, get_path_size
|
||||
|
||||
|
|
@ -56,6 +56,9 @@ class GoogleDriveHelper:
|
|||
self.update_interval = 3
|
||||
self.telegraph_content = []
|
||||
self.path = []
|
||||
self.total_bytes = 0
|
||||
self.total_files = 0
|
||||
self.total_folders = 0
|
||||
|
||||
def cancel(self):
|
||||
self.is_cancelled = True
|
||||
|
|
@ -195,9 +198,11 @@ class GoogleDriveHelper:
|
|||
if reason == 'userRateLimitExceeded' or reason == 'dailyLimitExceeded':
|
||||
if USE_SERVICE_ACCOUNTS:
|
||||
if not self.switchServiceAccount():
|
||||
return None
|
||||
raise err
|
||||
LOGGER.info(f"Got: {reason}, Trying Again.")
|
||||
return self.upload_file(file_path, file_name, mime_type, parent_id)
|
||||
else:
|
||||
raise err
|
||||
else:
|
||||
raise err
|
||||
self._file_uploaded_bytes = 0
|
||||
|
|
@ -210,8 +215,6 @@ class GoogleDriveHelper:
|
|||
return download_url
|
||||
|
||||
def upload(self, file_name: str):
|
||||
self.total_files = 0
|
||||
self.total_folders = 0
|
||||
if USE_SERVICE_ACCOUNTS:
|
||||
self.service_account_count = len(os.listdir("accounts"))
|
||||
self.__listener.onUploadStarted()
|
||||
|
|
@ -285,6 +288,8 @@ class GoogleDriveHelper:
|
|||
raise err
|
||||
LOGGER.info(f"Got: {reason}, Trying Again.")
|
||||
return self.copyFile(file_id,dest_id)
|
||||
else:
|
||||
raise err
|
||||
else:
|
||||
raise err
|
||||
|
||||
|
|
@ -316,9 +321,6 @@ class GoogleDriveHelper:
|
|||
return files
|
||||
|
||||
def clone(self, link):
|
||||
self.transferred_size = 0
|
||||
self.total_files = 0
|
||||
self.total_folders = 0
|
||||
try:
|
||||
file_id = self.getIdFromUrl(link)
|
||||
except (KeyError,IndexError):
|
||||
|
|
@ -383,10 +385,12 @@ class GoogleDriveHelper:
|
|||
siurl = requests.get(f'https://{SHORTENER}/api?api={SHORTENER_API}&url={url}&format=text').text
|
||||
siurls = requests.get(f'https://{SHORTENER}/api?api={SHORTENER_API}&url={urls}&format=text').text
|
||||
buttons.buildbutton("⚡ Index Link", siurl)
|
||||
buttons.buildbutton("🌐 View Link", siurls)
|
||||
if VIEW_LINK:
|
||||
buttons.buildbutton("🌐 View Link", siurls)
|
||||
else:
|
||||
buttons.buildbutton("⚡ Index Link", url)
|
||||
buttons.buildbutton("🌐 View Link", urls)
|
||||
if VIEW_LINK:
|
||||
buttons.buildbutton("🌐 View Link", urls)
|
||||
if BUTTON_FOUR_NAME is not None and BUTTON_FOUR_URL is not None:
|
||||
buttons.buildbutton(f"{BUTTON_FOUR_NAME}", f"{BUTTON_FOUR_URL}")
|
||||
if BUTTON_FIVE_NAME is not None and BUTTON_FIVE_URL is not None:
|
||||
|
|
@ -399,7 +403,13 @@ class GoogleDriveHelper:
|
|||
err = err.last_attempt.exception()
|
||||
err = str(err).replace('>', '').replace('<', '')
|
||||
LOGGER.error(err)
|
||||
return 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 msg, InlineKeyboardMarkup(buttons.build_menu(2))
|
||||
|
||||
def cloneFolder(self, name, local_path, folder_id, parent_id):
|
||||
|
|
@ -573,9 +583,13 @@ class GoogleDriveHelper:
|
|||
if SHORTENER is not None and SHORTENER_API is not None:
|
||||
siurl = requests.get(f'https://{SHORTENER}/api?api={SHORTENER_API}&url={url}&format=text').text
|
||||
siurls = requests.get(f'https://{SHORTENER}/api?api={SHORTENER_API}&url={urls}&format=text').text
|
||||
msg += f' <b>| <a href="{siurl}">Index Link</a></b> <b>| <a href="{siurls}">View Link</a></b>'
|
||||
msg += f' <b>| <a href="{siurl}">Index Link</a></b>'
|
||||
if VIEW_LINK:
|
||||
msg += f' <b>| <a href="{siurls}">View Link</a></b>'
|
||||
else:
|
||||
msg += f' <b>| <a href="{url}">Index Link</a></b> <b>| <a href="{urls}">View Link</a></b>'
|
||||
msg += f' <b>| <a href="{url}">Index Link</a></b>'
|
||||
if VIEW_LINK:
|
||||
msg += f' <b>| <a href="{urls}">View Link</a></b>'
|
||||
msg += '<br><br>'
|
||||
content_count += 1
|
||||
if content_count == TELEGRAPHLIMIT :
|
||||
|
|
@ -612,14 +626,11 @@ class GoogleDriveHelper:
|
|||
|
||||
|
||||
def count(self, link):
|
||||
self.total_bytes = 0
|
||||
self.total_files = 0
|
||||
self.total_folders = 0
|
||||
try:
|
||||
file_id = self.getIdFromUrl(link)
|
||||
except (KeyError,IndexError):
|
||||
msg = "Google drive ID could not be found in the provided link"
|
||||
return msg, ""
|
||||
return msg
|
||||
msg = ""
|
||||
LOGGER.info(f"File ID: {file_id}")
|
||||
try:
|
||||
|
|
@ -634,7 +645,6 @@ class GoogleDriveHelper:
|
|||
msg += f'\n<b>Type: </b><code>Folder</code>'
|
||||
msg += f'\n<b>SubFolders: </b><code>{self.total_folders}</code>'
|
||||
msg += f'\n<b>Files: </b><code>{self.total_files}</code>'
|
||||
clonesizelimit = self.total_bytes
|
||||
else:
|
||||
msg += f'<b>Filename: </b><code>{name}</code>'
|
||||
try:
|
||||
|
|
@ -647,7 +657,6 @@ class GoogleDriveHelper:
|
|||
msg += f'\n<b>Size: </b><code>{get_readable_file_size(self.total_bytes)}</code>'
|
||||
msg += f'\n<b>Type: </b><code>{typee}</code>'
|
||||
msg += f'\n<b>Files: </b><code>{self.total_files}</code>'
|
||||
clonesizelimit = self.total_bytes
|
||||
except TypeError:
|
||||
pass
|
||||
except Exception as err:
|
||||
|
|
@ -660,8 +669,8 @@ class GoogleDriveHelper:
|
|||
msg = "File not found."
|
||||
else:
|
||||
msg = f"Error.\n{err}"
|
||||
return msg, ""
|
||||
return msg, clonesizelimit
|
||||
return msg
|
||||
return msg
|
||||
|
||||
def gDrive_file(self, **kwargs):
|
||||
try:
|
||||
|
|
@ -681,3 +690,38 @@ class GoogleDriveHelper:
|
|||
else:
|
||||
self.total_files += 1
|
||||
self.gDrive_file(**file_)
|
||||
|
||||
def clonehelper(self, link):
|
||||
try:
|
||||
file_id = self.getIdFromUrl(link)
|
||||
except (KeyError,IndexError):
|
||||
msg = "Google drive ID could not be found in the provided link"
|
||||
return msg, "", ""
|
||||
LOGGER.info(f"File ID: {file_id}")
|
||||
try:
|
||||
drive_file = self.__service.files().get(fileId=file_id, fields="id, name, mimeType, size",
|
||||
supportsTeamDrives=True).execute()
|
||||
name = drive_file['name']
|
||||
LOGGER.info(f"Checking: {name}")
|
||||
if drive_file['mimeType'] == self.__G_DRIVE_DIR_MIME_TYPE:
|
||||
self.gDrive_directory(**drive_file)
|
||||
else:
|
||||
try:
|
||||
self.total_files += 1
|
||||
self.gDrive_file(**drive_file)
|
||||
except TypeError:
|
||||
pass
|
||||
clonesize = self.total_bytes
|
||||
except Exception as err:
|
||||
if isinstance(err, RetryError):
|
||||
LOGGER.info(f"Total Attempts: {err.last_attempt.attempt_number}")
|
||||
err = err.last_attempt.exception()
|
||||
err = str(err).replace('>', '').replace('<', '')
|
||||
LOGGER.error(err)
|
||||
if "File not found" in str(err):
|
||||
msg = "File not found."
|
||||
else:
|
||||
msg = f"Error.\n{err}"
|
||||
return msg, "", ""
|
||||
return "", clonesize, name
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,8 @@ from bot.helper.mirror_utils.upload_utils.gdriveTools import GoogleDriveHelper
|
|||
from bot.helper.telegram_helper.message_utils import sendMarkup, deleteMessage, sendMessage
|
||||
from bot.helper.telegram_helper.filters import CustomFilters
|
||||
from bot.helper.telegram_helper.bot_commands import BotCommands
|
||||
from bot import dispatcher, CLONE_LIMIT
|
||||
from bot import dispatcher, CLONE_LIMIT, STOP_DUPLICATE_CLONE
|
||||
from bot.helper.ext_utils.bot_utils import get_readable_file_size
|
||||
|
||||
|
||||
@run_async
|
||||
|
|
@ -12,32 +13,39 @@ def cloneNode(update, context):
|
|||
if len(args) > 1:
|
||||
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:
|
||||
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
|
||||
if CLONE_LIMIT is not None:
|
||||
mssg = sendMessage(f"Checking The Size...", context.bot, update)
|
||||
limit = CLONE_LIMIT
|
||||
limit = limit.split(' ', maxsplit=1)
|
||||
limitint = int(limit[0])
|
||||
res, clonesizelimit = gd.count(link)
|
||||
if clonesizelimit != "":
|
||||
msgg = f'Failed, Clone limit is {CLONE_LIMIT}'
|
||||
if 'GB' in limit or 'gb' in limit:
|
||||
if clonesizelimit > limitint * 1024**3:
|
||||
deleteMessage(context.bot, mssg)
|
||||
sendMessage(msgg, context.bot, update)
|
||||
return
|
||||
else:
|
||||
deleteMessage(context.bot, mssg)
|
||||
elif 'TB' in limit or 'tb' in limit:
|
||||
if clonesizelimit > limitint * 1024**4:
|
||||
deleteMessage(context.bot, mssg)
|
||||
sendMessage(msgg, context.bot, update)
|
||||
return
|
||||
else:
|
||||
deleteMessage(context.bot, mssg)
|
||||
else:
|
||||
deleteMessage(context.bot, mssg)
|
||||
sendMessage(res, context.bot, update)
|
||||
return
|
||||
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 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:
|
||||
if clonesize > limitint * 1024**4:
|
||||
deleteMessage(context.bot, msg1)
|
||||
sendMessage(msg2, context.bot, update)
|
||||
return
|
||||
else:
|
||||
deleteMessage(context.bot, msg1)
|
||||
msg = sendMessage(f"Cloning: <code>{link}</code>", context.bot, update)
|
||||
result, button = gd.clone(link)
|
||||
deleteMessage(context.bot, msg)
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ def countNode(update, context):
|
|||
link = args[1]
|
||||
msg = sendMessage(f"Counting: <code>{link}</code>", context.bot, update)
|
||||
gd = GoogleDriveHelper()
|
||||
result, empty = gd.count(link)
|
||||
result = gd.count(link)
|
||||
deleteMessage(context.bot, msg)
|
||||
if update.message.from_user.username:
|
||||
uname = f'@{update.message.from_user.username}'
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import requests
|
|||
from telegram.ext import CommandHandler, run_async
|
||||
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
|
||||
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.helper.ext_utils import fs_utils, bot_utils
|
||||
from bot.helper.ext_utils.bot_utils import setInterval, get_mega_link_type
|
||||
|
|
@ -178,10 +178,12 @@ class MirrorListener(listeners.MirrorListeners):
|
|||
siurl = requests.get(f'https://{SHORTENER}/api?api={SHORTENER_API}&url={share_url}&format=text').text
|
||||
siurls = requests.get(f'https://{SHORTENER}/api?api={SHORTENER_API}&url={share_urls}&format=text').text
|
||||
buttons.buildbutton("⚡ Index Link", siurl)
|
||||
buttons.buildbutton("🌐 View Link", siurls)
|
||||
if VIEW_LINK:
|
||||
buttons.buildbutton("🌐 View Link", siurls)
|
||||
else:
|
||||
buttons.buildbutton("⚡ Index Link", share_url)
|
||||
buttons.buildbutton("🌐 View Link", share_urls)
|
||||
if VIEW_LINK:
|
||||
buttons.buildbutton("🌐 View Link", share_urls)
|
||||
if BUTTON_FOUR_NAME is not None and BUTTON_FOUR_URL is not None:
|
||||
buttons.buildbutton(f"{BUTTON_FOUR_NAME}", f"{BUTTON_FOUR_URL}")
|
||||
if BUTTON_FIVE_NAME is not None and BUTTON_FIVE_URL is not None:
|
||||
|
|
|
|||
|
|
@ -23,9 +23,10 @@ MEGA_PASSWORD = ""
|
|||
BLOCK_MEGA_FOLDER = ""
|
||||
BLOCK_MEGA_LINKS = ""
|
||||
STOP_DUPLICATE_MIRROR = ""
|
||||
STOP_DUPLICATE_CLONE = ""
|
||||
SHORTENER = ""
|
||||
SHORTENER_API = ""
|
||||
CLONE_LIMIT = "" #leave space between number and unit (tb or gb only)
|
||||
CLONE_LIMIT = "" #leave space between number and unit (TB or GB only)
|
||||
IMAGE_URL = "https://telegra.ph/file/db03910496f06094f1f7a.jpg"
|
||||
# Change ENABLE_FILESIZE_LIMIT = True if you want to use MAX_TORRENT_SIZE
|
||||
ENABLE_FILESIZE_LIMIT = false
|
||||
|
|
@ -33,6 +34,8 @@ MAX_TORRENT_SIZE = 15
|
|||
# Fill only if you deploying with heroku-cli and Goorm IDE
|
||||
HEROKU_API_KEY = ""
|
||||
HEROKU_APP_NAME = ""
|
||||
#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 Code)
|
||||
VIEW_LINK = "False"
|
||||
# Add more buttons (Three buttons are already added of Drive Link, Index Link, and View Link, you can add extra buttons too, these are optional)
|
||||
# If you don't know what are below entries, simply leave them, Don't fill anything in them.
|
||||
BUTTON_FOUR_NAME = ""
|
||||
|
|
|
|||
Loading…
Reference in New Issue