Skip to content

Commit

Permalink
Add Sharer support
Browse files Browse the repository at this point in the history
  • Loading branch information
l3v11 committed Apr 5, 2022
1 parent 7738332 commit bbff43f
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

## SearchX

> A simple Telegram Bot for searching data on Google Drive. Able to clone data from Drive / AppDrive / DriveApp / GDToT links. Supports MongoDB for storing authorized users record.
> A simple Telegram Bot for searching data on Google Drive. Able to clone data from Drive / AppDrive / DriveApp / GDToT / Sharer links. Supports MongoDB for storing authorized users record.
</p>

Expand Down
9 changes: 9 additions & 0 deletions bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,15 @@ def get_config(name: str):
except KeyError:
GDTOT_CRYPT = None

try:
XSRF_TOKEN = get_config('XSRF_TOKEN')
laravel_session = get_config('laravel_session')
if len(XSRF_TOKEN) == 0 or len(laravel_session) == 0:
raise KeyError
except KeyError:
XSRF_TOKEN = None
laravel_session = None

try:
DRIVE_INDEX_URL = get_config('DRIVE_INDEX_URL')
if len(DRIVE_INDEX_URL) == 0:
Expand Down
2 changes: 1 addition & 1 deletion bot/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def bot_help(update, context):
/{BotCommands.ListCommand} [query]: Search data on Drives
/{BotCommands.CloneCommand} [url]: Copy data from Drive / AppDrive / DriveApp / GDToT to Drive
/{BotCommands.CloneCommand} [url]: Copy data from Drive / AppDrive / DriveApp / GDToT / Sharer to Drive
/{BotCommands.CountCommand} [drive_url]: Count data of Drive
Expand Down
8 changes: 4 additions & 4 deletions bot/helper/drive_utils/gdriveTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,15 +500,15 @@ def drive_list(self, file_name):
self.path.append(
telegraph[acc_no].create_page(title='SearchX',
author_name='Levi',
author_url='https://t.me/l3v11BOT',
author_url='https://t.me/l3v11',
html_content=self.telegraph_content[i])['path'])
except RetryAfterError as e:
LOGGER.info(f"Cooldown: {e.retry_after} seconds")
time.sleep(e.retry_after)
self.path.append(
telegraph[acc_no].create_page(title='SearchX',
author_name='Levi',
author_url='https://t.me/l3v11BOT',
author_url='https://t.me/l3v11',
html_content=self.telegraph_content[i])['path'])

if i != 0:
Expand All @@ -518,15 +518,15 @@ def drive_list(self, file_name):
telegraph[(acc_no - 1) if i % page_per_acc == 0 else acc_no].edit_page(path = self.path[i-1],
title='SearchX',
author_name='Levi',
author_url='https://t.me/l3v11BOT',
author_url='https://t.me/l3v11',
html_content=self.telegraph_content[i-1])
except RetryAfterError as e:
LOGGER.info(f"Cooldown: {e.retry_after} seconds")
time.sleep(e.retry_after)
telegraph[(acc_no - 1) if i % page_per_acc == 0 else acc_no].edit_page(path = self.path[i-1],
title='SearchX',
author_name='Levi',
author_url='https://t.me/l3v11BOT',
author_url='https://t.me/l3v11',
html_content=self.telegraph_content[i-1])

msg = f"<b>Found {response_count} results matching '{file_name}' in {len(DRIVE_ID)} Drives</b> " \
Expand Down
4 changes: 4 additions & 0 deletions bot/helper/ext_utils/bot_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ def is_gdtot_link(url: str):
url = re.match(r'https?://.+\.gdtot\.\S+', url)
return bool(url)

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

def new_thread(fn):
def wrapper(*args, **kwargs):
thread = threading.Thread(target=fn, args=args, kwargs=kwargs)
Expand Down
44 changes: 42 additions & 2 deletions bot/helper/ext_utils/parser.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import base64
import cloudscraper
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 APPDRIVE_EMAIL, APPDRIVE_PASS, GDTOT_CRYPT, XSRF_TOKEN, laravel_session
from bot.helper.ext_utils.exceptions import DDLException

