-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:
anas 2021-08-08 02:59:46 +03:00
parent bfeb829ef2
commit 8edadd83bd
9 changed files with 48 additions and 47 deletions

View File

@ -9,7 +9,23 @@ from dotenv import load_dotenv
load_dotenv('config.env')
url = os.environ.get("BASE_URL_OF_BOT")
while True:
time.sleep(1000)
status = requests.get(url).status_code
try:
BASE_URL = getConfig('BASE_URL_OF_BOT')
if len(BASE_URL) == 0:
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

View File

@ -123,12 +123,12 @@ def get_readable_message():
msg += f"\n<b>Status:</b> <i>{download.status()}</i>"
if download.status() != MirrorStatus.STATUS_ARCHIVING and download.status() != MirrorStatus.STATUS_EXTRACTING:
msg += f"\n<code>{get_progress_bar_string(download)} {download.progress()}</code>"
if download.status() == MirrorStatus.STATUS_DOWNLOADING:
msg += f"\n<b>Downloaded:</b> {get_readable_file_size(download.processed_bytes())} of {download.size()}"
elif download.status() == MirrorStatus.STATUS_CLONING:
if download.status() == MirrorStatus.STATUS_CLONING:
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()}"
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()}" \
f", <b>ETA:</b> {download.eta()} "
# if hasattr(download, 'is_torrent'):

View File

@ -68,6 +68,8 @@ class qbittorrent:
sendMessage("This is an unsupported/invalid link.", listener.bot, listener.update)
return
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)
tor_info = tor_info[0]
if BASE_URL is not None and qbitsel:
@ -102,10 +104,9 @@ class qbittorrent:
markup = sendMarkup(msg, listener.bot, listener.update, QBBUTTONS)
self.client.torrents_pause(torrent_hashes=self.ext_hash)
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:
with download_dict_lock:
download_dict[listener.uid] = QbDownloadStatus(gid, listener, self.ext_hash, self.client ,markup)
sendStatusMessage(listener.update, listener.bot)
except qba.UnsupportedMediaType415Error as e:
LOGGER.error(str(e))

View File

@ -11,15 +11,10 @@ class AriaDownloadStatus(Status):
def __init__(self, gid, listener):
super().__init__()
self.upload_name = None
self.is_archiving = False
self.__gid = gid
self.__download = get_download(self.__gid)
self.__uid = listener.uid
self.__listener = listener
self.message = listener.message
self.last = None
self.is_waiting = False
self.is_extracting = False
def __update(self):
self.__download = get_download(self.__gid)

View File

@ -9,17 +9,15 @@ from .status import Status
class QbDownloadStatus(Status):
def __init__(self, gid, listener, qbhash, client, markup):
def __init__(self, gid, listener, qbhash, client):
super().__init__()
self.__gid = gid
self.__hash = qbhash
self.__client = client
self.__markup = markup
self.markup = None
self.__uid = listener.uid
self.__listener = listener
self.message = listener.message
self.is_extracting = False
self.is_archiving = False
def progress(self):
@ -58,7 +56,7 @@ class QbDownloadStatus(Status):
download = self.torrent_info().state
if download == "queuedDL":
status = MirrorStatus.STATUS_WAITING
elif download == "metaDL":
elif download == "metaDL" or download == "checkingResumeData":
status = MirrorStatus.STATUS_DOWNLOADING + " (Metadata)"
elif download == "pausedDL":
status = MirrorStatus.STATUS_PAUSE
@ -89,7 +87,7 @@ class QbDownloadStatus(Status):
return self.__client
def mark(self):
return self.__markup
return self.markup
def cancel_download(self):
LOGGER.info(f"Cancelling Download: {self.name()}")

View File

@ -510,9 +510,10 @@ class GoogleDriveHelper:
mime_type = get_mime_type(current_file_name)
file_name = current_file_name.split("/")[-1]
# current_file_name will have the full path
self.upload_file(current_file_name, file_name, mime_type, parent_id)
self.total_files += 1
new_id = parent_id
if not file_name.endswith(".!qB"):
self.upload_file(current_file_name, file_name, mime_type, parent_id)
self.total_files += 1
new_id = parent_id
if self.is_cancelled:
break
return new_id

View File

@ -35,11 +35,11 @@ ariaDlManager = AriaDownloadHelper()
ariaDlManager.start_listener()
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)
self.isTar = isTar
self.tag = tag
self.extract = extract
self.qbit = qbit
self.pswd = pswd
def onDownloadStarted(self):
@ -65,11 +65,10 @@ class MirrorListener(listeners.MirrorListeners):
name = download.name()
gid = download.gid()
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]
m_path = f'{DOWNLOAD_DIR}{self.uid}/{name}'
if self.isTar:
download.is_archiving = True
try:
with download_dict_lock:
download_dict[self.uid] = TarStatus(name, m_path, size)
@ -79,12 +78,9 @@ class MirrorListener(listeners.MirrorListeners):
self.onUploadError('Internal error occurred!!')
return
elif self.extract:
download.is_extracting = True
try:
path = fs_utils.get_base_name(m_path)
LOGGER.info(
f"Extracting: {name} "
)
LOGGER.info(f"Extracting: {name}")
with download_dict_lock:
download_dict[self.uid] = ExtractStatus(name, m_path, size)
pswd = self.pswd
@ -98,9 +94,7 @@ class MirrorListener(listeners.MirrorListeners):
else:
LOGGER.warning('Unable to extract archive! Uploading anyway')
path = f'{DOWNLOAD_DIR}{self.uid}/{name}'
LOGGER.info(
f'got path: {path}'
)
LOGGER.info(f'got path: {path}')
except NotSupportedExtractionArchive:
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}'
up_name = pathlib.PurePath(path).name
up_path = f'{DOWNLOAD_DIR}{self.uid}/{up_name}'
if up_name == "None":
up_name = "".join(os.listdir(f'{DOWNLOAD_DIR}{self.uid}/'))
LOGGER.info(f"Upload Name: {up_name}")
LOGGER.info(f"Upload Name: {name}")
drive = gdriveTools.GoogleDriveHelper(up_name, self)
size = fs_utils.get_path_size(up_path)
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
if reply_to is not None:
file = None
tag = reply_to.from_user.username
media_array = [reply_to.document, reply_to.video, reply_to.audio]
for i in media_array:
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 file is not None:
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)
ms = update.message
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}"
else:
link = file.get_file().file_path
else:
tag = None
if not bot_utils.is_url(link) and not bot_utils.is_magnet(link):
sendMessage('No download source provided', bot, update)
return
@ -313,7 +303,7 @@ def _mirror(bot, update, isTar=False, extract=False):
sendMessage(f"{e}", bot, update)
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 not isTar and not extract:

View File

@ -33,7 +33,7 @@ SHORTENER_API = ""
# qBittorrent
IS_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
# These are optional, if you don't know, simply leave them, don't fill anything in them.
ACCOUNTS_ZIP_URL = ""

View File

@ -36,7 +36,7 @@ p { font-size: 12px; margin: 24px;}
</style>
</head>
<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">
{My_content}
@ -277,7 +277,7 @@ async def set_priority(request):
@routes.get('/')
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):