Skip to content

Commit

Permalink
Remove AppDrive support
Browse files Browse the repository at this point in the history
- This removes support for cloning, archiving and extracting data from AppDrive since the website admin has added Google reCAPTCHA on the login page and it can't be bypassed as of now
  • Loading branch information
l3v11 authored Dec 13, 2022
1 parent 95ae9d3 commit 2f865fb
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 115 deletions.
6 changes: 0 additions & 6 deletions bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,6 @@
except Exception as err:
LOGGER.error(f"DRIVE_LIST_URL: {err}")

APPDRIVE_EMAIL = os.environ.get('APPDRIVE_EMAIL', '')
APPDRIVE_PASS = os.environ.get('APPDRIVE_PASS', '')
if len(APPDRIVE_EMAIL) == 0 or len(APPDRIVE_PASS) == 0:
APPDRIVE_EMAIL = None
APPDRIVE_PASS = None

GDTOT_CRYPT = os.environ.get('GDTOT_CRYPT', '')
if len(GDTOT_CRYPT) == 0:
GDTOT_CRYPT = None
Expand Down
6 changes: 3 additions & 3 deletions bot/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ def restart(update, context):
<br><br>
• <b>/{BotCommands.ListCommand}</b> &lt;query&gt;: Search data in Google Drive
<br><br>
• <b>/{BotCommands.CloneCommand}</b> &lt;url&gt; &lt;dest_id&gt;: Clone data from Google Drive, AppDrive and GDToT (Destination ID optional)
• <b>/{BotCommands.CloneCommand}</b> &lt;url&gt; &lt;dest_id&gt;: Clone data from Google Drive and GDToT (Destination ID optional)
<br><br>
• <b>/{BotCommands.CompressCommand}</b> &lt;url&gt;: Compress data from Google Drive, AppDrive and GDToT
• <b>/{BotCommands.CompressCommand}</b> &lt;url&gt;: Compress data from Google Drive and GDToT
<br><br>
• <b>/{BotCommands.ExtractCommand}</b> &lt;url&gt;: Extract data from Google Drive, AppDrive and GDToT
• <b>/{BotCommands.ExtractCommand}</b> &lt;url&gt;: Extract data from Google Drive and GDToT
<br><br>
• <b>/{BotCommands.CountCommand}</b> &lt;drive_url&gt;: Count data from Google Drive
<br><br>
Expand Down
62 changes: 1 addition & 61 deletions bot/helper/download_utils/ddl_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,71 +2,11 @@
import re
import requests

from lxml import etree
from urllib.parse import urlparse, parse_qs

from bot import APPDRIVE_EMAIL, APPDRIVE_PASS, GDTOT_CRYPT
from bot import GDTOT_CRYPT
from bot.helper.ext_utils.exceptions import DDLExceptionHandler

def account_login(client, url, email, password):
data = {
'email': email,
'password': password
}
client.post(f'https://{urlparse(url).netloc}/login', data=data)

def gen_payload(data, boundary=f'{"-"*6}_'):
data_string = ''
for item in data:
data_string += f'{boundary}\r\n'
data_string += f'Content-Disposition: form-data; name="{item}"\r\n\r\n{data[item]}\r\n'
data_string += f'{boundary}--\r\n'
return data_string

def appdrive(url: str) -> str:
if (APPDRIVE_EMAIL or APPDRIVE_PASS) is None:
raise DDLExceptionHandler("APPDRIVE_EMAIL and APPDRIVE_PASS env vars not provided")
client = requests.Session()
client.headers.update({
"user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.99 Safari/537.36"
})
account_login(client, url, APPDRIVE_EMAIL, APPDRIVE_PASS)
res = client.get(url)
try:
key = re.findall(r'"key",\s+"(.*?)"', res.text)[0]
except IndexError:
raise DDLExceptionHandler("Invalid link")
ddl_btn = etree.HTML(res.content).xpath("//button[@id='drc']")
info = {}
info['error'] = False
info['link_type'] = 'login' # direct/login
headers = {
"Content-Type": f"multipart/form-data; boundary={'-'*4}_",
}
data = {
'type': 1,
'key': key,
'action': 'original'
}
if len(ddl_btn):
info['link_type'] = 'direct'
data['action'] = 'direct'
while data['type'] <= 3:
try:
response = client.post(url, data=gen_payload(data), headers=headers).json()
break
except:
data['type'] += 1
if 'url' in response:
info['gdrive_link'] = response['url']
elif 'error' in response and response['error']:
info['error'] = True
info['message'] = response['message']
if not info['error']:
return info
else:
raise DDLExceptionHandler(f"{info['message']}")

