Fix
-fix upload .!qB extension file afetr selecting files -fix no such directory -optional alive.py to avoid error Signed-off-by: anas <e.anastayyar@gmail.com>
This commit is contained in:
parent
bfeb829ef2
commit
8edadd83bd
24
alive.py
24
alive.py
|
|
@ -9,7 +9,23 @@ from dotenv import load_dotenv
|
||||||
|
|
||||||
load_dotenv('config.env')
|
load_dotenv('config.env')
|
||||||
|
|
||||||
url = os.environ.get("BASE_URL_OF_BOT")
|
try:
|
||||||
while True:
|
BASE_URL = getConfig('BASE_URL_OF_BOT')
|
||||||
time.sleep(1000)
|
if len(BASE_URL) == 0:
|
||||||
status = requests.get(url).status_code
|
BASE_URL = None
|
||||||
|
except KeyError:
|
||||||
|
BASE_URL = None
|
||||||
|
|
||||||
|
try:
|
||||||
|
IS_VPS = getConfig('IS_VPS')
|
||||||
|
if IS_VPS.lower() == 'true':
|
||||||
|
IS_VPS = True
|
||||||
|
else:
|
||||||
|
IS_VPS = False
|
||||||
|
except KeyError:
|
||||||
|
IS_VPS = False
|
||||||
|
|
||||||
|
if not IS_VPS and BASE_URL is not None:
|
||||||
|
while True:
|
||||||
|
time.sleep(1000)
|
||||||
|
status = requests.get(BASE_URL).status_code
|
||||||
|
|
|
||||||
|
|
@ -123,12 +123,12 @@ def get_readable_message():
|
||||||
msg += f"\n<b>Status:</b> <i>{download.status()}</i>"
|
msg += f"\n<b>Status:</b> <i>{download.status()}</i>"
|
||||||
if download.status() != MirrorStatus.STATUS_ARCHIVING and download.status() != MirrorStatus.STATUS_EXTRACTING:
|
if download.status() != MirrorStatus.STATUS_ARCHIVING and download.status() != MirrorStatus.STATUS_EXTRACTING:
|
||||||
msg += f"\n<code>{get_progress_bar_string(download)} {download.progress()}</code>"
|
msg += f"\n<code>{get_progress_bar_string(download)} {download.progress()}</code>"
|
||||||
if download.status() == MirrorStatus.STATUS_DOWNLOADING:
|
if download.status() == MirrorStatus.STATUS_CLONING:
|
||||||
msg += f"\n<b>Downloaded:</b> {get_readable_file_size(download.processed_bytes())} of {download.size()}"
|
|
||||||
elif download.status() == MirrorStatus.STATUS_CLONING:
|
|
||||||
msg += f"\n<b>Cloned:</b> {get_readable_file_size(download.processed_bytes())} of {download.size()}"
|
msg += f"\n<b>Cloned:</b> {get_readable_file_size(download.processed_bytes())} of {download.size()}"
|
||||||
else:
|
elif download.status() == MirrorStatus.STATUS_UPLOADING:
|
||||||
msg += f"\n<b>Uploaded:</b> {get_readable_file_size(download.processed_bytes())} of {download.size()}"
|
msg += f"\n<b>Uploaded:</b> {get_readable_file_size(download.processed_bytes())} of {download.size()}"
|
||||||
|
else:
|
||||||
|
msg += f"\n<b>Downloaded:</b> {get_readable_file_size(download.processed_bytes())} of {download.size()}"
|
||||||
msg += f"\n<b>Speed:</b> {download.speed()}" \
|
msg += f"\n<b>Speed:</b> {download.speed()}" \
|
||||||
f", <b>ETA:</b> {download.eta()} "
|
f", <b>ETA:</b> {download.eta()} "
|
||||||
# if hasattr(download, 'is_torrent'):
|
# if hasattr(download, 'is_torrent'):
|
||||||
|
|
|
||||||
|
|
@ -68,6 +68,8 @@ class qbittorrent:
|
||||||
sendMessage("This is an unsupported/invalid link.", listener.bot, listener.update)
|
sendMessage("This is an unsupported/invalid link.", listener.bot, listener.update)
|
||||||
return
|
return
|
||||||
gid = ''.join(random.SystemRandom().choices(string.ascii_letters + string.digits, k=14))
|
gid = ''.join(random.SystemRandom().choices(string.ascii_letters + string.digits, k=14))
|
||||||
|
with download_dict_lock:
|
||||||
|
download_dict[listener.uid] = QbDownloadStatus(gid, listener, self.ext_hash, self.client)
|
||||||
self.updater = setInterval(self.update_interval, self.update)
|
self.updater = setInterval(self.update_interval, self.update)
|
||||||
tor_info = tor_info[0]
|
tor_info = tor_info[0]
|
||||||
if BASE_URL is not None and qbitsel:
|
if BASE_URL is not None and qbitsel:
|
||||||
|
|
@ -102,10 +104,9 @@ class qbittorrent:
|
||||||
markup = sendMarkup(msg, listener.bot, listener.update, QBBUTTONS)
|
markup = sendMarkup(msg, listener.bot, listener.update, QBBUTTONS)
|
||||||
self.client.torrents_pause(torrent_hashes=self.ext_hash)
|
self.client.torrents_pause(torrent_hashes=self.ext_hash)
|
||||||
with download_dict_lock:
|
with download_dict_lock:
|
||||||
download_dict[listener.uid] = QbDownloadStatus(gid, listener, self.ext_hash, self.client, markup)
|
download = download_dict[listener.uid]
|
||||||
|
download.markup = markup
|
||||||
else:
|
else:
|
||||||
with download_dict_lock:
|
|
||||||
download_dict[listener.uid] = QbDownloadStatus(gid, listener, self.ext_hash, self.client ,markup)
|
|
||||||
sendStatusMessage(listener.update, listener.bot)
|
sendStatusMessage(listener.update, listener.bot)
|
||||||
except qba.UnsupportedMediaType415Error as e:
|
except qba.UnsupportedMediaType415Error as e:
|
||||||
LOGGER.error(str(e))
|
LOGGER.error(str(e))
|
||||||
|
|
|
||||||
|
|
@ -11,15 +11,10 @@ class AriaDownloadStatus(Status):
|
||||||
def __init__(self, gid, listener):
|
def __init__(self, gid, listener):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.upload_name = None
|
self.upload_name = None
|
||||||
self.is_archiving = False
|
|
||||||
self.__gid = gid
|
self.__gid = gid
|
||||||
self.__download = get_download(self.__gid)
|
self.__download = get_download(self.__gid)
|
||||||
self.__uid = listener.uid
|
self.__uid = listener.uid
|
||||||
self.__listener = listener
|
self.__listener = listener
|
||||||
self.message = listener.message
|
|
||||||
self.last = None
|
|
||||||
self.is_waiting = False
|
|
||||||
self.is_extracting = False
|
|
||||||
|
|
||||||
def __update(self):
|
def __update(self):
|
||||||
self.__download = get_download(self.__gid)
|
self.__download = get_download(self.__gid)
|
||||||
|
|
|
||||||
|
|
@ -9,17 +9,15 @@ from .status import Status
|
||||||
|
|
||||||
class QbDownloadStatus(Status):
|
class QbDownloadStatus(Status):
|
||||||
|
|
||||||
def __init__(self, gid, listener, qbhash, client, markup):
|
def __init__(self, gid, listener, qbhash, client):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.__gid = gid
|
self.__gid = gid
|
||||||
self.__hash = qbhash
|
self.__hash = qbhash
|
||||||
self.__client = client
|
self.__client = client
|
||||||
self.__markup = markup
|
self.markup = None
|
||||||
self.__uid = listener.uid
|
self.__uid = listener.uid
|
||||||
self.__listener = listener
|
self.__listener = listener
|
||||||
self.message = listener.message
|
self.message = listener.message
|
||||||
self.is_extracting = False
|
|
||||||
self.is_archiving = False
|
|
||||||
|
|
||||||
|
|
||||||
def progress(self):
|
def progress(self):
|
||||||
|
|
@ -58,7 +56,7 @@ class QbDownloadStatus(Status):
|
||||||
download = self.torrent_info().state
|
download = self.torrent_info().state
|
||||||
if download == "queuedDL":
|
if download == "queuedDL":
|
||||||
status = MirrorStatus.STATUS_WAITING
|
status = MirrorStatus.STATUS_WAITING
|
||||||
elif download == "metaDL":
|
elif download == "metaDL" or download == "checkingResumeData":
|
||||||
status = MirrorStatus.STATUS_DOWNLOADING + " (Metadata)"
|
status = MirrorStatus.STATUS_DOWNLOADING + " (Metadata)"
|
||||||
elif download == "pausedDL":
|
elif download == "pausedDL":
|
||||||
status = MirrorStatus.STATUS_PAUSE
|
status = MirrorStatus.STATUS_PAUSE
|
||||||
|
|
@ -89,7 +87,7 @@ class QbDownloadStatus(Status):
|
||||||
return self.__client
|
return self.__client
|
||||||
|
|
||||||
def mark(self):
|
def mark(self):
|
||||||
return self.__markup
|
return self.markup
|
||||||
|
|
||||||
def cancel_download(self):
|
def cancel_download(self):
|
||||||
LOGGER.info(f"Cancelling Download: {self.name()}")
|
LOGGER.info(f"Cancelling Download: {self.name()}")
|
||||||
|
|
|
||||||
|
|
@ -510,9 +510,10 @@ class GoogleDriveHelper:
|
||||||
mime_type = get_mime_type(current_file_name)
|
mime_type = get_mime_type(current_file_name)
|
||||||
file_name = current_file_name.split("/")[-1]
|
file_name = current_file_name.split("/")[-1]
|
||||||
# current_file_name will have the full path
|
# current_file_name will have the full path
|
||||||
self.upload_file(current_file_name, file_name, mime_type, parent_id)
|
if not file_name.endswith(".!qB"):
|
||||||
self.total_files += 1
|
self.upload_file(current_file_name, file_name, mime_type, parent_id)
|
||||||
new_id = parent_id
|
self.total_files += 1
|
||||||
|
new_id = parent_id
|
||||||
if self.is_cancelled:
|
if self.is_cancelled:
|
||||||
break
|
break
|
||||||
return new_id
|
return new_id
|
||||||
|
|
|
||||||
|
|
@ -35,11 +35,11 @@ ariaDlManager = AriaDownloadHelper()
|
||||||
ariaDlManager.start_listener()
|
ariaDlManager.start_listener()
|
||||||
|
|
||||||
class MirrorListener(listeners.MirrorListeners):
|
class MirrorListener(listeners.MirrorListeners):
|
||||||
def __init__(self, bot, update, pswd, isTar=False, tag=None, extract=False):
|
def __init__(self, bot, update, pswd, isTar=False, extract=False, qbit=False):
|
||||||
super().__init__(bot, update)
|
super().__init__(bot, update)
|
||||||
self.isTar = isTar
|
self.isTar = isTar
|
||||||
self.tag = tag
|
|
||||||
self.extract = extract
|
self.extract = extract
|
||||||
|
self.qbit = qbit
|
||||||
self.pswd = pswd
|
self.pswd = pswd
|
||||||
|
|
||||||
def onDownloadStarted(self):
|
def onDownloadStarted(self):
|
||||||
|
|
@ -65,11 +65,10 @@ class MirrorListener(listeners.MirrorListeners):
|
||||||
name = download.name()
|
name = download.name()
|
||||||
gid = download.gid()
|
gid = download.gid()
|
||||||
size = download.size_raw()
|
size = download.size_raw()
|
||||||
if name is None: # when pyrogram's media.file_name is of NoneType
|
if name is None or self.qbit: # when pyrogram's media.file_name is of NoneType
|
||||||
name = os.listdir(f'{DOWNLOAD_DIR}{self.uid}')[0]
|
name = os.listdir(f'{DOWNLOAD_DIR}{self.uid}')[0]
|
||||||
m_path = f'{DOWNLOAD_DIR}{self.uid}/{name}'
|
m_path = f'{DOWNLOAD_DIR}{self.uid}/{name}'
|
||||||
if self.isTar:
|
if self.isTar:
|
||||||
download.is_archiving = True
|
|
||||||
try:
|
try:
|
||||||
with download_dict_lock:
|
with download_dict_lock:
|
||||||
download_dict[self.uid] = TarStatus(name, m_path, size)
|
download_dict[self.uid] = TarStatus(name, m_path, size)
|
||||||
|
|
@ -79,12 +78,9 @@ class MirrorListener(listeners.MirrorListeners):
|
||||||
self.onUploadError('Internal error occurred!!')
|
self.onUploadError('Internal error occurred!!')
|
||||||
return
|
return
|
||||||
elif self.extract:
|
elif self.extract:
|
||||||
download.is_extracting = True
|
|
||||||
try:
|
try:
|
||||||
path = fs_utils.get_base_name(m_path)
|
path = fs_utils.get_base_name(m_path)
|
||||||
LOGGER.info(
|
LOGGER.info(f"Extracting: {name}")
|
||||||
f"Extracting: {name} "
|
|
||||||
)
|
|
||||||
with download_dict_lock:
|
with download_dict_lock:
|
||||||
download_dict[self.uid] = ExtractStatus(name, m_path, size)
|
download_dict[self.uid] = ExtractStatus(name, m_path, size)
|
||||||
pswd = self.pswd
|
pswd = self.pswd
|
||||||
|
|
@ -98,9 +94,7 @@ class MirrorListener(listeners.MirrorListeners):
|
||||||
else:
|
else:
|
||||||
LOGGER.warning('Unable to extract archive! Uploading anyway')
|
LOGGER.warning('Unable to extract archive! Uploading anyway')
|
||||||
path = f'{DOWNLOAD_DIR}{self.uid}/{name}'
|
path = f'{DOWNLOAD_DIR}{self.uid}/{name}'
|
||||||
LOGGER.info(
|
LOGGER.info(f'got path: {path}')
|
||||||
f'got path: {path}'
|
|
||||||
)
|
|
||||||
|
|
||||||
except NotSupportedExtractionArchive:
|
except NotSupportedExtractionArchive:
|
||||||
LOGGER.info("Not any valid archive, uploading file as it is.")
|
LOGGER.info("Not any valid archive, uploading file as it is.")
|
||||||
|
|
@ -109,9 +103,7 @@ class MirrorListener(listeners.MirrorListeners):
|
||||||
path = f'{DOWNLOAD_DIR}{self.uid}/{name}'
|
path = f'{DOWNLOAD_DIR}{self.uid}/{name}'
|
||||||
up_name = pathlib.PurePath(path).name
|
up_name = pathlib.PurePath(path).name
|
||||||
up_path = f'{DOWNLOAD_DIR}{self.uid}/{up_name}'
|
up_path = f'{DOWNLOAD_DIR}{self.uid}/{up_name}'
|
||||||
if up_name == "None":
|
LOGGER.info(f"Upload Name: {name}")
|
||||||
up_name = "".join(os.listdir(f'{DOWNLOAD_DIR}{self.uid}/'))
|
|
||||||
LOGGER.info(f"Upload Name: {up_name}")
|
|
||||||
drive = gdriveTools.GoogleDriveHelper(up_name, self)
|
drive = gdriveTools.GoogleDriveHelper(up_name, self)
|
||||||
size = fs_utils.get_path_size(up_path)
|
size = fs_utils.get_path_size(up_path)
|
||||||
upload_status = UploadStatus(drive, size, gid, self)
|
upload_status = UploadStatus(drive, size, gid, self)
|
||||||
|
|
@ -275,7 +267,6 @@ def _mirror(bot, update, isTar=False, extract=False):
|
||||||
reply_to = update.message.reply_to_message
|
reply_to = update.message.reply_to_message
|
||||||
if reply_to is not None:
|
if reply_to is not None:
|
||||||
file = None
|
file = None
|
||||||
tag = reply_to.from_user.username
|
|
||||||
media_array = [reply_to.document, reply_to.video, reply_to.audio]
|
media_array = [reply_to.document, reply_to.video, reply_to.audio]
|
||||||
for i in media_array:
|
for i in media_array:
|
||||||
if i is not None:
|
if i is not None:
|
||||||
|
|
@ -285,7 +276,7 @@ def _mirror(bot, update, isTar=False, extract=False):
|
||||||
if not bot_utils.is_url(link) and not bot_utils.is_magnet(link) or len(link) == 0:
|
if not bot_utils.is_url(link) and not bot_utils.is_magnet(link) or len(link) == 0:
|
||||||
if file is not None:
|
if file is not None:
|
||||||
if file.mime_type != "application/x-bittorrent":
|
if file.mime_type != "application/x-bittorrent":
|
||||||
listener = MirrorListener(bot, update, pswd, isTar, tag, extract)
|
listener = MirrorListener(bot, update, pswd, isTar, extract)
|
||||||
tg_downloader = TelegramDownloadHelper(listener)
|
tg_downloader = TelegramDownloadHelper(listener)
|
||||||
ms = update.message
|
ms = update.message
|
||||||
tg_downloader.add_download(ms, f'{DOWNLOAD_DIR}{listener.uid}/', name)
|
tg_downloader.add_download(ms, f'{DOWNLOAD_DIR}{listener.uid}/', name)
|
||||||
|
|
@ -296,8 +287,7 @@ def _mirror(bot, update, isTar=False, extract=False):
|
||||||
link = f"/usr/src/app/{file.file_name}"
|
link = f"/usr/src/app/{file.file_name}"
|
||||||
else:
|
else:
|
||||||
link = file.get_file().file_path
|
link = file.get_file().file_path
|
||||||
else:
|
|
||||||
tag = None
|
|
||||||
if not bot_utils.is_url(link) and not bot_utils.is_magnet(link):
|
if not bot_utils.is_url(link) and not bot_utils.is_magnet(link):
|
||||||
sendMessage('No download source provided', bot, update)
|
sendMessage('No download source provided', bot, update)
|
||||||
return
|
return
|
||||||
|
|
@ -313,7 +303,7 @@ def _mirror(bot, update, isTar=False, extract=False):
|
||||||
sendMessage(f"{e}", bot, update)
|
sendMessage(f"{e}", bot, update)
|
||||||
return
|
return
|
||||||
|
|
||||||
listener = MirrorListener(bot, update, pswd, isTar, tag, extract)
|
listener = MirrorListener(bot, update, pswd, isTar, extract, qbit)
|
||||||
|
|
||||||
if bot_utils.is_gdrive_link(link):
|
if bot_utils.is_gdrive_link(link):
|
||||||
if not isTar and not extract:
|
if not isTar and not extract:
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ SHORTENER_API = ""
|
||||||
# qBittorrent
|
# qBittorrent
|
||||||
IS_VPS = ""
|
IS_VPS = ""
|
||||||
SERVER_PORT = "80" # For VPS
|
SERVER_PORT = "80" # For VPS
|
||||||
BASE_URL_OF_BOT = ""
|
BASE_URL_OF_BOT = "" #required for heroku
|
||||||
# If you want to use Credentials externally from Index Links, fill these vars with the direct links
|
# If you want to use Credentials externally from Index Links, fill these vars with the direct links
|
||||||
# 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 = ""
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ p { font-size: 12px; margin: 24px;}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>slam-tg-mirror-bot: <a href="#">Github</a></h1>
|
<h1>slam-tg-mirror-bot: <a href="https://github.com/breakdowns/slam-tg-mirror-bot">@Github</a></h1>
|
||||||
<form action="{form_url}" method="POST">
|
<form action="{form_url}" method="POST">
|
||||||
|
|
||||||
{My_content}
|
{My_content}
|
||||||
|
|
@ -277,7 +277,7 @@ async def set_priority(request):
|
||||||
@routes.get('/')
|
@routes.get('/')
|
||||||
async def homepage(request):
|
async def homepage(request):
|
||||||
|
|
||||||
return web.Response(text="<h1>See slam-mirror-bot <a href=\"#\">@GitHub</a>By Slam</h1>",content_type="text/html")
|
return web.Response(text="<h1>See slam-tg-mirror-bot <a href='https://github.com/breakdowns/slam-tg-mirror-bot'>@GitHub</a> By <a href='https://github.com/breakdowns'>Breakdowns</a></h1>",content_type="text/html")
|
||||||
|
|
||||||
async def e404_middleware(app, handler):
|
async def e404_middleware(app, handler):
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue