mirror of
https://github.com/anasty17/mirror-leech-telegram-bot.git
synced 2025-01-08 12:07:33 +08:00
Minor fixes
Signed-off-by: anasty17 <e.anastayyar@gmail.com>
This commit is contained in:
parent
d0930ee050
commit
e867da0fe3
@ -163,12 +163,14 @@ def update_user_ldata(id_, key, value):
|
||||
user_data[id_][key] = value
|
||||
|
||||
|
||||
async def retry_function(func, *args, **kwargs):
|
||||
async def retry_function(func, *args, retry=10, **kwargs):
|
||||
try:
|
||||
return await sync_to_async(func, *args, **kwargs)
|
||||
except:
|
||||
if retry == 0:
|
||||
return "Unable to connect to jdserver!"
|
||||
await sleep(0.3)
|
||||
return await retry_function(func, *args, **kwargs)
|
||||
return await retry_function(func, *args, retry=retry-1, **kwargs)
|
||||
|
||||
|
||||
async def cmd_exec(cmd, shell=False):
|
||||
|
@ -73,7 +73,7 @@ async def clean_target(path):
|
||||
LOGGER.info(f"Cleaning Target: {path}")
|
||||
try:
|
||||
if await aiopath.isdir(path):
|
||||
await aiormtree(path)
|
||||
await aiormtree(path, ignore_errors=True)
|
||||
else:
|
||||
await remove(path)
|
||||
except Exception as e:
|
||||
@ -84,7 +84,7 @@ async def clean_download(path):
|
||||
if await aiopath.exists(path):
|
||||
LOGGER.info(f"Cleaning Download: {path}")
|
||||
try:
|
||||
await aiormtree(path)
|
||||
await aiormtree(path, ignore_errors=True)
|
||||
except Exception as e:
|
||||
LOGGER.error(str(e))
|
||||
|
||||
@ -93,7 +93,7 @@ def clean_all():
|
||||
aria2.remove_all(True)
|
||||
get_qb_client().torrents_delete(torrent_hashes="all")
|
||||
try:
|
||||
rmtree(DOWNLOAD_DIR)
|
||||
rmtree(DOWNLOAD_DIR, ignore_errors=True)
|
||||
except:
|
||||
pass
|
||||
makedirs(DOWNLOAD_DIR, exist_ok=True)
|
||||
@ -123,7 +123,7 @@ async def clean_unwanted(path, custom_list=[]):
|
||||
):
|
||||
await remove(f_path)
|
||||
if dirpath.endswith((".unwanted", "splited_files_mltb", "copied_mltb")):
|
||||
await aiormtree(dirpath)
|
||||
await aiormtree(dirpath, ignore_errors=True)
|
||||
for dirpath, _, files in await sync_to_async(walk, path, topdown=False):
|
||||
if not await listdir(dirpath):
|
||||
await rmdir(dirpath)
|
||||
|
@ -97,8 +97,6 @@ async def _onBtDownloadComplete(api, gid):
|
||||
seed_start_time = time()
|
||||
await sleep(1)
|
||||
download = await sync_to_async(api.get_download, gid)
|
||||
if download.options.follow_torrent == "false":
|
||||
return
|
||||
LOGGER.info(f"onBtDownloadComplete: {download.name} - Gid: {gid}")
|
||||
if task := await getTaskByGid(gid):
|
||||
task.listener.isTorrent = True
|
||||
@ -138,7 +136,7 @@ async def _onBtDownloadComplete(api, gid):
|
||||
f"Seeding stopped with Ratio: {task.ratio()} and Time: {task.seeding_time()}"
|
||||
)
|
||||
await sync_to_async(api.remove, [download], force=True, files=True)
|
||||
else:
|
||||
elif not task.is_cancelled:
|
||||
async with task_dict_lock:
|
||||
if task.listener.mid not in task_dict:
|
||||
await sync_to_async(
|
||||
@ -149,6 +147,8 @@ async def _onBtDownloadComplete(api, gid):
|
||||
task_dict[task.listener.mid].start_time = seed_start_time
|
||||
LOGGER.info(f"Seeding started: {download.name} - Gid: {gid}")
|
||||
await update_status_message(task.listener.message.chat.id)
|
||||
else:
|
||||
await sync_to_async(api.remove, [download], force=True, files=True)
|
||||
else:
|
||||
await sync_to_async(api.remove, [download], force=True, files=True)
|
||||
|
||||
|
@ -8,7 +8,6 @@ class DirectListener:
|
||||
def __init__(self, path, listener, a2c_opt):
|
||||
self.listener = listener
|
||||
self._path = path
|
||||
self._is_cancelled = False
|
||||
self._a2c_opt = a2c_opt
|
||||
self._proc_bytes = 0
|
||||
self._failed = 0
|
||||
@ -28,7 +27,7 @@ class DirectListener:
|
||||
def download(self, contents):
|
||||
self.is_downloading = True
|
||||
for content in contents:
|
||||
if self._is_cancelled:
|
||||
if self.listener.is_cancelled:
|
||||
break
|
||||
if content["path"]:
|
||||
self._a2c_opt["dir"] = f"{self._path}/{content['path']}"
|
||||
@ -44,7 +43,7 @@ class DirectListener:
|
||||
continue
|
||||
self.download_task = self.download_task.live
|
||||
while True:
|
||||
if self._is_cancelled:
|
||||
if self.listener.is_cancelled:
|
||||
if self.download_task:
|
||||
self.download_task.remove(True, True)
|
||||
break
|
||||
@ -62,7 +61,7 @@ class DirectListener:
|
||||
break
|
||||
sleep(1)
|
||||
self.download_task = None
|
||||
if self._is_cancelled:
|
||||
if self.listener.is_cancelled:
|
||||
return
|
||||
if self._failed == len(contents):
|
||||
async_to_sync(
|
||||
@ -72,7 +71,7 @@ class DirectListener:
|
||||
async_to_sync(self.listener.onDownloadComplete)
|
||||
|
||||
async def cancel_task(self):
|
||||
self._is_cancelled = True
|
||||
self.listener.is_cancelled = True
|
||||
LOGGER.info(f"Cancelling Download: {self.listener.name}")
|
||||
await self.listener.onDownloadError("Download Cancelled by User!")
|
||||
if self.download_task:
|
||||
|
@ -91,7 +91,7 @@ async def _onDownloadComplete(tor):
|
||||
if Intervals["stopAll"]:
|
||||
return
|
||||
client = await sync_to_async(get_qb_client)
|
||||
if task.listener.seed:
|
||||
if task.listener.seed and not task.is_cancelled:
|
||||
async with task_dict_lock:
|
||||
if task.listener.mid in task_dict:
|
||||
removed = False
|
||||
|
@ -193,9 +193,8 @@ class TaskListener(TaskConfig):
|
||||
async with task_dict_lock:
|
||||
task_dict[self.mid] = QueueStatus(self, gid, "Up")
|
||||
await event.wait()
|
||||
async with task_dict_lock:
|
||||
if self.mid not in task_dict:
|
||||
return
|
||||
if self.is_cancelled:
|
||||
return
|
||||
LOGGER.info(f"Start from Queued/Upload: {self.name}")
|
||||
async with queue_dict_lock:
|
||||
if self.mid in non_queued_dl:
|
||||
|
@ -86,10 +86,9 @@ async def add_aria2c_download(listener, dpath, header, ratio, seed_time):
|
||||
|
||||
if add_to_queue:
|
||||
await event.wait()
|
||||
|
||||
if listener.is_cancelled:
|
||||
return
|
||||
async with task_dict_lock:
|
||||
if listener.mid not in task_dict:
|
||||
return
|
||||
task = task_dict[listener.mid]
|
||||
task.queued = False
|
||||
new_gid = task.gid()
|
||||
|
@ -44,9 +44,8 @@ async def add_direct_download(listener, path):
|
||||
if listener.multi <= 1:
|
||||
await sendStatusMessage(listener.message)
|
||||
await event.wait()
|
||||
async with task_dict_lock:
|
||||
if listener.mid not in task_dict:
|
||||
return
|
||||
if listener.is_cancelled:
|
||||
return
|
||||
else:
|
||||
add_to_queue = False
|
||||
|
||||
|
@ -37,9 +37,8 @@ async def add_gd_download(listener, path):
|
||||
if listener.multi <= 1:
|
||||
await sendStatusMessage(listener.message)
|
||||
await event.wait()
|
||||
async with task_dict_lock:
|
||||
if listener.mid not in task_dict:
|
||||
return
|
||||
if listener.is_cancelled:
|
||||
return
|
||||
else:
|
||||
add_to_queue = False
|
||||
|
||||
|
@ -257,9 +257,8 @@ async def add_jd_download(listener, path):
|
||||
if listener.multi <= 1:
|
||||
await sendStatusMessage(listener.message)
|
||||
await event.wait()
|
||||
async with task_dict_lock:
|
||||
if listener.mid not in task_dict:
|
||||
return
|
||||
if listener.is_cancelled:
|
||||
return
|
||||
else:
|
||||
add_to_queue = False
|
||||
|
||||
|
@ -133,10 +133,9 @@ async def add_qb_torrent(listener, path, ratio, seed_time):
|
||||
|
||||
if add_to_queue:
|
||||
await event.wait()
|
||||
|
||||
if listener.is_cancelled:
|
||||
return
|
||||
async with task_dict_lock:
|
||||
if listener.mid not in task_dict:
|
||||
return
|
||||
task_dict[listener.mid].queued = False
|
||||
|
||||
await sync_to_async(client.torrents_resume, torrent_hashes=ext_hash)
|
||||
|
@ -44,9 +44,7 @@ async def add_rclone_download(listener, path):
|
||||
res1, res2 = await gather(cmd_exec(cmd1), cmd_exec(cmd2))
|
||||
if res1[2] != res2[2] != 0:
|
||||
if res1[2] != -9:
|
||||
err = res1[1] or res2[1]
|
||||
if not err:
|
||||
err = "Use '/shell cat rlog.txt' to see more information"
|
||||
err = res1[1] or res2[1] or "Use '/shell cat rlog.txt' to see more information"
|
||||
msg = f"Error: While getting rclone stat/size. Path: {remote}:{listener.link}. Stderr: {err[:4000]}"
|
||||
await listener.onDownloadError(msg)
|
||||
return
|
||||
@ -84,9 +82,8 @@ async def add_rclone_download(listener, path):
|
||||
if listener.multi <= 1:
|
||||
await sendStatusMessage(listener.message)
|
||||
await event.wait()
|
||||
async with task_dict_lock:
|
||||
if listener.mid not in task_dict:
|
||||
return
|
||||
if listener.is_cancelled:
|
||||
return
|
||||
else:
|
||||
add_to_queue = False
|
||||
|
||||
|
@ -26,7 +26,6 @@ class TelegramDownloadHelper:
|
||||
self._listener = listener
|
||||
self._id = ""
|
||||
self.session = ""
|
||||
self._is_cancelled = False
|
||||
|
||||
@property
|
||||
def speed(self):
|
||||
@ -55,7 +54,7 @@ class TelegramDownloadHelper:
|
||||
LOGGER.info(f"Start Queued Download from Telegram: {self._listener.name}")
|
||||
|
||||
async def _onDownloadProgress(self, current, total):
|
||||
if self._is_cancelled:
|
||||
if self._listener.is_cancelled:
|
||||
if self.session == "user":
|
||||
user.stop_transmission()
|
||||
else:
|
||||
@ -80,7 +79,7 @@ class TelegramDownloadHelper:
|
||||
download = await message.download(
|
||||
file_name=path, progress=self._onDownloadProgress
|
||||
)
|
||||
if self._is_cancelled:
|
||||
if self._listener.is_cancelled:
|
||||
await self._onDownloadError("Cancelled by user!")
|
||||
return
|
||||
except Exception as e:
|
||||
@ -89,7 +88,7 @@ class TelegramDownloadHelper:
|
||||
return
|
||||
if download is not None:
|
||||
await self._onDownloadComplete()
|
||||
elif not self._is_cancelled:
|
||||
elif not self._listener.is_cancelled:
|
||||
await self._onDownloadError("Internal error occurred")
|
||||
|
||||
async def add_download(self, message, path, session):
|
||||
@ -145,9 +144,8 @@ class TelegramDownloadHelper:
|
||||
if self._listener.multi <= 1:
|
||||
await sendStatusMessage(self._listener.message)
|
||||
await event.wait()
|
||||
async with task_dict_lock:
|
||||
if self._listener.mid not in task_dict:
|
||||
return
|
||||
if self._listener.is_cancelled:
|
||||
return
|
||||
else:
|
||||
add_to_queue = False
|
||||
await self._onDownloadStart(gid, add_to_queue)
|
||||
@ -160,7 +158,7 @@ class TelegramDownloadHelper:
|
||||
)
|
||||
|
||||
async def cancel_task(self):
|
||||
self._is_cancelled = True
|
||||
self._listener.is_cancelled = True
|
||||
LOGGER.info(
|
||||
f"Cancelling download on user request: name: {self._listener.name} id: {self._id}"
|
||||
)
|
||||
|
@ -49,7 +49,6 @@ class YoutubeDLHelper:
|
||||
self._eta = "-"
|
||||
self._listener = listener
|
||||
self._gid = ""
|
||||
self._is_cancelled = False
|
||||
self._downloading = False
|
||||
self._ext = ""
|
||||
self.is_playlist = False
|
||||
@ -95,7 +94,7 @@ class YoutubeDLHelper:
|
||||
|
||||
def _onDownloadProgress(self, d):
|
||||
self._downloading = True
|
||||
if self._is_cancelled:
|
||||
if self._listener.is_cancelled:
|
||||
raise ValueError("Cancelling...")
|
||||
if d["status"] == "finished":
|
||||
if self.is_playlist:
|
||||
@ -130,7 +129,7 @@ class YoutubeDLHelper:
|
||||
await sendStatusMessage(self._listener.message)
|
||||
|
||||
def _onDownloadError(self, error):
|
||||
self._is_cancelled = True
|
||||
self._listener.is_cancelled = True
|
||||
async_to_sync(self._listener.onDownloadError, error)
|
||||
|
||||
def extractMetaData(self):
|
||||
@ -174,7 +173,7 @@ class YoutubeDLHelper:
|
||||
try:
|
||||
ydl.download([self._listener.link])
|
||||
except DownloadError as e:
|
||||
if not self._is_cancelled:
|
||||
if not self._listener.is_cancelled:
|
||||
self._onDownloadError(str(e))
|
||||
return
|
||||
if self.is_playlist and (
|
||||
@ -184,7 +183,7 @@ class YoutubeDLHelper:
|
||||
"No video available to download from this playlist. Check logs for more details"
|
||||
)
|
||||
return
|
||||
if self._is_cancelled:
|
||||
if self._listener.is_cancelled:
|
||||
raise ValueError
|
||||
async_to_sync(self._listener.onDownloadComplete)
|
||||
except ValueError:
|
||||
@ -233,7 +232,7 @@ class YoutubeDLHelper:
|
||||
self.opts["format"] = qual
|
||||
|
||||
await sync_to_async(self.extractMetaData)
|
||||
if self._is_cancelled:
|
||||
if self._listener.is_cancelled:
|
||||
return
|
||||
|
||||
base_name, ext = ospath.splitext(self._listener.name)
|
||||
@ -320,9 +319,8 @@ class YoutubeDLHelper:
|
||||
self._listener, self._gid, "dl"
|
||||
)
|
||||
await event.wait()
|
||||
async with task_dict_lock:
|
||||
if self._listener.mid not in task_dict:
|
||||
return
|
||||
if self._listener.is_cancelled:
|
||||
return
|
||||
LOGGER.info(f"Start Queued Download from YT_DLP: {self._listener.name}")
|
||||
await self._onDownloadStart(True)
|
||||
else:
|
||||
@ -337,7 +335,7 @@ class YoutubeDLHelper:
|
||||
await sync_to_async(self._download, path)
|
||||
|
||||
async def cancel_task(self):
|
||||
self._is_cancelled = True
|
||||
self._listener.is_cancelled = True
|
||||
LOGGER.info(f"Cancelling Download: {self._listener.name}")
|
||||
if not self._downloading:
|
||||
await self._listener.onDownloadError("Download Cancelled by User!")
|
||||
|
@ -61,7 +61,7 @@ class gdClone(GoogleDriveHelper):
|
||||
dir_id = self.create_directory(meta.get("name"), self.listener.upDest)
|
||||
self._cloneFolder(meta.get("name"), meta.get("id"), dir_id)
|
||||
durl = self.G_DRIVE_DIR_BASE_DOWNLOAD_URL.format(dir_id)
|
||||
if self.is_cancelled:
|
||||
if self.listener.is_cancelled:
|
||||
LOGGER.info("Deleting cloned data from Drive...")
|
||||
self.service.files().delete(
|
||||
fileId=dir_id, supportsAllDrives=True
|
||||
@ -122,7 +122,7 @@ class gdClone(GoogleDriveHelper):
|
||||
self._copyFile(file.get("id"), dest_id)
|
||||
self.proc_bytes += int(file.get("size", 0))
|
||||
self.total_time = int(time() - self._start_time)
|
||||
if self.is_cancelled:
|
||||
if self.listener.is_cancelled:
|
||||
break
|
||||
|
||||
@retry(
|
||||
@ -156,7 +156,7 @@ class gdClone(GoogleDriveHelper):
|
||||
)
|
||||
raise err
|
||||
else:
|
||||
if self.is_cancelled:
|
||||
if self.listener.is_cancelled:
|
||||
return
|
||||
self.switchServiceAccount()
|
||||
return self._copyFile(file_id, dest_id)
|
||||
|
@ -55,10 +55,10 @@ class gdDownload(GoogleDriveHelper):
|
||||
return self.download()
|
||||
err = "File not found!"
|
||||
async_to_sync(self.listener.onDownloadError, err)
|
||||
self.is_cancelled = True
|
||||
self.listener.is_cancelled = True
|
||||
finally:
|
||||
self._updater.cancel()
|
||||
if self.is_cancelled:
|
||||
if self.listener.is_cancelled:
|
||||
return
|
||||
async_to_sync(self.listener.onDownloadComplete)
|
||||
|
||||
@ -86,7 +86,7 @@ class gdDownload(GoogleDriveHelper):
|
||||
f"{path}{filename}"
|
||||
) and not filename.lower().endswith(tuple(self.listener.extensionFilter)):
|
||||
self._download_file(file_id, path, filename, mime_type)
|
||||
if self.is_cancelled:
|
||||
if self.listener.is_cancelled:
|
||||
break
|
||||
|
||||
@retry(
|
||||
@ -102,14 +102,14 @@ class gdDownload(GoogleDriveHelper):
|
||||
filename = f"{filename[:245]}{ext}"
|
||||
if self.listener.name.endswith(ext):
|
||||
self.listener.name = filename
|
||||
if self.is_cancelled:
|
||||
if self.listener.is_cancelled:
|
||||
return
|
||||
fh = FileIO(f"{path}/{filename}", "wb")
|
||||
downloader = MediaIoBaseDownload(fh, request, chunksize=50 * 1024 * 1024)
|
||||
done = False
|
||||
retries = 0
|
||||
while not done:
|
||||
if self.is_cancelled:
|
||||
if self.listener.is_cancelled:
|
||||
fh.close()
|
||||
break
|
||||
try:
|
||||
@ -134,7 +134,7 @@ class gdDownload(GoogleDriveHelper):
|
||||
)
|
||||
raise err
|
||||
else:
|
||||
if self.is_cancelled:
|
||||
if self.listener.is_cancelled:
|
||||
return
|
||||
self.switchServiceAccount()
|
||||
LOGGER.info(f"Got: {reason}, Trying Again...")
|
||||
|
@ -32,7 +32,6 @@ class GoogleDriveHelper:
|
||||
self.is_uploading = False
|
||||
self.is_downloading = False
|
||||
self.is_cloning = False
|
||||
self.is_cancelled = False
|
||||
self.sa_index = 0
|
||||
self.sa_count = 1
|
||||
self.sa_number = 100
|
||||
@ -237,7 +236,7 @@ class GoogleDriveHelper:
|
||||
"""
|
||||
|
||||
async def cancel_task(self):
|
||||
self.is_cancelled = True
|
||||
self.listener.is_cancelled = True
|
||||
if self.is_downloading:
|
||||
LOGGER.info(f"Cancelling Download: {self.listener.name}")
|
||||
await self.listener.onDownloadError("Download stopped by user!")
|
||||
|
@ -59,7 +59,7 @@ class gdUpload(GoogleDriveHelper):
|
||||
ft_delete,
|
||||
in_dir=False,
|
||||
)
|
||||
if self.is_cancelled:
|
||||
if self.listener.is_cancelled:
|
||||
return
|
||||
if link is None:
|
||||
raise Exception("Upload has been manually cancelled")
|
||||
@ -74,7 +74,7 @@ class gdUpload(GoogleDriveHelper):
|
||||
if result is None:
|
||||
raise Exception("Upload has been manually cancelled!")
|
||||
link = self.G_DRIVE_DIR_BASE_DOWNLOAD_URL.format(dir_id)
|
||||
if self.is_cancelled:
|
||||
if self.listener.is_cancelled:
|
||||
return
|
||||
LOGGER.info(f"Uploaded To G-Drive: {self.listener.name}")
|
||||
except Exception as err:
|
||||
@ -86,7 +86,7 @@ class gdUpload(GoogleDriveHelper):
|
||||
self._is_errored = True
|
||||
finally:
|
||||
self._updater.cancel()
|
||||
if self.is_cancelled and not self._is_errored:
|
||||
if self.listener.is_cancelled and not self._is_errored:
|
||||
if mime_type == "Folder":
|
||||
LOGGER.info("Deleting uploaded data from Drive...")
|
||||
self.service.files().delete(
|
||||
@ -131,7 +131,7 @@ class gdUpload(GoogleDriveHelper):
|
||||
if not self.listener.seed or self.listener.newDir:
|
||||
remove(current_file_name)
|
||||
new_id = "filter"
|
||||
if self.is_cancelled:
|
||||
if self.listener.is_cancelled:
|
||||
break
|
||||
return new_id
|
||||
|
||||
@ -180,7 +180,7 @@ class gdUpload(GoogleDriveHelper):
|
||||
)
|
||||
response = None
|
||||
retries = 0
|
||||
while response is None and not self.is_cancelled:
|
||||
while response is None and not self.listener.is_cancelled:
|
||||
try:
|
||||
self.status, response = drive_file.next_chunk()
|
||||
except HttpError as err:
|
||||
@ -203,7 +203,7 @@ class gdUpload(GoogleDriveHelper):
|
||||
)
|
||||
raise err
|
||||
else:
|
||||
if self.is_cancelled:
|
||||
if self.listener.is_cancelled:
|
||||
return
|
||||
self.switchServiceAccount()
|
||||
LOGGER.info(f"Got: {reason}, Trying Again.")
|
||||
@ -218,7 +218,7 @@ class gdUpload(GoogleDriveHelper):
|
||||
else:
|
||||
LOGGER.error(f"Got: {reason}")
|
||||
raise err
|
||||
if self.is_cancelled:
|
||||
if self.listener.is_cancelled:
|
||||
return
|
||||
if not self.listener.seed or self.listener.newDir or file_path in ft_delete:
|
||||
try:
|
||||
|
@ -28,7 +28,6 @@ class RcloneTransferHelper:
|
||||
self._percentage = "0%"
|
||||
self._speed = "0 B/s"
|
||||
self._size = "0 B"
|
||||
self._is_cancelled = False
|
||||
self._is_download = False
|
||||
self._is_upload = False
|
||||
self._sa_count = 1
|
||||
@ -57,7 +56,7 @@ class RcloneTransferHelper:
|
||||
return self._size
|
||||
|
||||
async def _progress(self):
|
||||
while not (self._proc is None or self._is_cancelled):
|
||||
while not (self._proc is None or self._listener.is_cancelled):
|
||||
try:
|
||||
data = (await self._proc.stdout.readline()).decode()
|
||||
except:
|
||||
@ -115,7 +114,7 @@ class RcloneTransferHelper:
|
||||
self._proc = await create_subprocess_exec(*cmd, stdout=PIPE, stderr=PIPE)
|
||||
_, return_code = await gather(self._progress(), self._proc.wait())
|
||||
|
||||
if self._is_cancelled:
|
||||
if self._listener.is_cancelled:
|
||||
return
|
||||
|
||||
if return_code == 0:
|
||||
@ -137,7 +136,7 @@ class RcloneTransferHelper:
|
||||
if self._sa_count < self._sa_number:
|
||||
remote = self._switchServiceAccount()
|
||||
cmd[6] = f"{remote}:{cmd[6].split(':', 1)[1]}"
|
||||
if self._is_cancelled:
|
||||
if self._listener.is_cancelled:
|
||||
return
|
||||
return await self._start_download(cmd, remote_type)
|
||||
else:
|
||||
@ -233,7 +232,7 @@ class RcloneTransferHelper:
|
||||
self._proc = await create_subprocess_exec(*cmd, stdout=PIPE, stderr=PIPE)
|
||||
_, return_code = await gather(self._progress(), self._proc.wait())
|
||||
|
||||
if self._is_cancelled:
|
||||
if self._listener.is_cancelled:
|
||||
return False
|
||||
|
||||
if return_code == -9:
|
||||
@ -256,7 +255,7 @@ class RcloneTransferHelper:
|
||||
cmd[7] = f"{remote}:{cmd[7].split(':', 1)[1]}"
|
||||
return (
|
||||
False
|
||||
if self._is_cancelled
|
||||
if self._listener.is_cancelled
|
||||
else await self._start_upload(cmd, remote_type)
|
||||
)
|
||||
else:
|
||||
@ -356,7 +355,7 @@ class RcloneTransferHelper:
|
||||
err = "Use '/shell cat rlog.txt' to see more information"
|
||||
LOGGER.error(f"while getting link. Path: {destination} | Stderr: {err}")
|
||||
link = ""
|
||||
if self._is_cancelled:
|
||||
if self._listener.is_cancelled:
|
||||
return
|
||||
LOGGER.info(f"Upload Done. Path: {destination}")
|
||||
if self._listener.seed and not self._listener.newDir:
|
||||
@ -395,7 +394,7 @@ class RcloneTransferHelper:
|
||||
self._proc = await create_subprocess_exec(*cmd, stdout=PIPE, stderr=PIPE)
|
||||
_, return_code = await gather(self._progress(), self._proc.wait())
|
||||
|
||||
if self._is_cancelled:
|
||||
if self._listener.is_cancelled:
|
||||
return None, None
|
||||
|
||||
if return_code == -9:
|
||||
@ -412,7 +411,7 @@ class RcloneTransferHelper:
|
||||
link, destination = await self._get_gdrive_link(
|
||||
config_path, dst_remote, dst_path, mime_type
|
||||
)
|
||||
return (None, None) if self._is_cancelled else (link, destination)
|
||||
return (None, None) if self._listener.is_cancelled else (link, destination)
|
||||
else:
|
||||
if mime_type != "Folder":
|
||||
destination += (
|
||||
@ -422,7 +421,7 @@ class RcloneTransferHelper:
|
||||
cmd = ["rclone", "link", "--config", config_path, destination]
|
||||
res, err, code = await cmd_exec(cmd)
|
||||
|
||||
if self._is_cancelled:
|
||||
if self._listener.is_cancelled:
|
||||
return None, None
|
||||
|
||||
if code == 0:
|
||||
@ -484,7 +483,7 @@ class RcloneTransferHelper:
|
||||
return {opt: config.get(remote, opt) for opt in options}
|
||||
|
||||
async def cancel_task(self):
|
||||
self._is_cancelled = True
|
||||
self._listener.is_cancelled = True
|
||||
if self._proc is not None:
|
||||
try:
|
||||
self._proc.kill()
|
||||
|
@ -90,6 +90,7 @@ class Aria2Status:
|
||||
return self._gid
|
||||
|
||||
async def cancel_task(self):
|
||||
self.listener.is_cancelled = True
|
||||
await sync_to_async(self._update)
|
||||
if self._download.seeder and self.seeding:
|
||||
LOGGER.info(f"Cancelling Seed: {self.name()}")
|
||||
|
@ -102,6 +102,7 @@ class JDownloaderStatus:
|
||||
return self._gid
|
||||
|
||||
async def cancel_task(self):
|
||||
self.listener.cancelled = True
|
||||
LOGGER.info(f"Cancelling Download: {self.name()}")
|
||||
await retry_function(
|
||||
jdownloader.device.downloads.remove_links,
|
||||
|
@ -95,6 +95,7 @@ class QbittorrentStatus:
|
||||
return self._info.hash
|
||||
|
||||
async def cancel_task(self):
|
||||
self.listener.is_cancelled = True
|
||||
await sync_to_async(self._update)
|
||||
await sync_to_async(self.client.torrents_pause, torrent_hashes=self._info.hash)
|
||||
if not self.seeding:
|
||||
|
@ -39,6 +39,7 @@ class QueueStatus:
|
||||
return self
|
||||
|
||||
async def cancel_task(self):
|
||||
self.listener.is_cancelled = True
|
||||
LOGGER.info(f"Cancelling Queue{self._status}: {self.listener.name}")
|
||||
if self._status == "dl":
|
||||
await self.listener.onDownloadError(
|
||||
|
@ -45,7 +45,6 @@ class TgUploader:
|
||||
self._path = path
|
||||
self._start_time = time()
|
||||
self._total_files = 0
|
||||
self._is_cancelled = False
|
||||
self._thumb = self._listener.thumb or f"Thumbnails/{listener.userId}.jpg"
|
||||
self._msgs_dict = {}
|
||||
self._corrupted = 0
|
||||
@ -57,7 +56,7 @@ class TgUploader:
|
||||
self._media_group = False
|
||||
|
||||
async def _upload_progress(self, current, total):
|
||||
if self._is_cancelled:
|
||||
if self._listener.is_cancelled:
|
||||
if self._listener.userTransmission:
|
||||
user.stop_transmission()
|
||||
else:
|
||||
@ -255,7 +254,7 @@ class TgUploader:
|
||||
)
|
||||
self._corrupted += 1
|
||||
continue
|
||||
if self._is_cancelled:
|
||||
if self._listener.is_cancelled:
|
||||
return
|
||||
cap_mono = await self._prepare_file(file_, dirpath, delete_file)
|
||||
if self._last_msg_in_group:
|
||||
@ -273,7 +272,7 @@ class TgUploader:
|
||||
self._last_msg_in_group = False
|
||||
self._last_uploaded = 0
|
||||
await self._upload_file(cap_mono, file_)
|
||||
if self._is_cancelled:
|
||||
if self._listener.is_cancelled:
|
||||
return
|
||||
if not self._is_corrupted and (
|
||||
self._listener.isSuperChat or self._listener.upDest
|
||||
@ -288,12 +287,12 @@ class TgUploader:
|
||||
err = err.last_attempt.exception()
|
||||
LOGGER.error(f"{err}. Path: {self._up_path}")
|
||||
self._corrupted += 1
|
||||
if self._is_cancelled:
|
||||
if self._listener.is_cancelled:
|
||||
return
|
||||
continue
|
||||
finally:
|
||||
if (
|
||||
not self._is_cancelled
|
||||
not self._listener.is_cancelled
|
||||
and await aiopath.exists(self._up_path)
|
||||
and (
|
||||
not self._listener.seed
|
||||
@ -313,7 +312,7 @@ class TgUploader:
|
||||
LOGGER.info(
|
||||
f"While sending media group at the end of task. Error: {e}"
|
||||
)
|
||||
if self._is_cancelled:
|
||||
if self._listener.is_cancelled:
|
||||
return
|
||||
if self._listener.seed and not self._listener.newDir:
|
||||
await clean_unwanted(self._path)
|
||||
@ -365,7 +364,7 @@ class TgUploader:
|
||||
if thumb is None:
|
||||
thumb = await create_thumbnail(self._up_path, None)
|
||||
|
||||
if self._is_cancelled:
|
||||
if self._listener.is_cancelled:
|
||||
return
|
||||
self._sent_msg = await self._sent_msg.reply_document(
|
||||
document=self._up_path,
|
||||
@ -389,7 +388,7 @@ class TgUploader:
|
||||
else:
|
||||
width = 480
|
||||
height = 320
|
||||
if self._is_cancelled:
|
||||
if self._listener.is_cancelled:
|
||||
return
|
||||
self._sent_msg = await self._sent_msg.reply_video(
|
||||
video=self._up_path,
|
||||
@ -406,7 +405,7 @@ class TgUploader:
|
||||
elif is_audio:
|
||||
key = "audios"
|
||||
duration, artist, title = await get_media_info(self._up_path)
|
||||
if self._is_cancelled:
|
||||
if self._listener.is_cancelled:
|
||||
return
|
||||
self._sent_msg = await self._sent_msg.reply_audio(
|
||||
audio=self._up_path,
|
||||
@ -421,7 +420,7 @@ class TgUploader:
|
||||
)
|
||||
else:
|
||||
key = "photos"
|
||||
if self._is_cancelled:
|
||||
if self._listener.is_cancelled:
|
||||
return
|
||||
self._sent_msg = await self._sent_msg.reply_photo(
|
||||
photo=self._up_path,
|
||||
@ -432,7 +431,7 @@ class TgUploader:
|
||||
)
|
||||
|
||||
if (
|
||||
not self._is_cancelled
|
||||
not self._listener.is_cancelled
|
||||
and self._media_group
|
||||
and (self._sent_msg.video or self._sent_msg.document)
|
||||
):
|
||||
@ -486,6 +485,6 @@ class TgUploader:
|
||||
return self._processed_bytes
|
||||
|
||||
async def cancel_task(self):
|
||||
self._is_cancelled = True
|
||||
self._listener.is_cancelled = True
|
||||
LOGGER.info(f"Cancelling Upload: {self._listener.name}")
|
||||
await self._listener.onUploadError("your upload has been stopped!")
|
||||
|
@ -342,9 +342,9 @@ async def update_private_file(_, message, pre_message):
|
||||
await remove(fn)
|
||||
if fn == "accounts":
|
||||
if await aiopath.exists("accounts"):
|
||||
await rmtree("accounts")
|
||||
await rmtree("accounts", ignore_errors=True)
|
||||
if await aiopath.exists("rclone_sa"):
|
||||
await rmtree("rclone_sa")
|
||||
await rmtree("rclone_sa", ignore_errors=True)
|
||||
config_dict["USE_SERVICE_ACCOUNTS"] = False
|
||||
if DATABASE_URL:
|
||||
await DbManager().update_config({"USE_SERVICE_ACCOUNTS": False})
|
||||
@ -358,9 +358,9 @@ async def update_private_file(_, message, pre_message):
|
||||
await message.download(file_name=f"{getcwd()}/{file_name}")
|
||||
if file_name == "accounts.zip":
|
||||
if await aiopath.exists("accounts"):
|
||||
await rmtree("accounts")
|
||||
await rmtree("accounts", ignore_errors=True)
|
||||
if await aiopath.exists("rclone_sa"):
|
||||
await rmtree("rclone_sa")
|
||||
await rmtree("rclone_sa", ignore_errors=True)
|
||||
await (
|
||||
await create_subprocess_exec(
|
||||
"7z", "x", "-o.", "-aoa", "accounts.zip", "accounts/*.json"
|
||||
|
Loading…
Reference in New Issue
Block a user