def gdtot(url: str) -> str:
if GDTOT_CRYPT is None:
raise DDLExceptionHandler("GDTOT_CRYPT env var not provided")
Expand Down
8 changes: 2 additions & 6 deletions bot/helper/download_utils/gd_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from bot.helper.telegram_helper.message_utils import sendMessage, deleteMessage, sendStatusMessage
from bot.helper.ext_utils.bot_utils import get_readable_file_size

def add_gd_download(link, path, listener, customname, is_appdrive, appdict, is_gdtot):
def add_gd_download(link, path, listener, customname, is_gdtot):
msg = sendMessage(f"<b>Checking:</b> <code>{link}</code>", listener.bot, listener.message)
LOGGER.info(f"Checking: {link}")
gd = GoogleDriveHelper()
Expand All @@ -32,10 +32,6 @@ def add_gd_download(link, path, listener, customname, is_appdrive, appdict, is_g
download_dict[listener.uid] = download_status
sendStatusMessage(listener.message, listener.bot)
drive.download(link)
if is_appdrive:
if appdict.get('link_type') == 'login':
LOGGER.info(f"Deleting: {link}")
drive.deleteFile(link)
elif is_gdtot:
if is_gdtot:
LOGGER.info(f"Deleting: {link}")
drive.deleteFile(link)
2 changes: 1 addition & 1 deletion bot/helper/drive_utils/gdriveTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ def upload(self, file_name: str):
if isinstance(err, RetryError):
LOGGER.info(f"Total attempts: {err.last_attempt.attempt_number}")
err = err.last_attempt.exception()
self.__listener.onUploadError(err)
self.__listener.onUploadError(str(err))
self.__is_errored = True
finally:
self.__updater.cancel()
Expand Down
4 changes: 0 additions & 4 deletions bot/helper/ext_utils/bot_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,6 @@ def is_url(url: str):
def is_gdrive_link(url: str):
return "drive.google.com" in url

def is_appdrive_link(url: str):
url = re.match(r'https?://appdrive\.\S+', url)
return bool(url)

def is_gdtot_link(url: str):
url = re.match(r'https?://.+\.gdtot\.\S+', url)
return bool(url)
Expand Down
19 changes: 6 additions & 13 deletions bot/modules/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
from telegram.ext import CommandHandler

from bot import LOGGER, dispatcher, DOWNLOAD_DIR, Interval, INDEX_URL, download_dict, download_dict_lock, status_reply_dict_lock
from bot.helper.download_utils.ddl_generator import appdrive, gdtot
from bot.helper.download_utils.ddl_generator import gdtot
from bot.helper.download_utils.gd_downloader import add_gd_download
from bot.helper.drive_utils.gdriveTools import GoogleDriveHelper
from bot.helper.ext_utils.bot_utils import is_gdrive_link, is_appdrive_link, is_gdtot_link
from bot.helper.ext_utils.bot_utils import is_gdrive_link, is_gdtot_link
from bot.helper.ext_utils.exceptions import ArchiveExceptionHandler, DDLExceptionHandler
from bot.helper.ext_utils.fs_utils import clean_download, clean_target, get_base_name, get_path_size
from bot.helper.status_utils.compress_status import CompressStatus
Expand Down Expand Up @@ -189,9 +189,7 @@ def _archive(bot, message, is_compress=False, is_extract=False):
mesg = message.text.split('\n')
message_args = mesg[0].split(maxsplit=1)
name_arg = mesg[0].split('|', maxsplit=1)
is_appdrive = False
is_gdtot = False
appdict = ''
if len(message_args) > 1:
link = message_args[1].strip()
if link.startswith("pswd:"):
Expand All @@ -214,28 +212,23 @@ def _archive(bot, message, is_compress=False, is_extract=False):
reply_to = message.reply_to_message
if reply_to is not None:
link = reply_to.text.split(maxsplit=1)[0].strip()
is_appdrive = is_appdrive_link(link)
is_gdtot = is_gdtot_link(link)
if any([is_appdrive, is_gdtot]):
if is_gdtot:
msg = sendMessage(f"<b>Processing:</b> <code>{link}</code>", bot, message)
LOGGER.info(f"Processing: {link}")
try:
if is_appdrive:
appdict = appdrive(link)
link = appdict.get('gdrive_link')
if is_gdtot:
link = gdtot(link)
link = gdtot(link)
deleteMessage(bot, msg)
except DDLExceptionHandler as err:
deleteMessage(bot, msg)
LOGGER.error(err)
return sendMessage(str(err), bot, message)
listener = ArchiveListener(bot, message, is_compress, is_extract, pswd)
if is_gdrive_link(link):
threading.Thread(target=add_gd_download, args=(link, f'{DOWNLOAD_DIR}{listener.uid}', listener, name, is_appdrive, appdict, is_gdtot)).start()
threading.Thread(target=add_gd_download, args=(link, f'{DOWNLOAD_DIR}{listener.uid}', listener, name, is_gdtot)).start()
else:
help_msg = '<b><u>Instructions</u></b>\nSend a link along with command'
help_msg += '\n\n<b><u>Supported Sites</u></b>\n• Google Drive\nAppDrive\nGDToT'
help_msg += '\n\n<b><u>Supported Sites</u></b>\n• Google Drive\n• GDToT'
help_msg += '\n\n<b><u>Set Custom Name</u></b>\nAdd "<code>|customname</code>" after the link'
help_msg += '\n\n<b><u>Set Password</u></b>\nAdd "<code>pswd: xxx</code>" after the link'
sendMessage(help_msg, bot, message)
Expand Down
26 changes: 8 additions & 18 deletions bot/modules/clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
from telegram.ext import CommandHandler

from bot import LOGGER, dispatcher, CLONE_LIMIT, download_dict, download_dict_lock, Interval
from bot.helper.download_utils.ddl_generator import appdrive, gdtot
from bot.helper.download_utils.ddl_generator import gdtot
from bot.helper.drive_utils.gdriveTools import GoogleDriveHelper
from bot.helper.ext_utils.bot_utils import new_thread, get_readable_file_size, is_gdrive_link, \
is_appdrive_link, is_gdtot_link
from bot.helper.ext_utils.bot_utils import new_thread, get_readable_file_size, is_gdrive_link, is_gdtot_link
from bot.helper.ext_utils.exceptions import DDLExceptionHandler
from bot.helper.status_utils.clone_status import CloneStatus
from bot.helper.telegram_helper.message_utils import sendMessage, editMessage, deleteMessage, \
delete_all_messages, update_all_messages, sendStatusMessage
from bot.helper.telegram_helper.message_utils import sendMessage, editMessage, deleteMessage, delete_all_messages, \
update_all_messages, sendStatusMessage
from bot.helper.telegram_helper.bot_commands import BotCommands
from bot.helper.telegram_helper.filters import CustomFilters

Expand All @@ -33,17 +32,12 @@ def cloneNode(update, context):
dest_id = args[1].strip()
except IndexError:
pass
is_appdrive = is_appdrive_link(link)
is_gdtot = is_gdtot_link(link)
if any([is_appdrive, is_gdtot]):
if is_gdtot:
msg = sendMessage(f"<b>Processing:</b> <code>{link}</code>", context.bot, update.message)
LOGGER.info(f"Processing: {link}")
try:
if is_appdrive:
appdict = appdrive(link)
link = appdict.get('gdrive_link')
if is_gdtot:
link = gdtot(link)
link = gdtot(link)
deleteMessage(context.bot, msg)
except DDLExceptionHandler as err:
deleteMessage(context.bot, msg)
Expand Down Expand Up @@ -91,16 +85,12 @@ def cloneNode(update, context):
except IndexError:
pass
sendMessage(result, context.bot, update.message)
if is_appdrive:
if appdict.get('link_type') == 'login':
LOGGER.info(f"Deleting: {link}")
gd.deleteFile(link)
elif is_gdtot:
if is_gdtot:
LOGGER.info(f"Deleting: {link}")
gd.deleteFile(link)
else:
help_msg = '<b><u>Instructions</u></b>\nSend a link along with command'
help_msg += '\n\n<b><u>Supported Sites</u></b>\n• Google Drive\nAppDrive\nGDToT'
help_msg += '\n\n<b><u>Supported Sites</u></b>\n• Google Drive\n• GDToT'
sendMessage(help_msg, context.bot, update.message)

clone_handler = CommandHandler(BotCommands.CloneCommand, cloneNode,
Expand Down
2 changes: 0 additions & 2 deletions config_sample.env
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,4 @@ CLONE_LIMIT=
TOKEN_JSON_URL=
ACCOUNTS_ZIP_URL=
DRIVE_LIST_URL=
APPDRIVE_EMAIL=
APPDRIVE_PASS=
GDTOT_CRYPT=
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
dnspython
google-api-python-client
google-auth-oauthlib
lxml
psutil
pymongo
python-dotenv
Expand Down

0 comments on commit 2f865fb

Please sign in to comment.