Update
-Add multi folder/td search -Improve search -Improve stop duplicate -Other minor changes Signed-off-by: anas <e.anastayyar@gmail.com>
This commit is contained in:
parent
92340bc807
commit
cd7349ce0d
|
|
@ -5,6 +5,7 @@ import time
|
||||||
import random
|
import random
|
||||||
import string
|
import string
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import requests
|
||||||
|
|
||||||
import aria2p
|
import aria2p
|
||||||
import qbittorrentapi as qba
|
import qbittorrentapi as qba
|
||||||
|
|
@ -35,9 +36,13 @@ LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
CONFIG_FILE_URL = os.environ.get('CONFIG_FILE_URL', None)
|
CONFIG_FILE_URL = os.environ.get('CONFIG_FILE_URL', None)
|
||||||
if CONFIG_FILE_URL is not None:
|
if CONFIG_FILE_URL is not None:
|
||||||
out = subprocess.run(["wget", "-q", "-O", "config.env", CONFIG_FILE_URL])
|
res = requests.get(CONFIG_FILE_URL)
|
||||||
if out.returncode != 0:
|
if res.status_code == 200:
|
||||||
logging.error(out)
|
with open('config.env', 'wb') as f:
|
||||||
|
f.truncate(0)
|
||||||
|
f.write(res.content)
|
||||||
|
else:
|
||||||
|
logging.error(res.status_code)
|
||||||
|
|
||||||
load_dotenv('config.env')
|
load_dotenv('config.env')
|
||||||
|
|
||||||
|
|
@ -48,7 +53,9 @@ subprocess.run(["cp", "qBittorrent.conf", "qBittorrent/config/qBittorrent.conf"]
|
||||||
subprocess.run(["qbittorrent-nox", "-d", "--profile=."])
|
subprocess.run(["qbittorrent-nox", "-d", "--profile=."])
|
||||||
|
|
||||||
Interval = []
|
Interval = []
|
||||||
|
DRIVES_NAMES = []
|
||||||
|
DRIVES_IDS = []
|
||||||
|
INDEX_URLS = []
|
||||||
|
|
||||||
def getConfig(name: str):
|
def getConfig(name: str):
|
||||||
return os.environ[name]
|
return os.environ[name]
|
||||||
|
|
@ -60,9 +67,9 @@ def mktable():
|
||||||
sql = "CREATE TABLE users (uid bigint, sudo boolean DEFAULT FALSE);"
|
sql = "CREATE TABLE users (uid bigint, sudo boolean DEFAULT FALSE);"
|
||||||
cur.execute(sql)
|
cur.execute(sql)
|
||||||
conn.commit()
|
conn.commit()
|
||||||
LOGGER.info("Table Created!")
|
logging.info("Table Created!")
|
||||||
except Error as e:
|
except Error as e:
|
||||||
LOGGER.error(e)
|
logging.error(e)
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
@ -88,7 +95,7 @@ def get_client() -> qba.TorrentsAPIMixIn:
|
||||||
#qb_client.application.set_preferences({"disk_cache":64, "incomplete_files_ext":True, "max_connec":3000, "max_connec_per_torrent":300, "async_io_threads":8, "preallocate_all":True, "upnp":True, "dl_limit":-1, "up_limit":-1, "dht":True, "pex":True, "lsd":True, "encryption":0, "queueing_enabled":True, "max_active_downloads":15, "max_active_torrents":50, "dont_count_slow_torrents":True, "bittorrent_protocol":0, "recheck_completed_torrents":True, "enable_multi_connections_from_same_ip":True, "slow_torrent_dl_rate_threshold":100,"slow_torrent_inactive_timer":600})
|
#qb_client.application.set_preferences({"disk_cache":64, "incomplete_files_ext":True, "max_connec":3000, "max_connec_per_torrent":300, "async_io_threads":8, "preallocate_all":True, "upnp":True, "dl_limit":-1, "up_limit":-1, "dht":True, "pex":True, "lsd":True, "encryption":0, "queueing_enabled":True, "max_active_downloads":15, "max_active_torrents":50, "dont_count_slow_torrents":True, "bittorrent_protocol":0, "recheck_completed_torrents":True, "enable_multi_connections_from_same_ip":True, "slow_torrent_dl_rate_threshold":100,"slow_torrent_inactive_timer":600})
|
||||||
return qb_client
|
return qb_client
|
||||||
except qba.LoginFailed as e:
|
except qba.LoginFailed as e:
|
||||||
LOGGER.error(str(e))
|
logging.error(str(e))
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -222,8 +229,12 @@ try:
|
||||||
INDEX_URL = getConfig('INDEX_URL')
|
INDEX_URL = getConfig('INDEX_URL')
|
||||||
if len(INDEX_URL) == 0:
|
if len(INDEX_URL) == 0:
|
||||||
INDEX_URL = None
|
INDEX_URL = None
|
||||||
|
INDEX_URLS.append(None)
|
||||||
|
else:
|
||||||
|
INDEX_URLS.append(INDEX_URL)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
INDEX_URL = None
|
INDEX_URL = None
|
||||||
|
INDEX_URLS.append(None)
|
||||||
try:
|
try:
|
||||||
TORRENT_DIRECT_LIMIT = getConfig('TORRENT_DIRECT_LIMIT')
|
TORRENT_DIRECT_LIMIT = getConfig('TORRENT_DIRECT_LIMIT')
|
||||||
if len(TORRENT_DIRECT_LIMIT) == 0:
|
if len(TORRENT_DIRECT_LIMIT) == 0:
|
||||||
|
|
@ -332,31 +343,70 @@ try:
|
||||||
if len(SERVER_PORT) == 0:
|
if len(SERVER_PORT) == 0:
|
||||||
SERVER_PORT = None
|
SERVER_PORT = None
|
||||||
except KeyError:
|
except KeyError:
|
||||||
logging.warning('SERVER_PORT not provided!')
|
if IS_VPS:
|
||||||
|
logging.warning('SERVER_PORT not provided!')
|
||||||
SERVER_PORT = None
|
SERVER_PORT = None
|
||||||
try:
|
try:
|
||||||
TOKEN_PICKLE_URL = getConfig('TOKEN_PICKLE_URL')
|
TOKEN_PICKLE_URL = getConfig('TOKEN_PICKLE_URL')
|
||||||
if len(TOKEN_PICKLE_URL) == 0:
|
if len(TOKEN_PICKLE_URL) == 0:
|
||||||
TOKEN_PICKLE_URL = None
|
TOKEN_PICKLE_URL = None
|
||||||
else:
|
else:
|
||||||
out = subprocess.run(["wget", "-q", "-O", "token.pickle", TOKEN_PICKLE_URL])
|
res = requests.get(TOKEN_PICKLE_URL)
|
||||||
if out.returncode != 0:
|
if res.status_code == 200:
|
||||||
logging.error(out)
|
with open('token.pickle', 'wb') as f:
|
||||||
|
f.truncate(0)
|
||||||
|
f.write(res.content)
|
||||||
|
else:
|
||||||
|
logging.error(res.status_code)
|
||||||
|
raise KeyError
|
||||||
except KeyError:
|
except KeyError:
|
||||||
TOKEN_PICKLE_URL = None
|
pass
|
||||||
try:
|
try:
|
||||||
ACCOUNTS_ZIP_URL = getConfig('ACCOUNTS_ZIP_URL')
|
ACCOUNTS_ZIP_URL = getConfig('ACCOUNTS_ZIP_URL')
|
||||||
if len(ACCOUNTS_ZIP_URL) == 0:
|
if len(ACCOUNTS_ZIP_URL) == 0:
|
||||||
ACCOUNTS_ZIP_URL = None
|
ACCOUNTS_ZIP_URL = None
|
||||||
else:
|
else:
|
||||||
out = subprocess.run(["wget", "-q", "-O", "accounts.zip", ACCOUNTS_ZIP_URL])
|
res = requests.get(ACCOUNTS_ZIP_URL)
|
||||||
if out.returncode != 0:
|
if res.status_code == 200:
|
||||||
logging.error(out)
|
with open('accounts.zip', 'wb') as f:
|
||||||
|
f.truncate(0)
|
||||||
|
f.write(res.content)
|
||||||
|
else:
|
||||||
|
logging.error(res.status_code)
|
||||||
raise KeyError
|
raise KeyError
|
||||||
subprocess.run(["unzip", "-q", "-o", "accounts.zip"])
|
subprocess.run(["unzip", "-q", "-o", "accounts.zip"])
|
||||||
os.remove("accounts.zip")
|
os.remove("accounts.zip")
|
||||||
except KeyError:
|
except KeyError:
|
||||||
ACCOUNTS_ZIP_URL = None
|
pass
|
||||||
|
try:
|
||||||
|
MULTI_SEARCH_URL = getConfig('MULTI_SEARCH_URL')
|
||||||
|
if len(MULTI_SEARCH_URL) == 0:
|
||||||
|
MULTI_SEARCH_URL = None
|
||||||
|
else:
|
||||||
|
res = requests.get(MULTI_SEARCH_URL)
|
||||||
|
if res.status_code == 200:
|
||||||
|
with open('drive_folder', 'wb') as f:
|
||||||
|
f.truncate(0)
|
||||||
|
f.write(res.content)
|
||||||
|
else:
|
||||||
|
logging.error(res.status_code)
|
||||||
|
raise KeyError
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
DRIVES_NAMES.append("Main")
|
||||||
|
DRIVES_IDS.append(parent_id)
|
||||||
|
if os.path.exists('drive_folder'):
|
||||||
|
with open('drive_folder', 'r+') as f:
|
||||||
|
lines = f.readlines()
|
||||||
|
for line in lines:
|
||||||
|
temp = line.strip().split()
|
||||||
|
DRIVES_NAMES.append(temp[0].replace("_", " "))
|
||||||
|
DRIVES_IDS.append(temp[1])
|
||||||
|
try:
|
||||||
|
INDEX_URLS.append(temp[2])
|
||||||
|
except IndexError as e:
|
||||||
|
INDEX_URLS.append(None)
|
||||||
|
|
||||||
updater = tg.Updater(token=BOT_TOKEN)
|
updater = tg.Updater(token=BOT_TOKEN)
|
||||||
bot = updater.bot
|
bot = updater.bot
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ class AriaDownloadHelper:
|
||||||
@new_thread
|
@new_thread
|
||||||
def __onDownloadStarted(self, api, gid):
|
def __onDownloadStarted(self, api, gid):
|
||||||
if STOP_DUPLICATE or TORRENT_DIRECT_LIMIT is not None or TAR_UNZIP_LIMIT is not None:
|
if STOP_DUPLICATE or TORRENT_DIRECT_LIMIT is not None or TAR_UNZIP_LIMIT is not None:
|
||||||
sleep(2)
|
sleep(1)
|
||||||
dl = getDownloadByGid(gid)
|
dl = getDownloadByGid(gid)
|
||||||
download = aria2.get_download(gid)
|
download = aria2.get_download(gid)
|
||||||
if STOP_DUPLICATE and dl is not None:
|
if STOP_DUPLICATE and dl is not None:
|
||||||
|
|
@ -27,14 +27,15 @@ class AriaDownloadHelper:
|
||||||
if dl.getListener().extract:
|
if dl.getListener().extract:
|
||||||
smsg = None
|
smsg = None
|
||||||
else:
|
else:
|
||||||
gdrive = GoogleDriveHelper(None)
|
gdrive = GoogleDriveHelper()
|
||||||
smsg, button = gdrive.drive_list(sname)
|
smsg, button = gdrive.drive_list(sname, True)
|
||||||
if smsg:
|
if smsg:
|
||||||
dl.getListener().onDownloadError('File/Folder already available in Drive.\n\n')
|
dl.getListener().onDownloadError('File/Folder already available in Drive.\n\n')
|
||||||
aria2.remove([download], force=True)
|
aria2.remove([download], force=True)
|
||||||
sendMarkup("Here are the search results:", dl.getListener().bot, dl.getListener().update, button)
|
sendMarkup("Here are the search results:", dl.getListener().bot, dl.getListener().update, button)
|
||||||
return
|
return
|
||||||
if (TORRENT_DIRECT_LIMIT is not None or TAR_UNZIP_LIMIT is not None) and dl is not None:
|
if (TORRENT_DIRECT_LIMIT is not None or TAR_UNZIP_LIMIT is not None) and dl is not None:
|
||||||
|
sleep(1)
|
||||||
size = aria2.get_download(gid).total_length
|
size = aria2.get_download(gid).total_length
|
||||||
if dl.getListener().isTar or dl.getListener().extract:
|
if dl.getListener().isTar or dl.getListener().extract:
|
||||||
is_tar_ext = True
|
is_tar_ext = True
|
||||||
|
|
|
||||||
|
|
@ -176,7 +176,7 @@ class MegaDownloadHelper:
|
||||||
smsg = None
|
smsg = None
|
||||||
else:
|
else:
|
||||||
gd = GoogleDriveHelper()
|
gd = GoogleDriveHelper()
|
||||||
smsg, button = gd.drive_list(mname)
|
smsg, button = gd.drive_list(mname, True)
|
||||||
if smsg:
|
if smsg:
|
||||||
msg1 = "File/Folder is already available in Drive.\nHere are the search results:"
|
msg1 = "File/Folder is already available in Drive.\nHere are the search results:"
|
||||||
sendMarkup(msg1, listener.bot, listener.update, button)
|
sendMarkup(msg1, listener.bot, listener.update, button)
|
||||||
|
|
|
||||||
|
|
@ -107,7 +107,7 @@ class TelegramDownloadHelper(DownloadHelper):
|
||||||
smsg = None
|
smsg = None
|
||||||
else:
|
else:
|
||||||
gd = GoogleDriveHelper()
|
gd = GoogleDriveHelper()
|
||||||
smsg, button = gd.drive_list(name)
|
smsg, button = gd.drive_list(name, True)
|
||||||
if smsg:
|
if smsg:
|
||||||
sendMarkup("File/Folder is already available in Drive.\nHere are the search results:", self.__listener.bot, self.__listener.update, button)
|
sendMarkup("File/Folder is already available in Drive.\nHere are the search results:", self.__listener.bot, self.__listener.update, button)
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ from telegram import InlineKeyboardMarkup
|
||||||
from bot.helper.telegram_helper import button_build
|
from bot.helper.telegram_helper import button_build
|
||||||
from telegraph import Telegraph
|
from telegraph import Telegraph
|
||||||
from bot import parent_id, DOWNLOAD_DIR, IS_TEAM_DRIVE, INDEX_URL, \
|
from bot import parent_id, DOWNLOAD_DIR, IS_TEAM_DRIVE, INDEX_URL, \
|
||||||
USE_SERVICE_ACCOUNTS, telegraph_token, BUTTON_FOUR_NAME, BUTTON_FOUR_URL, BUTTON_FIVE_NAME, BUTTON_FIVE_URL, BUTTON_SIX_NAME, BUTTON_SIX_URL, SHORTENER, SHORTENER_API, VIEW_LINK
|
USE_SERVICE_ACCOUNTS, telegraph_token, BUTTON_FOUR_NAME, BUTTON_FOUR_URL, BUTTON_FIVE_NAME, BUTTON_FIVE_URL, BUTTON_SIX_NAME, BUTTON_SIX_URL, SHORTENER, SHORTENER_API, VIEW_LINK, DRIVES_NAMES, DRIVES_IDS, INDEX_URLS
|
||||||
from bot.helper.ext_utils.bot_utils import get_readable_file_size, setInterval
|
from bot.helper.ext_utils.bot_utils import get_readable_file_size, setInterval
|
||||||
from bot.helper.ext_utils.fs_utils import get_mime_type, get_path_size
|
from bot.helper.ext_utils.fs_utils import get_mime_type, get_path_size
|
||||||
from bot.helper.ext_utils.shortenurl import short_url
|
from bot.helper.ext_utils.shortenurl import short_url
|
||||||
|
|
@ -372,10 +372,11 @@ class GoogleDriveHelper:
|
||||||
q=q,
|
q=q,
|
||||||
spaces='drive',
|
spaces='drive',
|
||||||
pageSize=200,
|
pageSize=200,
|
||||||
fields='nextPageToken, files(id, name, mimeType,size)', corpora='allDrives', orderBy='folder, name',
|
fields='nextPageToken, files(id, name, mimeType,size)',
|
||||||
|
corpora='allDrives',
|
||||||
|
orderBy='folder, name',
|
||||||
pageToken=page_token).execute()
|
pageToken=page_token).execute()
|
||||||
for file in response.get('files', []):
|
files.extend(response.get('files', []))
|
||||||
files.append(file)
|
|
||||||
page_token = response.get('nextPageToken', None)
|
page_token = response.get('nextPageToken', None)
|
||||||
if page_token is None:
|
if page_token is None:
|
||||||
break
|
break
|
||||||
|
|
@ -594,17 +595,23 @@ class GoogleDriveHelper:
|
||||||
|
|
||||||
|
|
||||||
def escapes(self, str):
|
def escapes(self, str):
|
||||||
chars = ['\\', "'", '"', r'\a', r'\b', r'\f', r'\n', r'\r', r'\t']
|
chars = ['\\', "'", '"', r'\a', r'\b', r'\f', r'\n', r'\r', r'\s', r'\t']
|
||||||
for char in chars:
|
for char in chars:
|
||||||
str = str.replace(char, '\\'+char)
|
str = str.replace(char, ' ')
|
||||||
return str
|
return str
|
||||||
|
|
||||||
|
|
||||||
def drive_list(self, fileName):
|
def drive_query(self, parent_id, fileName):
|
||||||
msg = ""
|
|
||||||
fileName = self.escapes(str(fileName))
|
|
||||||
# Create Search Query for API request.
|
# Create Search Query for API request.
|
||||||
query = f"'{parent_id}' in parents and (name contains '{fileName}')"
|
if self.stopDup:
|
||||||
|
query = f"'{parent_id}' in parents and name = '{fileName}' and "
|
||||||
|
else:
|
||||||
|
query = f"'{parent_id}' in parents and "
|
||||||
|
fileName = fileName.split(' ')
|
||||||
|
for name in fileName:
|
||||||
|
if name != '':
|
||||||
|
query += f"name contains '{name}' and "
|
||||||
|
query += "trashed = false"
|
||||||
response = self.__service.files().list(supportsTeamDrives=True,
|
response = self.__service.files().list(supportsTeamDrives=True,
|
||||||
includeTeamDriveItems=True,
|
includeTeamDriveItems=True,
|
||||||
q=query,
|
q=query,
|
||||||
|
|
@ -612,66 +619,82 @@ class GoogleDriveHelper:
|
||||||
pageSize=200,
|
pageSize=200,
|
||||||
fields='files(id, name, mimeType, size)',
|
fields='files(id, name, mimeType, size)',
|
||||||
orderBy='name asc').execute()
|
orderBy='name asc').execute()
|
||||||
content_count = 0
|
return response
|
||||||
if not response["files"]:
|
|
||||||
return '', ''
|
|
||||||
|
|
||||||
msg += f'<h4>{len(response["files"])} Results: {fileName}</h4><br><br>'
|
|
||||||
for file in response.get('files', []):
|
def drive_list(self, fileName, stopDup=False):
|
||||||
if file.get('mimeType') == "application/vnd.google-apps.folder": # Detect Whether Current Entity is a Folder or File.
|
self.stopDup = stopDup
|
||||||
furl = f"https://drive.google.com/drive/folders/{file.get('id')}"
|
msg = ""
|
||||||
msg += f"📁 <code>{file.get('name')}<br>(folder)</code><br>"
|
if not stopDup:
|
||||||
if SHORTENER is not None and SHORTENER_API is not None:
|
fileName = self.escapes(str(fileName))
|
||||||
sfurl = short_url(furl)
|
content_count = 0
|
||||||
msg += f"<b><a href={sfurl}>Drive Link</a></b>"
|
all_contents_count = 0
|
||||||
else:
|
Title = False
|
||||||
msg += f"<b><a href={furl}>Drive Link</a></b>"
|
for index, parent_id in enumerate(DRIVES_IDS):
|
||||||
if INDEX_URL is not None:
|
response = self.drive_query(parent_id, fileName)
|
||||||
url_path = requests.utils.quote(f'{file.get("name")}')
|
if not response["files"]:
|
||||||
url = f'{INDEX_URL}/{url_path}/'
|
continue
|
||||||
|
if not Title:
|
||||||
|
msg += f'<h4>Search Result For: {fileName}</h4><br><br>'
|
||||||
|
Title = True
|
||||||
|
if len(DRIVES_NAMES) > 1 and DRIVES_NAMES[index] is not None:
|
||||||
|
msg += f"╾────────────╼<br><b>{DRIVES_NAMES[index]}</b><br>╾────────────╼<br>"
|
||||||
|
for file in response.get('files', []):
|
||||||
|
if file.get('mimeType') == "application/vnd.google-apps.folder":
|
||||||
|
furl = f"https://drive.google.com/drive/folders/{file.get('id')}"
|
||||||
|
msg += f"📁 <code>{file.get('name')}<br>(folder)</code><br>"
|
||||||
if SHORTENER is not None and SHORTENER_API is not None:
|
if SHORTENER is not None and SHORTENER_API is not None:
|
||||||
siurl = short_url(url)
|
sfurl = short_url(furl)
|
||||||
msg += f' <b>| <a href="{siurl}">Index Link</a></b>'
|
msg += f"<b><a href={sfurl}>Drive Link</a></b>"
|
||||||
else:
|
else:
|
||||||
msg += f' <b>| <a href="{url}">Index Link</a></b>'
|
msg += f"<b><a href={furl}>Drive Link</a></b>"
|
||||||
elif file.get('mimeType') == 'application/vnd.google-apps.shortcut':
|
if INDEX_URL[index] is not None:
|
||||||
msg += f"⁍<a href='https://drive.google.com/drive/folders/{file.get('id')}'>{file.get('name')}" \
|
url_path = requests.utils.quote(f'{file.get("name")}')
|
||||||
f"</a> (shortcut)"
|
url = f'{INDEX_URLS[index]}/{url_path}/'
|
||||||
# Excluded index link as indexes cant download or open these shortcuts
|
if SHORTENER is not None and SHORTENER_API is not None:
|
||||||
else:
|
siurl = short_url(url)
|
||||||
furl = f"https://drive.google.com/uc?id={file.get('id')}&export=download"
|
msg += f' <b>| <a href="{siurl}">Index Link</a></b>'
|
||||||
msg += f"📄 <code>{file.get('name')}<br>({get_readable_file_size(int(file.get('size')))})</code><br>"
|
else:
|
||||||
if SHORTENER is not None and SHORTENER_API is not None:
|
msg += f' <b>| <a href="{url}">Index Link</a></b>'
|
||||||
sfurl = short_url(furl)
|
elif file.get('mimeType') == 'application/vnd.google-apps.shortcut':
|
||||||
msg += f"<b><a href={sfurl}>Drive Link</a></b>"
|
msg += f"⁍<a href='https://drive.google.com/drive/folders/{file.get('id')}'>{file.get('name')}" \
|
||||||
|
f"</a> (shortcut)"
|
||||||
|
# Excluded index link as indexes cant download or open these shortcuts
|
||||||
else:
|
else:
|
||||||
msg += f"<b><a href={furl}>Drive Link</a></b>"
|
furl = f"https://drive.google.com/uc?id={file.get('id')}&export=download"
|
||||||
if INDEX_URL is not None:
|
msg += f"📄 <code>{file.get('name')}<br>({get_readable_file_size(int(file.get('size')))})</code><br>"
|
||||||
url_path = requests.utils.quote(f'{file.get("name")}')
|
|
||||||
url = f'{INDEX_URL}/{url_path}'
|
|
||||||
urls = f'{INDEX_URL}/{url_path}?a=view'
|
|
||||||
if SHORTENER is not None and SHORTENER_API is not None:
|
if SHORTENER is not None and SHORTENER_API is not None:
|
||||||
siurl = short_url(url)
|
sfurl = short_url(furl)
|
||||||
msg += f' <b>| <a href="{siurl}">Index Link</a></b>'
|
msg += f"<b><a href={sfurl}>Drive Link</a></b>"
|
||||||
if VIEW_LINK:
|
|
||||||
siurls = short_url(urls)
|
|
||||||
msg += f' <b>| <a href="{siurls}">View Link</a></b>'
|
|
||||||
else:
|
else:
|
||||||
msg += f' <b>| <a href="{url}">Index Link</a></b>'
|
msg += f"<b><a href={furl}>Drive Link</a></b>"
|
||||||
if VIEW_LINK:
|
if INDEX_URL[index] is not None:
|
||||||
msg += f' <b>| <a href="{urls}">View Link</a></b>'
|
url_path = requests.utils.quote(f'{file.get("name")}')
|
||||||
msg += '<br><br>'
|
url = f'{INDEX_URLS[index]}/{url_path}'
|
||||||
content_count += 1
|
urls = f'{INDEX_URLS[index]}/{url_path}?a=view'
|
||||||
if content_count == TELEGRAPHLIMIT :
|
if SHORTENER is not None and SHORTENER_API is not None:
|
||||||
self.telegraph_content.append(msg)
|
siurl = short_url(url)
|
||||||
msg = ""
|
msg += f' <b>| <a href="{siurl}">Index Link</a></b>'
|
||||||
content_count = 0
|
if VIEW_LINK:
|
||||||
|
siurls = short_url(urls)
|
||||||
|
msg += f' <b>| <a href="{siurls}">View Link</a></b>'
|
||||||
|
else:
|
||||||
|
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
|
||||||
|
all_contents_count += 1
|
||||||
|
if content_count == TELEGRAPHLIMIT :
|
||||||
|
self.telegraph_content.append(msg)
|
||||||
|
msg = ""
|
||||||
|
content_count = 0
|
||||||
|
|
||||||
if msg != '':
|
if msg != '':
|
||||||
self.telegraph_content.append(msg)
|
self.telegraph_content.append(msg)
|
||||||
|
|
||||||
if len(self.telegraph_content) == 0:
|
if len(self.telegraph_content) == 0:
|
||||||
return "No Result Found ❌", None
|
return "", None
|
||||||
|
|
||||||
for content in self.telegraph_content :
|
for content in self.telegraph_content :
|
||||||
self.path.append(Telegraph(access_token=telegraph_token).create_page(
|
self.path.append(Telegraph(access_token=telegraph_token).create_page(
|
||||||
|
|
@ -685,7 +708,7 @@ class GoogleDriveHelper:
|
||||||
if self.num_of_path > 1:
|
if self.num_of_path > 1:
|
||||||
self.edit_telegraph()
|
self.edit_telegraph()
|
||||||
|
|
||||||
msg = f"<b>Found <code>{len(response['files'])}</code> results for <code>{fileName}</code></b>"
|
msg = f"<b>Found <code>{all_contents_count}</code> results for <code>{fileName}</code></b>"
|
||||||
buttons = button_build.ButtonMaker()
|
buttons = button_build.ButtonMaker()
|
||||||
buttons.buildbutton("🔎 VIEW", f"https://telegra.ph/{self.path[0]}")
|
buttons.buildbutton("🔎 VIEW", f"https://telegra.ph/{self.path[0]}")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ def cloneNode(update, context):
|
||||||
return
|
return
|
||||||
if STOP_DUPLICATE:
|
if STOP_DUPLICATE:
|
||||||
LOGGER.info('Checking File/Folder if already in Drive...')
|
LOGGER.info('Checking File/Folder if already in Drive...')
|
||||||
smsg, button = gd.drive_list(name)
|
smsg, button = gd.drive_list(name, True)
|
||||||
if smsg:
|
if smsg:
|
||||||
msg3 = "File/Folder is already available in Drive.\nHere are the search results:"
|
msg3 = "File/Folder is already available in Drive.\nHere are the search results:"
|
||||||
sendMarkup(msg3, context.bot, update, button)
|
sendMarkup(msg3, context.bot, update, button)
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,17 @@
|
||||||
from telegram.ext import CommandHandler
|
from telegram.ext import CommandHandler
|
||||||
from bot.helper.mirror_utils.upload_utils.gdriveTools import GoogleDriveHelper
|
from bot.helper.mirror_utils.upload_utils.gdriveTools import GoogleDriveHelper
|
||||||
from bot import LOGGER, dispatcher
|
from bot import LOGGER, dispatcher
|
||||||
from bot.helper.telegram_helper.message_utils import sendMessage, sendMarkup, editMessage
|
from bot.helper.telegram_helper.message_utils import sendMessage, editMessage
|
||||||
from bot.helper.telegram_helper.filters import CustomFilters
|
from bot.helper.telegram_helper.filters import CustomFilters
|
||||||
import threading
|
|
||||||
from bot.helper.telegram_helper.bot_commands import BotCommands
|
from bot.helper.telegram_helper.bot_commands import BotCommands
|
||||||
|
|
||||||
|
|
||||||
def list_drive(update, context):
|
def list_drive(update, context):
|
||||||
try:
|
try:
|
||||||
search = update.message.text.split(' ',maxsplit=1)[1]
|
search = update.message.text.split(' ', maxsplit=1)[1]
|
||||||
LOGGER.info(f"Searching: {search}")
|
LOGGER.info(f"Searching: {search}")
|
||||||
reply = sendMessage('Searching..... Please wait!', context.bot, update)
|
reply = sendMessage('Searching..... Please wait!', context.bot, update)
|
||||||
gdrive = GoogleDriveHelper(None)
|
gdrive = GoogleDriveHelper()
|
||||||
msg, button = gdrive.drive_list(search)
|
msg, button = gdrive.drive_list(search)
|
||||||
|
|
||||||
if button:
|
if button:
|
||||||
|
|
|
||||||
|
|
@ -246,8 +246,7 @@ def _mirror(bot, update, isTar=False, extract=False, isZip=False, isQbit=False):
|
||||||
resp = requests.get(link)
|
resp = requests.get(link)
|
||||||
if resp.status_code == 200:
|
if resp.status_code == 200:
|
||||||
file_name = str(time.time()).replace(".", "") + ".torrent"
|
file_name = str(time.time()).replace(".", "") + ".torrent"
|
||||||
with open(file_name, "wb") as f:
|
open(file_name, "wb").write(resp.content)
|
||||||
f.write(resp.content)
|
|
||||||
link = f"{file_name}"
|
link = f"{file_name}"
|
||||||
else:
|
else:
|
||||||
sendMessage("ERROR: link got HTTP response:" + resp.status_code, bot, update)
|
sendMessage("ERROR: link got HTTP response:" + resp.status_code, bot, update)
|
||||||
|
|
|
||||||
|
|
@ -36,12 +36,13 @@ BASE_URL_OF_BOT = "" # Web Link, Required for Heroku to avoid sleep or use work
|
||||||
# These are optional, if you don't know, simply leave them, don't fill anything in them.
|
# These are optional, if you don't know, simply leave them, don't fill anything in them.
|
||||||
ACCOUNTS_ZIP_URL = ""
|
ACCOUNTS_ZIP_URL = ""
|
||||||
TOKEN_PICKLE_URL = ""
|
TOKEN_PICKLE_URL = ""
|
||||||
|
MULTI_SEARCH_URL = "" # You can use gist raw link (remove commit id from the link, like config raw link check heroku guide)
|
||||||
# To use limit leave space between number and unit. Available units is (gb or GB, tb or TB)
|
# To use limit leave space between number and unit. Available units is (gb or GB, tb or TB)
|
||||||
TORRENT_DIRECT_LIMIT = ""
|
TORRENT_DIRECT_LIMIT = ""
|
||||||
TAR_UNZIP_LIMIT = ""
|
TAR_UNZIP_LIMIT = ""
|
||||||
CLONE_LIMIT = ""
|
CLONE_LIMIT = ""
|
||||||
MEGA_LIMIT = ""
|
MEGA_LIMIT = ""
|
||||||
# Required for Heroku
|
# Optional for Heroku features(dyno restart(/reboot) and update cnmd soon)
|
||||||
HEROKU_API_KEY = ""
|
HEROKU_API_KEY = ""
|
||||||
HEROKU_APP_NAME = ""
|
HEROKU_APP_NAME = ""
|
||||||
# View Link button to open file Index Link in browser instead of direct download link
|
# View Link button to open file Index Link in browser instead of direct download link
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,50 @@
|
||||||
|
import os
|
||||||
|
import re
|
||||||
|
print("\n\n"\
|
||||||
|
" Bot can search files recursively, but you have to add the list of drives you want to search.\n"\
|
||||||
|
" Use the following format: (You can use 'root' in the ID in case you wan to use main drive.)\n"\
|
||||||
|
" teamdrive NAME --> anything that u likes\n"\
|
||||||
|
" teamdrive ID --> id of teamdrives in which u likes to search ('root' for main drive)\n"\
|
||||||
|
" teamdrive INDEX URL --> enter index url for this drive.\n" \
|
||||||
|
" goto the respective drive and copy the url from address bar\n")
|
||||||
|
msg = ''
|
||||||
|
if os.path.exists('drive_folder'):
|
||||||
|
with open('drive_folder', 'r+') as f:
|
||||||
|
lines = f.read()
|
||||||
|
if not re.match(r'^\s*$', lines):
|
||||||
|
print(lines)
|
||||||
|
print("\n\n"\
|
||||||
|
" DO YOU WISH TO KEEP THE ABOVE DETAILS THAT YOU PREVIOUSLY ADDED???? ENTER (y/n)\n"\
|
||||||
|
" IF NOTHING SHOWS ENTER n")
|
||||||
|
while (1):
|
||||||
|
choice = input()
|
||||||
|
if choice == 'y' or choice == 'Y':
|
||||||
|
msg = f'{lines}'
|
||||||
|
break
|
||||||
|
elif choice == 'n' or choice == 'N':
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
print("\n\n DO YOU WISH TO KEEP THE ABOVE DETAILS ???? y/n <=== this is option ..... OPEN YOUR EYES & READ...")
|
||||||
|
num = int(input(" How Many Drive/Folder You Likes To Add : "))
|
||||||
|
count = 1
|
||||||
|
while count <= num :
|
||||||
|
print(f"\n > DRIVE - {count}\n")
|
||||||
|
name = input(" Enter Drive NAME (anything) : ")
|
||||||
|
id = input(" Enter Drive ID : ")
|
||||||
|
index = input(" Enter Drive INDEX URL (optional) : ")
|
||||||
|
if not name or not id:
|
||||||
|
print("\n\n ERROR : Dont leave the name/id without filling.")
|
||||||
|
exit(1)
|
||||||
|
name=name.replace(" ", "_")
|
||||||
|
if index:
|
||||||
|
if index[-1] == "/":
|
||||||
|
index = index[:-1]
|
||||||
|
else:
|
||||||
|
index = ''
|
||||||
|
count+=1
|
||||||
|
msg += f"{name} {id} {index}\n"
|
||||||
|
with open('drive_folder', 'w') as file:
|
||||||
|
file.truncate(0)
|
||||||
|
file.write(msg)
|
||||||
|
print("\n\n Done!")
|
||||||
|
|
||||||
|
|
@ -9,7 +9,7 @@ Accepted=true
|
||||||
Cookies=@Invalid()
|
Cookies=@Invalid()
|
||||||
|
|
||||||
[BitTorrent]
|
[BitTorrent]
|
||||||
Session\AsyncIOThreadsCount=32
|
Session\AsyncIOThreadsCount=4
|
||||||
Session\BTProtocol=Both
|
Session\BTProtocol=Both
|
||||||
Session\MultiConnectionsPerIp=true
|
Session\MultiConnectionsPerIp=true
|
||||||
Session\SlowTorrentsDownloadRate=100
|
Session\SlowTorrentsDownloadRate=100
|
||||||
|
|
@ -23,8 +23,8 @@ Advanced\IncludeOverhead=false
|
||||||
Advanced\RecheckOnCompletion=true
|
Advanced\RecheckOnCompletion=true
|
||||||
Advanced\LtTrackerExchange=true
|
Advanced\LtTrackerExchange=true
|
||||||
Advanced\SuperSeeding=false
|
Advanced\SuperSeeding=false
|
||||||
Bittorrent\MaxConnecs=3000
|
Bittorrent\MaxConnecs=-1
|
||||||
Bittorrent\MaxConnecsPerTorrent=500
|
Bittorrent\MaxConnecsPerTorrent=-1
|
||||||
Bittorrent\DHT=true
|
Bittorrent\DHT=true
|
||||||
Bittorrent\DHTPort=6881
|
Bittorrent\DHTPort=6881
|
||||||
Bittorrent\Encryption=0
|
Bittorrent\Encryption=0
|
||||||
|
|
@ -32,7 +32,7 @@ Bittorrent\PeX=true
|
||||||
Bittorrent\LSD=true
|
Bittorrent\LSD=true
|
||||||
Bittorrent\sameDHTPortAsBT=true
|
Bittorrent\sameDHTPortAsBT=true
|
||||||
Bittorrent\uTP=true
|
Bittorrent\uTP=true
|
||||||
Bittorrent\uTP_rate_limited=true
|
Bittorrent\uTP_rate_limited=false
|
||||||
Connection\PortRangeMin=6881
|
Connection\PortRangeMin=6881
|
||||||
Connection\UPnP=true
|
Connection\UPnP=true
|
||||||
Downloads\DiskWriteCacheSize=64
|
Downloads\DiskWriteCacheSize=64
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue