diff --git a/bot/helper/common.py b/bot/helper/common.py index 00ed4536a629..0f1076b23d5a 100644 --- a/bot/helper/common.py +++ b/bot/helper/common.py @@ -1753,16 +1753,24 @@ async def substitute(self, dl_path): res = substitution[1] else: res = "" - name = sub( - rf"{pattern}", - res, - name, - flags=I - if sen - else 0 - ) + try: + name = sub( + rf"{pattern}", + res, + name, + flags=I + if sen + else 0 + ) + except Exception as e: + LOGGER.error( + f"Substitute Error: pattern: {pattern} res: {res}. Error: {e}" + ) + return dl_path if len(name.encode()) > 255: - LOGGER.error(f"Substitute: {name} is too long") + LOGGER.error( + f"Substitute: {name} is too long" + ) return dl_path new_path = ospath.join( up_dir, @@ -1801,16 +1809,24 @@ async def substitute(self, dl_path): res = substitution[1] else: res = "" - file_ = sub( - rf"{pattern}", - res, - file_, - flags=I - if sen - else 0 - ) + try: + file_ = sub( + rf"{pattern}", + res, + file_, + flags=I + if sen + else 0 + ) + except Exception as e: + LOGGER.error( + f"Substitute Error: pattern: {pattern} res: {res}. Error: {e}" + ) + continue if len(file_.encode()) > 255: - LOGGER.error(f"Substitute: {file_} is too long") + LOGGER.error( + f"Substitute: {file_} is too long" + ) continue await move( f_path, diff --git a/bot/helper/ext_utils/db_handler.py b/bot/helper/ext_utils/db_handler.py index 5bfeb48424e7..804f9206111e 100644 --- a/bot/helper/ext_utils/db_handler.py +++ b/bot/helper/ext_utils/db_handler.py @@ -310,10 +310,12 @@ async def trunc_table(self, name): async def add_download_url(self, url: str, tag: str): if self._return : return + suffix = config_dict["CMD_SUFFIX"] download = { "_id": url, "tag": tag, - "botname": bot_name + "botname": bot_name, + "suffix": suffix } await self._db.download_links.update_one( # type: ignore {"_id": url}, diff --git a/bot/helper/task_utils/download_utils/direct_downloader.py b/bot/helper/task_utils/download_utils/direct_downloader.py index 02fdc93a0ff6..094e69aa6b71 100644 --- a/bot/helper/task_utils/download_utils/direct_downloader.py +++ b/bot/helper/task_utils/download_utils/direct_downloader.py @@ -61,7 +61,10 @@ async def add_direct_download(listener, path): ) return - gid = token_urlsafe(10) + gid = token_urlsafe(10).replace( + "-", + "" + ) ( add_to_queue, event diff --git a/bot/helper/task_utils/download_utils/gd_download.py b/bot/helper/task_utils/download_utils/gd_download.py index 8073b2150b51..225a7e6e6a66 100644 --- a/bot/helper/task_utils/download_utils/gd_download.py +++ b/bot/helper/task_utils/download_utils/gd_download.py @@ -42,7 +42,10 @@ async def add_gd_download(listener, path): return listener.name = listener.name or name - gid = token_urlsafe(12) + gid = token_urlsafe(12).replace( + "-", + "" + ) ( msg, diff --git a/bot/helper/task_utils/download_utils/jd_download.py b/bot/helper/task_utils/download_utils/jd_download.py index a788db4bfa6f..ef5eb3fd092a 100644 --- a/bot/helper/task_utils/download_utils/jd_download.py +++ b/bot/helper/task_utils/download_utils/jd_download.py @@ -194,7 +194,10 @@ async def add_jd_download(listener, path): ]: await jdownloader.device.linkgrabber.remove_links(package_ids=odl_list) - gid = token_urlsafe(12) + gid = token_urlsafe(12).replace( + "-", + "" + ) jd_downloads[gid] = { "status": "collect", "path": path diff --git a/bot/helper/task_utils/download_utils/rclone_download.py b/bot/helper/task_utils/download_utils/rclone_download.py index 8b0836a1d530..b12038f8096c 100644 --- a/bot/helper/task_utils/download_utils/rclone_download.py +++ b/bot/helper/task_utils/download_utils/rclone_download.py @@ -131,7 +131,10 @@ async def add_rclone_download(listener, path): 1 )[-1] listener.size = rsize["bytes"] - gid = token_urlsafe(12) + gid = token_urlsafe(12).replace( + "-", + "" + ) if not rclone_select: ( diff --git a/bot/helper/task_utils/download_utils/telegram_download.py b/bot/helper/task_utils/download_utils/telegram_download.py index e42229147e5f..170a9b06ad57 100644 --- a/bot/helper/task_utils/download_utils/telegram_download.py +++ b/bot/helper/task_utils/download_utils/telegram_download.py @@ -73,10 +73,8 @@ async def _on_download_progress(self, current, total): async def _on_download_error(self, error): async with global_lock: - try: + if self._id in GLOBAL_GID: GLOBAL_GID.remove(self._id) - except: - pass await self._listener.on_download_error(error) async def _on_download_complete(self): @@ -195,6 +193,9 @@ async def add_download(self, message, path, session): await send_status_message(self._listener.message) await event.wait() # type: ignore if self._listener.is_cancelled: + async with global_lock: + if self._id in GLOBAL_GID: + GLOBAL_GID.remove(self._id) return await self._on_download_start(gid, add_to_queue) diff --git a/bot/helper/task_utils/download_utils/yt_dlp_download.py b/bot/helper/task_utils/download_utils/yt_dlp_download.py index 73e29bb14e9f..63f7d11e1e9f 100644 --- a/bot/helper/task_utils/download_utils/yt_dlp_download.py +++ b/bot/helper/task_utils/download_utils/yt_dlp_download.py @@ -259,7 +259,10 @@ async def add_download(self, path, qual, playlist, options): self.opts["ignoreerrors"] = True self.is_playlist = True - self._gid = token_urlsafe(8) + self._gid = token_urlsafe(8).replace( + "-", + "" + ) await self._on_download_start() diff --git a/bot/helper/z_utils.py b/bot/helper/z_utils.py index 07d5dbdaeec8..08a457b5f55c 100644 --- a/bot/helper/z_utils.py +++ b/bot/helper/z_utils.py @@ -92,7 +92,7 @@ async def stop_duplicate_tasks(message, link, file_=None): exist = await database.check_download(raw_url) # type: ignore if exist: _msg = f'Download is already added by {exist["tag"]}\n' - _msg += f'Check the download status in @{exist["botname"]}\n\n' + _msg += f'Check the download status in /status{exist["suffix"]}@{exist["botname"]}\n\n' _msg += f'Link: {exist["_id"]}' reply_message = await send_message( message, diff --git a/bot/modules/clone.py b/bot/modules/clone.py index 3f382203895d..2703e0223be6 100644 --- a/bot/modules/clone.py +++ b/bot/modules/clone.py @@ -273,7 +273,10 @@ async def _proceed_to_clone(self, sync): await delete_links(self.message) else: msg = "" - gid = token_urlsafe(12) + gid = token_urlsafe(12).replace( + "-", + "" + ) async with task_dict_lock: task_dict[self.mid] = GoogleDriveStatus( self, @@ -385,7 +388,10 @@ async def _proceed_to_clone(self, sync): LOGGER.info( f"Clone Started: Name: {self.name} - Source: {self.link} - Destination: {self.up_dest}" ) - gid = token_urlsafe(12) + gid = token_urlsafe(12).replace( + "-", + "" + ) async with task_dict_lock: task_dict[self.mid] = RcloneStatus( self,