Skip to content

Commit

Permalink
Minor Updates
Browse files Browse the repository at this point in the history
Signed-off-by: priiiiyo <[email protected]>
Co-authored-by: anas
<[email protected]>
  • Loading branch information
priiiiyo committed Jan 27, 2022
1 parent 1283b79 commit aa1fc72
Show file tree
Hide file tree
Showing 26 changed files with 299 additions and 291 deletions.
184 changes: 89 additions & 95 deletions README.md

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion alive.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
from os import environ
from logging import error as logerror

BASE_URL = environ.get('BASE_URL_OF_BOT', None).rstrip("/")
BASE_URL = environ.get('BASE_URL_OF_BOT', None)
try:
if len(BASE_URL) == 0:
raise TypeError
BASE_URL = BASE_URL.rstrip("/")
except TypeError:
BASE_URL = None
PORT = environ.get('PORT', None)
Expand Down
4 changes: 2 additions & 2 deletions aria.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
tracker_list=$(curl -Ns https://raw.githubusercontent.com/XIU2/TrackersListCollection/master/all.txt https://ngosang.github.io/trackerslist/trackers_all_http.txt https://newtrackon.com/api/all https://raw.githubusercontent.com/hezhijie0327/Trackerslist/main/trackerslist_tracker.txt https://raw.githubusercontent.com/hezhijie0327/Trackerslist/main/trackerslist_exclude.txt | awk '$0' | tr '\n\n' ',')
aria2c --enable-rpc=true --check-certificate=false --daemon=true \
--max-connection-per-server=10 --rpc-max-request-size=1024M \
aria2c --enable-rpc=true --check-certificate=false --daemon=false \
--max-connection-per-server=10 --rpc-max-request-size=1024M --quiet=true \
--bt-stop-timeout=0 --min-split-size=10M --split=10 --allow-overwrite=true \
--max-overall-download-limit=0 --bt-tracker="[$tracker_list]" --disk-cache=32M \
--max-overall-upload-limit=1K --max-concurrent-downloads=15 --summary-interval=0 \
Expand Down
27 changes: 15 additions & 12 deletions bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import faulthandler

from telegram.ext import Updater as tgUpdater
from qbittorrentapi import TorrentsAPIMixIn, Client as qbClient
from qbittorrentapi import Client as qbClient
from aria2p import API as ariaAPI, Client as ariaClient
from os import remove as osremove, path as ospath, environ
from requests import get as rget
Expand Down Expand Up @@ -63,8 +63,8 @@ def getConfig(name: str):
srun(["cp", ".netrc", "/root/.netrc"])
srun(["chmod", "600", ".netrc"])
srun(["chmod", "+x", "aria.sh"])
srun(["./aria.sh"], shell=True)
sleep(0.5)
a2c = Popen(["./aria.sh"], shell=True)
sleep(1)

Interval = []
DRIVES_NAMES = []
Expand All @@ -86,7 +86,7 @@ def getConfig(name: str):
)
)

def get_client() -> TorrentsAPIMixIn:
def get_client():
return qbClient(host="localhost", port=8090)

