diff --git a/bot/helper/ext_utils/fs_utils.py b/bot/helper/ext_utils/fs_utils.py index 961500edecc..1f7b826d56a 100644 --- a/bot/helper/ext_utils/fs_utils.py +++ b/bot/helper/ext_utils/fs_utils.py @@ -57,21 +57,13 @@ def get_path_size(path): def tar(org_path): tar_path = org_path + ".tar" - #path = pathlib.PurePath(org_path) + path = pathlib.PurePath(org_path) LOGGER.info(f'Tar: orig_path: {org_path}, tar_path: {tar_path}') tar = tarfile.open(tar_path, "w") - tar.add(org_path, arcname=os.path.basename(org_path)) + tar.add(org_path, arcname=path.name) tar.close() return tar_path -def zip(name, path): - root_dir = os.path.dirname(path) - base_dir = os.path.basename(path.strip(os.sep)) - zip_file = shutil.make_archive(name, "zip", root_dir, base_dir) - zip_path = shutil.move(zip_file, root_dir) - LOGGER.info(f"Zip: {zip_path}") - return zip_path - def get_base_name(orig_path: str): if orig_path.endswith(".tar.bz2"): return orig_path.replace(".tar.bz2", "") @@ -180,7 +172,7 @@ def split(path, size, file, dirpath, split_size, start_time=0, i=1): base_name, extension = os.path.splitext(file) metadata = extractMetadata(createParser(path)) total_duration = metadata.get('duration').seconds - 8 - split_size = split_size - 2000000 + split_size = split_size - 3000000 while start_time < total_duration: parted_name = "{}.part{}{}".format(str(base_name), str(i).zfill(3), str(extension)) out_path = os.path.join(dirpath, parted_name) @@ -190,7 +182,7 @@ def split(path, size, file, dirpath, split_size, start_time=0, i=1): out_size = get_path_size(out_path) if out_size > TG_SPLIT_SIZE: dif = out_size - TG_SPLIT_SIZE - split_size = TG_SPLIT_SIZE - dif + split_size = split_size - dif + 2000000 os.remove(out_path) return split(path, size, file, dirpath, split_size, start_time, i) metadata = extractMetadata(createParser(out_path)) diff --git a/bot/helper/mirror_utils/upload_utils/pyrogramEngine.py b/bot/helper/mirror_utils/upload_utils/pyrogramEngine.py index 5676109a72c..2cd1016e5b8 100644 --- a/bot/helper/mirror_utils/upload_utils/pyrogramEngine.py +++ b/bot/helper/mirror_utils/upload_utils/pyrogramEngine.py @@ -87,7 +87,6 @@ def upload_file(self, up_path, file, dirpath): supports_streaming=True, disable_notification=True, progress=self.upload_progress) - os.remove(up_path) if self.thumb is None and thumb is not None and os.path.lexists(thumb): os.remove(thumb) elif file.upper().endswith(AUDIO_SUFFIXES): @@ -106,7 +105,6 @@ def upload_file(self, up_path, file, dirpath): thumb=thumb, disable_notification=True, progress=self.upload_progress) - os.remove(up_path) elif file.upper().endswith(IMAGE_SUFFIXES): self.sent_msg = self.sent_msg.reply_photo(photo=up_path, quote=True, @@ -114,12 +112,13 @@ def upload_file(self, up_path, file, dirpath): parse_mode="html", disable_notification=True, progress=self.upload_progress) - os.remove(up_path) else: notMedia = True if self.as_doc or notMedia: if file.upper().endswith(VIDEO_SUFFIXES) and thumb is None: thumb = take_ss(up_path) + if self.is_cancelled: + return self.sent_msg = self.sent_msg.reply_document(document=up_path, quote=True, thumb=thumb, @@ -127,6 +126,9 @@ def upload_file(self, up_path, file, dirpath): parse_mode="html", disable_notification=True, progress=self.upload_progress) + if self.thumb is None and thumb is not None and os.path.lexists(thumb): + os.remove(thumb) + if not self.is_cancelled: os.remove(up_path) except FloodWait as f: LOGGER.info(f) diff --git a/bot/modules/mirror.py b/bot/modules/mirror.py index d11b447b0f4..4ce1a868424 100644 --- a/bot/modules/mirror.py +++ b/bot/modules/mirror.py @@ -83,7 +83,16 @@ def onDownloadComplete(self): try: with download_dict_lock: download_dict[self.uid] = TarStatus(name, m_path, size) - path = fs_utils.zip(name, m_path) if self.isZip else fs_utils.tar(m_path) + if self.isZip: + pswd = self.pswd + path = m_path + ".zip" + LOGGER.info(f'Zip: orig_path: {m_path}, zip_path: {path}') + if pswd is not None: + subprocess.run(["7z", "a", f"-p{pswd}", path, m_path]) + else: + subprocess.run(["7z", "a", path, m_path]) + else: + path = fs_utils.tar(m_path) except FileNotFoundError: LOGGER.info('File to archive not found!') self.onUploadError('Internal error occurred!!')