account = {
Expand Down Expand Up @@ -60,7 +61,8 @@ def appdrive(url: str) -> str:
try:
response = client.post(url, data=gen_payload(data), headers=headers).json()
break
except: data['type'] += 1
except:
data['type'] += 1
if 'url' in response:
info['gdrive_link'] = response['url']
elif 'error' in response and response['error']:
Expand Down Expand Up @@ -100,3 +102,41 @@ def gdtot(url: str) -> str:
return info['gdrive_link']
else:
raise DDLException(f"{info['message']}")

def sharer(url: str, forced_login=False) -> str:
if (XSRF_TOKEN or laravel_session) is None:
raise DDLException("XSRF_TOKEN and laravel_session env vars not provided")
scraper = cloudscraper.create_scraper(allow_brotli=False)
scraper.cookies.update({
"XSRF-TOKEN": XSRF_TOKEN,
"laravel_session": laravel_session
})
res = scraper.get(url)
token = re.findall("_token\s=\s'(.*?)'", res.text, re.DOTALL)[0]
ddl_btn = etree.HTML(res.content).xpath("//button[@id='btndirect']")
info = {}
info['error'] = True
info['link_type'] = 'login' # direct/login
info['forced_login'] = forced_login
headers = {
'content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
'x-requested-with': 'XMLHttpRequest'
}
data = {
'_token': token
}
if len(ddl_btn):
info['link_type'] = 'direct'
if not forced_login:
data['nl'] = 1
res = scraper.post(url+'/dl', headers=headers, data=data).json()
if 'url' in res and res['url']:
info['error'] = False
info['gdrive_link'] = res['url']
if len(ddl_btn) and not forced_login and not 'url' in info:
# retry download via login
return sharer(url, forced_login=True)
if not info['error']:
return info['gdrive_link']
else:
raise DDLException("Invalid link")
14 changes: 10 additions & 4 deletions bot/modules/clone.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

from bot import LOGGER, dispatcher
from bot.helper.drive_utils.gdriveTools import GoogleDriveHelper
from bot.helper.ext_utils.bot_utils import new_thread, is_gdrive_link, is_appdrive_link, is_gdtot_link
from bot.helper.ext_utils.bot_utils import new_thread, is_gdrive_link, is_appdrive_link, is_gdtot_link, is_sharer_link
from bot.helper.ext_utils.clone_status import CloneStatus
from bot.helper.ext_utils.exceptions import DDLException
from bot.helper.ext_utils.parser import appdrive, gdtot
from bot.helper.ext_utils.parser import appdrive, gdtot, sharer
from bot.helper.telegram_helper.message_utils import sendMessage, editMessage, deleteMessage
from bot.helper.telegram_helper.bot_commands import BotCommands
from bot.helper.telegram_helper.filters import CustomFilters
Expand All @@ -25,7 +25,8 @@ def cloneNode(update, context):
link = reply_to.text
is_appdrive = is_appdrive_link(link)
is_gdtot = is_gdtot_link(link)
if (is_appdrive or is_gdtot):
is_sharer = is_sharer_link(link)
if (is_appdrive or is_gdtot or is_sharer):
try:
msg = sendMessage(f"<b>Processing:</b> <code>{link}</code>", context.bot, update)
LOGGER.info(f"Processing: {link}")
Expand All @@ -34,6 +35,8 @@ def cloneNode(update, context):
link = appdict.get('gdrive_link')
if is_gdtot:
link = gdtot(link)
if is_sharer:
link = sharer(link)
deleteMessage(context.bot, msg)
except DDLException as e:
deleteMessage(context.bot, msg)
Expand All @@ -56,8 +59,11 @@ def cloneNode(update, context):
if appdict.get('link_type') == 'login':
LOGGER.info(f"Deleting: {link}")
gd.deleteFile(link)
if is_sharer:
LOGGER.info(f"Deleting: {link}")
gd.deleteFile(link)
else:
sendMessage("<b>Send a Drive / AppDrive / DriveApp / GDToT link along with command</b>", context.bot, update)
sendMessage("<b>Send a Drive / AppDrive / DriveApp / GDToT / Sharer link along with command</b>", context.bot, update)
LOGGER.info("Cloning: None")

@new_thread
Expand Down
2 changes: 2 additions & 0 deletions config_sample.env
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ DRIVE_LIST_URL=
APPDRIVE_EMAIL=
APPDRIVE_PASS=
GDTOT_CRYPT=
XSRF_TOKEN=
laravel_session=
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
cloudscraper
dnspython
google-api-python-client
google-auth-oauthlib
Expand Down

0 comments on commit bbff43f

Please sign in to comment.