Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
-Fix split
-Fix zip
-Fix cancel leech upload
-Add zip by pswd: /zipcmd <link> pswd: slam

Signed-off-by: anas <[email protected]>
  • Loading branch information
anasty17 committed Sep 24, 2021
1 parent 8a3d049 commit d384ccb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
16 changes: 4 additions & 12 deletions bot/helper/ext_utils/fs_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", "")
Expand Down Expand Up @@ -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)
Expand All @@ -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))
Expand Down
8 changes: 5 additions & 3 deletions bot/helper/mirror_utils/upload_utils/pyrogramEngine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -106,27 +105,30 @@ 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,
caption=cap_mono,
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,
caption=cap_mono,
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)
Expand Down
11 changes: 10 additions & 1 deletion bot/modules/mirror.py
Original file line number Diff line number Diff line change
Expand Up @@ -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!!')
Expand Down

0 comments on commit d384ccb

Please sign in to comment.