Skip to content

Commit

Permalink
Minor Fixes (SilentDemonSD#53)
Browse files Browse the repository at this point in the history
Minor fixes regarding aria2c options and for upload manually cancelled when using extension filter

committed-by DarkLordlk [[email protected]]
  • Loading branch information
DarkLordlk authored Dec 3, 2022
1 parent 92e6800 commit 38c6ceb
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 30 deletions.
12 changes: 8 additions & 4 deletions bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@ def aria2c_init():
aria2.add_uris([link], {'dir': dire})
sleep(3)
downloads = aria2.get_downloads()
sleep(20)
sleep(15)
aria2.remove(downloads, force=True, files=True, clean=True)
except Exception as e:
log_error(f"Aria2c initializing error: {e}")
Expand All @@ -826,8 +826,12 @@ def aria2c_init():
if not aria2_options:
aria2_options = aria2.client.get_global_option()
del aria2_options['dir']
del aria2_options['max-download-limit']
del aria2_options['lowest-speed-limit']
else:
a2c_glo = {}
for op in aria2c_global:
if op in aria2_options:
a2c_glo[op] = aria2_options[op]
aria2.set_global_options(a2c_glo)

qb_client = get_client()
if not qbit_options:
Expand All @@ -846,4 +850,4 @@ def aria2c_init():
updater = tgUpdater(token=BOT_TOKEN, request_kwargs={'read_timeout': 20, 'connect_timeout': 15})
bot = updater.bot
dispatcher = updater.dispatcher
job_queue = updater.job_queue
job_queue = updater.job_queue
2 changes: 1 addition & 1 deletion bot/helper/mirror_utils/download_utils/aria2_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ def __onBtDownloadComplete(api, gid):
except Exception as e:
LOGGER.error(f"{e} GID: {gid}" )
listener.onDownloadComplete()
download = download.live
if listener.seed:
download = download.live
if download.is_complete:
if dl := getDownloadByGid(gid):
LOGGER.info(f"Cancelling Seed: {download.name}")
Expand Down
10 changes: 5 additions & 5 deletions bot/helper/mirror_utils/status_utils/aria_download_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,15 @@ def cancel_download(self):
LOGGER.info(f"Cancelling Seed: {self.name()}")
self.__listener.onUploadError(f"Seeding stopped with Ratio: {self.ratio()} and Time: {self.seeding_time()}")
aria2.remove([self.__download], force=True, files=True)
elif len(self.__download.followed_by_ids) != 0:
elif downloads := self.__download.followed_by:
LOGGER.info(f"Cancelling Download: {self.name()}")
downloads = aria2.get_downloads(self.__download.followed_by_ids)
self.__listener.onDownloadError('Download stopped by user!')
self.__listener.onDownloadError('Download cancelled by user!')
downloads.append(self.__download)
aria2.remove(downloads, force=True, files=True)
else:
LOGGER.info(f"Cancelling Download: {self.name()}")
self.__listener.onDownloadError('Download stopped by user!')
aria2.remove([self.__download], force=True, files=True)
aria2.remove([self.__download], force=True, files=True)

def eng(self):
return EngineStatus.STATUS_ARIA
return EngineStatus.STATUS_ARIA
4 changes: 3 additions & 1 deletion bot/helper/mirror_utils/upload_utils/gdriveTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,8 @@ def __upload_dir(self, input_directory, dest_id):
self.__upload_file(current_file_name, file_name, mime_type, dest_id)
self.__total_files += 1
new_id = dest_id
else:
new_id = 'filter'
if self.__is_cancelled:
break
return new_id
Expand Down Expand Up @@ -951,4 +953,4 @@ def cancel_download(self):
LOGGER.info(f"Cancelling Clone: {self.name}")
elif self.__is_uploading:
LOGGER.info(f"Cancelling Upload: {self.name}")
self.__listener.onUploadError('your upload has been stopped and uploaded data has been deleted!')
self.__listener.onUploadError('your upload has been stopped and uploaded data has been deleted!')
5 changes: 3 additions & 2 deletions bot/helper/mirror_utils/upload_utils/pyrogramEngine.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ def upload(self, o_files):
if self.__listener.seed and not self.__listener.newDir:
clean_unwanted(self.__path)
if self.__total_files <= self.__corrupted:
return self.__listener.onUploadError('Files Corrupted. Check logs')
self.__listener.onUploadError('Files Corrupted. Check logs!')
return
LOGGER.info(f"Leech Completed: {self.name}")
size = get_readable_file_size(self.__size)
self.__listener.onUploadComplete(None, size, self.__msgs_dict, self.__total_files, self.__corrupted, self.name)
Expand Down Expand Up @@ -367,4 +368,4 @@ def speed(self):
def cancel_download(self):
self.__is_cancelled = True
LOGGER.info(f"Cancelling Upload: {self.name}")
self.__listener.onUploadError('Your upload has been stopped!')
self.__listener.onUploadError('Your upload has been stopped!')
73 changes: 56 additions & 17 deletions bot/modules/bot_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,13 +233,26 @@ def load_config():
TORRENT_TIMEOUT = environ.get('TORRENT_TIMEOUT', '')
downloads = aria2.get_downloads()
if len(TORRENT_TIMEOUT) == 0:
if downloads:
aria2.set_options({'bt-stop-timeout': '0'}, downloads)
for download in downloads:
if not download.is_complete:
try:
aria2.client.change_option(download.gid, {'bt-stop-timeout': '0'})
except Exception as e:
LOGGER.error(e)
aria2_options['bt-stop-timeout'] = '0'
if DATABASE_URL:
DbManger().update_aria2('bt-stop-timeout', '0')
TORRENT_TIMEOUT = ''
else:
if downloads:
aria2.set_options({'bt-stop-timeout': TORRENT_TIMEOUT}, downloads)
for download in downloads:
if not download.is_complete:
try:
aria2.client.change_option(download.gid, {'bt-stop-timeout': TORRENT_TIMEOUT})
except Exception as e:
LOGGER.error(e)
aria2_options['bt-stop-timeout'] = TORRENT_TIMEOUT
if DATABASE_URL:
DbManger().update_aria2('bt-stop-timeout', TORRENT_TIMEOUT)
TORRENT_TIMEOUT = int(TORRENT_TIMEOUT)


Expand Down Expand Up @@ -845,8 +858,12 @@ def edit_variable(update, context, omsg, key):
elif key == 'TORRENT_TIMEOUT':
value = int(value)
downloads = aria2.get_downloads()
if downloads:
aria2.set_options({'bt-stop-timeout': f'{value}'}, downloads)
for download in downloads:
if not download.is_complete:
try:
aria2.client.change_option(download.gid, {'bt-stop-timeout': f'{value}'})
except Exception as e:
LOGGER.error(e)
aria2_options['bt-stop-timeout'] = f'{value}'
elif key == 'TG_SPLIT_SIZE':
value = min(int(value), tgBotMaxFileSize)
Expand Down Expand Up @@ -893,8 +910,12 @@ def edit_aria(update, context, omsg, key):
aria2.set_global_options({key: value})
else:
downloads = aria2.get_downloads()
if downloads:
aria2.set_options({key: value}, downloads)
for download in downloads:
if not download.is_complete:
try:
aria2.client.change_option(download.gid, {key: value})
except Exception as e:
LOGGER.error(e)
aria2_options[key] = value
update_buttons(omsg, 'aria')
update.message.delete()
Expand Down Expand Up @@ -932,6 +953,10 @@ def update_private_file(update, context, omsg):
config_dict['USE_SERVICE_ACCOUNTS'] = False
if DATABASE_URL:
DbManger().update_config({'USE_SERVICE_ACCOUNTS': False})
elif file_name in ['.netrc', 'netrc']:
srun(["touch", ".netrc"])
srun(["cp", ".netrc", "/root/.netrc"])
srun(["chmod", "600", ".netrc"])
update.message.delete()
else:
doc = update.message.document
Expand Down Expand Up @@ -1022,9 +1047,15 @@ def edit_bot_settings(update, context):
GLOBAL_EXTENSION_FILTER.append('.aria2')
elif data[2] == 'TORRENT_TIMEOUT':
downloads = aria2.get_downloads()
if downloads:
aria2.set_options({'bt-stop-timeout': '0'}, downloads)
for download in downloads:
if not download.is_complete:
try:
aria2.client.change_option(download.gid, {'bt-stop-timeout': '0'})
except Exception as e:
LOGGER.error(e)
aria2_options['bt-stop-timeout'] = '0'
if DATABASE_URL:
DbManger().update_aria2('bt-stop-timeout', '0')
elif data[2] == 'BASE_URL':
srun(["pkill", "-9", "-f", "gunicorn"])
elif data[2] == 'SERVER_PORT':
Expand Down Expand Up @@ -1056,8 +1087,12 @@ def edit_bot_settings(update, context):
aria2_options[data[2]] = value
update_buttons(message, 'aria')
downloads = aria2.get_downloads()
if downloads:
aria2.set_options({data[2]: value}, downloads)
for download in downloads:
if not download.is_complete:
try:
aria2.client.change_option(download.gid, {data[2]: value})
except Exception as e:
LOGGER.error(e)
if DATABASE_URL:
DbManger().update_aria2(data[2], value)
elif data[1] == 'emptyaria':
Expand All @@ -1066,8 +1101,12 @@ def edit_bot_settings(update, context):
aria2_options[data[2]] = ''
update_buttons(message, 'aria')
downloads = aria2.get_downloads()
if downloads:
aria2.set_options({data[2]: ''}, downloads)
for download in downloads:
if not download.is_complete:
try:
aria2.client.change_option(download.gid, {data[2]: ''})
except Exception as e:
LOGGER.error(e)
if DATABASE_URL:
DbManger().update_aria2(data[2], '')
elif data[1] == 'emptyqbit':
Expand Down Expand Up @@ -1138,8 +1177,8 @@ def edit_bot_settings(update, context):
handler_dict[message.chat.id] = True
update_buttons(message, data[2], data[1])
partial_fnc = partial(edit_aria, omsg=message, key=data[2])
value_handler = MessageHandler(filters=Filters.text & Filters.chat(message.chat.id) &
(CustomFilters.owner_filter | CustomFilters.sudo_user), callback=partial_fnc, run_async=True)
value_handler = MessageHandler(filters=Filters.text & Filters.chat(message.chat.id) & Filters.user(user_id),
callback=partial_fnc, run_async=True)
dispatcher.add_handler(value_handler)
while handler_dict[message.chat.id]:
if time() - start_time > 60:
Expand Down Expand Up @@ -1225,4 +1264,4 @@ def bot_settings(update, context):
bb_set_handler = CallbackQueryHandler(edit_bot_settings, pattern="botset", run_async=True)

dispatcher.add_handler(bot_settings_handler)
dispatcher.add_handler(bb_set_handler)
dispatcher.add_handler(bb_set_handler)

0 comments on commit 38c6ceb

Please sign in to comment.