"""
Expand Down Expand Up @@ -175,14 +175,16 @@ def aria2c_init():
try:
logging.info("Initializing Aria2c")
link = "https://releases.ubuntu.com/21.10/ubuntu-21.10-desktop-amd64.iso.torrent"
aria2.add_uris([link], {'dir': DOWNLOAD_DIR})
dire = DOWNLOAD_DIR.rstrip("/")
aria2.add_uris([link], {'dir': dire})
sleep(3)
downloads = aria2.get_downloads()
sleep(30)
for download in downloads:
aria2.remove([download], force=True, files=True)
except Exception as e:
logging.error(f"Aria2c initializing error: {e}")
pass

if not ospath.isfile(".restartmsg"):
Thread(target=aria2c_init).start()
Expand Down Expand Up @@ -301,6 +303,14 @@ def aria2c_init():
RSS_DELAY = int(RSS_DELAY)
except KeyError:
RSS_DELAY = 900
try:
QB_TIMEOUT = getConfig('QB_TIMEOUT')
if len(QB_TIMEOUT) == 0:
raise KeyError
else:
QB_TIMEOUT = int(QB_TIMEOUT)
except KeyError:
QB_TIMEOUT = None
try:
BUTTON_FOUR_NAME = getConfig('BUTTON_FOUR_NAME')
BUTTON_FOUR_URL = getConfig('BUTTON_FOUR_URL')
Expand Down Expand Up @@ -505,13 +515,6 @@ def aria2c_init():
if len(SEARCH_PLUGINS) == 0:
raise KeyError
SEARCH_PLUGINS = jsnloads(SEARCH_PLUGINS)
qbclient = get_client()
qb_plugins = qbclient.search_plugins()
if qb_plugins:
for plugin in qb_plugins:
p = plugin['name']
qbclient.search_uninstall_plugin(names=p)
qbclient.search_install_plugin(SEARCH_PLUGINS)
except KeyError:
SEARCH_PLUGINS = None

Expand Down
13 changes: 8 additions & 5 deletions bot/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from telegram.ext import CommandHandler

from wserver import start_server_async
from bot import bot, app, dispatcher, updater, botStartTime, IGNORE_PENDING_REQUESTS, IS_VPS, PORT, alive, web, OWNER_ID, AUTHORIZED_CHATS, LOGGER, Interval, nox, rss_session
from bot import bot, app, dispatcher, updater, botStartTime, IGNORE_PENDING_REQUESTS, IS_VPS, PORT, alive, web, OWNER_ID, AUTHORIZED_CHATS, LOGGER, Interval, nox, rss_session, a2c
from .helper.ext_utils.fs_utils import start_cleanup, clean_all, exit_clean_up
from .helper.telegram_helper.bot_commands import BotCommands
from .helper.telegram_helper.message_utils import sendMessage, sendMarkup, editMessage, sendLogFile
Expand Down Expand Up @@ -62,8 +62,8 @@ def stats(update, context):

def start(update, context):
buttons = ButtonMaker()
buttons.buildbutton("Repo", "https://www.github.com/anasty17/mirror-leech-telegram-bot")
buttons.buildbutton("Report Group", "https://t.me/+MwgSi5vmQEA2N2Vk")
buttons.buildbutton("Repo", "https://www.github.com/Appeza/tg-mirror-leech-bot")
buttons.buildbutton("Report Group", "https://t.me/+TWOOFONY5TZAgIgL")
reply_markup = InlineKeyboardMarkup(buttons.build_menu(2))
if CustomFilters.authorized_user(update) or CustomFilters.authorized_chat(update):
start_string = f'''
Expand All @@ -85,8 +85,11 @@ def restart(update, context):
procs.kill()
clean_all()
srun(["python3", "update.py"])
# Save restart message object in order to reply to it after restarting
nox.kill()
a2cproc = psprocess(a2c.pid)
for proc in a2cproc.children(recursive=True):
proc.kill()
a2cproc.kill()
with open(".restartmsg", "w") as f:
f.truncate(0)
f.write(f"{restart_message.chat.id}\n{restart_message.message_id}\n")
Expand Down Expand Up @@ -173,7 +176,7 @@ def log(update, context):
'''

help = telegraph.create_page(
title='Mirror-Leech-Bot Help',
title='TG-Mirror-Leech-Bot Help',
content=help_string_telegraph,
)["path"]

Expand Down
1 change: 1 addition & 0 deletions bot/helper/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

3 changes: 2 additions & 1 deletion bot/helper/ext_utils/db_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ def user_rm_thumb(self, user_id: int, path):

def user_check(self, uid: int):
self.cur.execute("SELECT * FROM users WHERE uid = {}".format(uid))
return self.cur.fetchone()
res = self.cur.fetchone()
return res

def rss_add(self, name, link, last, title, filters):
if self.err:
Expand Down
14 changes: 8 additions & 6 deletions bot/helper/ext_utils/shortenurl.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

import random

from pyshorteners import Shortener as pyShortener
from requests import get as rget
from requests import get as rget, post as rpost
from base64 import b64encode
from urllib.parse import quote
from urllib3 import disable_warnings
Expand All @@ -27,15 +26,18 @@ def short_url(longurl):
f"https://file-link.net/{SHORTENER_API}/{random.random() * 1000}/dynamic?r={url}"]
link = random.choice(linkvertise)
elif "bitly.com" in SHORTENER:
s = pyShortener(api_key=SHORTENER_API)
link = s.bitly.short(longurl)
shorten_url = "https://api-ssl.bit.ly/v4/shorten"
params = {"long_url": longurl}
headers = {"Authorization": f"Bearer {SHORTENER_API}"}
response = rpost(shorten_url, json=params, headers=headers).json()
link = response["link"]
elif "ouo.io" in SHORTENER:
disable_warnings()
link = rget(f'http://ouo.io/api/{SHORTENER_API}?s={longurl}', verify=False).text
else:
link = rget(f'https://{SHORTENER}/api?api={SHORTENER_API}&url={longurl}&format=text').text
link = rget(f'https://{SHORTENER}/api?api={SHORTENER_API}&url={quote(longurl)}&format=text').text

if len(link) == 0:
LOGGER.error("Something is Wrong with the url shortener")
return longurl
return link
return link
63 changes: 31 additions & 32 deletions bot/helper/mirror_utils/download_utils/aria2_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from bot.helper.mirror_utils.status_utils.aria_download_status import AriaDownloadStatus
from bot.helper.telegram_helper.message_utils import sendMarkup, sendStatusMessage, sendMessage
from bot.helper.ext_utils.fs_utils import get_base_name
from bot.helper.ext_utils.exceptions import NotSupportedExtractionArchive


@new_thread
Expand All @@ -17,37 +16,37 @@ def __onDownloadStarted(api, gid):
sleep(1.5)
dl = getDownloadByGid(gid)
download = api.get_download(gid)
if STOP_DUPLICATE and dl is not None and not dl.getListener().isLeech:
LOGGER.info('Checking File/Folder if already in Drive...')
sname = download.name
if dl.getListener().isZip:
sname = sname + ".zip"
elif dl.getListener().extract:
try:
sname = get_base_name(sname)
except NotSupportedExtractionArchive:
dl.getListener().onDownloadError("Not any valid archive.")
return api.remove([download], force=True, files=True)
smsg, button = GoogleDriveHelper().drive_list(sname, True)
if smsg:
dl.getListener().onDownloadError('File/Folder already available in Drive.\n\n')
api.remove([download], force=True, files=True)
return sendMarkup("Here are the search results:", dl.getListener().bot, dl.getListener().update, button)
if dl is not None and (ZIP_UNZIP_LIMIT is not None or TORRENT_DIRECT_LIMIT is not None):
sleep(1)
limit = None
if ZIP_UNZIP_LIMIT is not None and (dl.getListener().isZip or dl.getListener().extract):
mssg = f'Zip/Unzip limit is {ZIP_UNZIP_LIMIT}GB'
limit = ZIP_UNZIP_LIMIT
elif TORRENT_DIRECT_LIMIT is not None:
mssg = f'Torrent/Direct limit is {TORRENT_DIRECT_LIMIT}GB'
limit = TORRENT_DIRECT_LIMIT
if limit is not None:
LOGGER.info('Checking File/Folder Size...')
size = api.get_download(gid).total_length
if size > limit * 1024**3:
dl.getListener().onDownloadError(f'{mssg}.\nYour File/Folder size is {get_readable_file_size(size)}')
return api.remove([download], force=True, files=True)
if STOP_DUPLICATE and dl is not None and not dl.getListener().isLeech:
LOGGER.info('Checking File/Folder if already in Drive...')
sname = download.name
if dl.getListener().isZip:
sname = sname + ".zip"
elif dl.getListener().extract:
try:
sname = get_base_name(sname)
except:
sname = None
if sname is not None:
smsg, button = GoogleDriveHelper().drive_list(sname, True)
if smsg:
dl.getListener().onDownloadError('File/Folder already available in Drive.\n\n')
api.remove([download], force=True, files=True)
return sendMarkup("Here are the search results:", dl.getListener().bot, dl.getListener().update, button)
if dl is not None and (ZIP_UNZIP_LIMIT is not None or TORRENT_DIRECT_LIMIT is not None):
sleep(1)
limit = None
if ZIP_UNZIP_LIMIT is not None and (dl.getListener().isZip or dl.getListener().extract):
mssg = f'Zip/Unzip limit is {ZIP_UNZIP_LIMIT}GB'
limit = ZIP_UNZIP_LIMIT
elif TORRENT_DIRECT_LIMIT is not None:
mssg = f'Torrent/Direct limit is {TORRENT_DIRECT_LIMIT}GB'
limit = TORRENT_DIRECT_LIMIT
if limit is not None:
LOGGER.info('Checking File/Folder Size...')
size = api.get_download(gid).total_length
if size > limit * 1024**3:
dl.getListener().onDownloadError(f'{mssg}.\nYour File/Folder size is {get_readable_file_size(size)}')
return api.remove([download], force=True, files=True)
except:
LOGGER.error(f"onDownloadStart: {gid} stop duplicate and size check didn't pass")

Expand Down
14 changes: 7 additions & 7 deletions bot/helper/mirror_utils/download_utils/gd_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from bot.helper.telegram_helper.message_utils import sendMessage, sendStatusMessage, sendMarkup
from bot.helper.ext_utils.bot_utils import get_readable_file_size
from bot.helper.ext_utils.fs_utils import get_base_name
from bot.helper.ext_utils.exceptions import NotSupportedExtractionArchive


def add_gd_download(link: str, listener, gdtot):
Expand All @@ -22,12 +21,13 @@ def add_gd_download(link: str, listener, gdtot):
elif listener.extract:
try:
gname = get_base_name(name)
except NotSupportedExtractionArchive:
return sendMessage("Not any valid archive.", listener.bot, listener.update)
gmsg, button = GoogleDriveHelper().drive_list(gname, True)
if gmsg:
msg = "File/Folder is already available in Drive.\nHere are the search results:"
return sendMarkup(msg, listener.bot, listener.update, button)
except:
gname = None
if gname is not None:
gmsg, button = GoogleDriveHelper().drive_list(gname, True)
if gmsg:
msg = "File/Folder is already available in Drive.\nHere are the search results:"
return sendMarkup(msg, listener.bot, listener.update, button)
if ZIP_UNZIP_LIMIT is not None:
LOGGER.info('Checking File/Folder Size...')
if size > ZIP_UNZIP_LIMIT * 1024**3:
Expand Down
14 changes: 7 additions & 7 deletions bot/helper/mirror_utils/download_utils/mega_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from bot.helper.mirror_utils.status_utils.mega_download_status import MegaDownloadStatus
from bot.helper.mirror_utils.upload_utils.gdriveTools import GoogleDriveHelper
from bot.helper.ext_utils.fs_utils import get_base_name
from bot.helper.ext_utils.exceptions import NotSupportedExtractionArchive


class MegaAppListener(MegaListener):
Expand Down Expand Up @@ -162,12 +161,13 @@ def add_mega_download(mega_link: str, path: str, listener):
elif listener.extract:
try:
mname = get_base_name(mname)
except NotSupportedExtractionArchive:
return sendMessage("Not any valid archive.", listener.bot, listener.update)
smsg, button = GoogleDriveHelper().drive_list(mname, True)
if smsg:
msg1 = "File/Folder is already available in Drive.\nHere are the search results:"
return sendMarkup(msg1, listener.bot, listener.update, button)
except:
mname = None
if mname is not None:
smsg, button = GoogleDriveHelper().drive_list(mname, True)
if smsg:
msg1 = "File/Folder is already available in Drive.\nHere are the search results:"
return sendMarkup(msg1, listener.bot, listener.update, button)
limit = None
if ZIP_UNZIP_LIMIT is not None and (listener.isZip or listener.extract):
msg3 = f'Failed, Zip/Unzip limit is {ZIP_UNZIP_LIMIT}GB.\nYour File/Folder size is {get_readable_file_size(api.getSize(node))}.'
Expand Down
Loading

0 comments on commit aa1fc72

Please sign in to comment.