From 10a4975ca142a5bbbb818189fd762257e6d2712e Mon Sep 17 00:00:00 2001 From: Levi <57452819+l3v11@users.noreply.github.com> Date: Sun, 12 Jun 2022 20:15:48 +0600 Subject: [PATCH] Add support for extracting files in .7z format from folder --- bot/modules/compress.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bot/modules/compress.py b/bot/modules/compress.py index 7b582bf0..3aaf0589 100644 --- a/bot/modules/compress.py +++ b/bot/modules/compress.py @@ -75,7 +75,7 @@ def onDownloadComplete(self): if os.path.isdir(m_path): for dirpath, subdir, files in os.walk(m_path, topdown=False): for file_ in files: - if file_.endswith(".zip") or re.search(r'\.part0*1\.rar$|\.7z\.0*1$|\.zip\.0*1$', file_) \ + if file_.endswith((".zip", ".7z")) or re.search(r'\.part0*1\.rar$|\.7z\.0*1$|\.zip\.0*1$', file_) \ or (file_.endswith(".rar") and not re.search(r'\.part\d+\.rar$', file_)): m_path = os.path.join(dirpath, file_) if self.pswd is not None: @@ -85,7 +85,7 @@ def onDownloadComplete(self): if result.returncode != 0: LOGGER.error("Failed to extract the archive") for file_ in files: - if file_.endswith((".rar", ".zip")) or re.search(r'\.r\d+$|\.7z\.\d+$|\.z\d+$|\.zip\.\d+$', file_): + if file_.endswith((".rar", ".zip", ".7z")) or re.search(r'\.r\d+$|\.7z\.\d+$|\.z\d+$|\.zip\.\d+$', file_): del_path = os.path.join(dirpath, file_) os.remove(del_path) path = f'{DOWNLOAD_DIR}{self.uid}/{name}' @@ -99,8 +99,8 @@ def onDownloadComplete(self): else: LOGGER.error("Failed to extract the archive") path = f'{DOWNLOAD_DIR}{self.uid}/{name}' - except CompressExceptionHandler: - LOGGER.info("Not a valid archive") + except CompressExceptionHandler as err: + LOGGER.info(err) path = f'{DOWNLOAD_DIR}{self.uid}/{name}' else: path = f'{DOWNLOAD_DIR}{self.uid}/{name}'