Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
-Fix cancel leech
-Fix wrong video height on telegram desktop
-Mono caption
-Improve splitting

Signed-off-by: anas <[email protected]>
  • Loading branch information
anasty17 committed Sep 22, 2021
1 parent 3f1b109 commit deb90cc
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 29 deletions.
19 changes: 8 additions & 11 deletions bot/helper/ext_utils/fs_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,12 @@
from PIL import Image
from hachoir.parser import createParser
from hachoir.metadata import extractMetadata
from fsplit.filesplit import Filesplit

from .exceptions import NotSupportedExtractionArchive
from bot import aria2, LOGGER, DOWNLOAD_DIR, get_client, TG_SPLIT_SIZE

VIDEO_SUFFIXES = ("M4V", "MP4", "MOV", "FLV", "WMV", "3GP", "MPG", "WEBM", "MKV", "AVI")

fs = Filesplit()

def clean_download(path: str):
if os.path.exists(path):
LOGGER.info(f"Cleaning Download: {path}")
Expand Down Expand Up @@ -168,14 +165,14 @@ def take_ss(video_file, duration):
subprocess.run(["ffmpeg", "-hide_banner", "-loglevel", "error", "-ss", str(duration),
"-i", video_file, "-vframes", "1", des_dir])
if not os.path.lexists(des_dir):
return None, 0, 0
return None, 0

Image.open(des_dir).convert("RGB").save(des_dir)
img = Image.open(des_dir)
w, h = img.size
img.resize((320, h))
img.save(des_dir, "JPEG")
return des_dir, 320, h
return des_dir, 320

def split(path, size, split_size, start_time=0, i=1):
out_dir = os.path.dirname(path)
Expand All @@ -184,23 +181,23 @@ def split(path, size, split_size, start_time=0, i=1):
base_name, extension = os.path.splitext(path)
metadata = extractMetadata(createParser(path))
total_duration = metadata.get('duration').seconds - 8
split_size = split_size - 2000000
while start_time < total_duration:
parted_name = "{}.part{}{}".format(str(base_name), str(i).zfill(2), str(extension))
parted_name = "{}.part{}{}".format(str(base_name), str(i).zfill(3), str(extension))
out_path = os.path.join(out_dir, parted_name)
subprocess.run(["ffmpeg", "-hide_banner", "-loglevel", "error", "-i",
path, "-ss", str(start_time), "-fs", str(split_size),
"-strict", "-2", "-c", "copy", out_path])
out_size = get_path_size(out_path)
if out_size > TG_SPLIT_SIZE:
dif = out_size - TG_SPLIT_SIZE
split_size = split_size - dif
split_size = TG_SPLIT_SIZE - dif
os.remove(out_path)
return split(path, size, split_size, start_time, i)
metadata = extractMetadata(createParser(out_path))
start_time = start_time + metadata.get('duration').seconds - 5
i = i + 1
else:
#subprocess.run(["split", "--numeric-suffixes=1", "--suffix-length=5", f"--bytes={split_size}", path, out_dir])
fs.split(file=path, split_size=split_size, output_dir=out_dir)
csv_path = os.path.join(out_dir, "fs_manifest.csv")
os.remove(csv_path)
out_path = os.path.join(out_dir, base_name + ".")
subprocess.run(["split", "--numeric-suffixes=1", "--suffix-length=3", f"--bytes={split_size}", path, out_path])

9 changes: 3 additions & 6 deletions bot/helper/mirror_utils/download_utils/qbit_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,9 @@ def add_torrent(self, link, dire, listener, qbitsel):
self.ext_hash = get_hash_magnet(link)
tor_info = self.client.torrents_info(torrent_hashes=self.ext_hash)
if len(tor_info) > 0:
if tor_info[0].state == "pausedDL":
self.client.torrents_delete(torrent_hashes=self.ext_hash)
else:
sendMessage("This Torrent is already in list.", listener.bot, listener.update)
self.client.auth_log_out()
return
sendMessage("This Torrent is already in list.", listener.bot, listener.update)
self.client.auth_log_out()
return
if is_file:
op = self.client.torrents_add(torrent_files=[link], save_path=dire)
os.remove(link)
Expand Down
21 changes: 12 additions & 9 deletions bot/helper/mirror_utils/upload_utils/pyrogramEngine.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,20 @@ def upload(self):
self.user_settings()
for dirpath, subdir, files in sorted(os.walk(path)):
for file in sorted(files):
if self.is_cancelled:
return
up_path = os.path.join(dirpath, file)
self.upload_file(up_path, file)
if self.is_cancelled:
return
msgs_dict[file] = self.sent_msg.message_id
os.remove(up_path)
self.last_uploaded = 0
LOGGER.info(f"Leech Done: {self.name}")
self.__listener.onUploadComplete(self.name, None, msgs_dict, None, None)

def upload_file(self, up_path, file):
cap_mono = f"<code>{file}</code>"
notMedia = False
thumb = self.thumb
try:
Expand All @@ -66,11 +71,12 @@ def upload_file(self, up_path, file):
if metadata.has("duration"):
duration = metadata.get("duration").seconds
if thumb is None:
thumb, width, height = take_ss(up_path, duration)
thumb, width = take_ss(up_path, duration)
if self.is_cancelled:
return
self.sent_msg = self.sent_msg.reply_video(video=up_path,
quote=True,
caption=file,
parse_mode="html",
caption=cap_mono,
duration=duration,
width=width,
height=height,
Expand All @@ -88,8 +94,7 @@ def upload_file(self, up_path, file):
artist = metadata.get("artist") if metadata.has("artist") else None
self.sent_msg = self.sent_msg.reply_audio(audio=up_path,
quote=True,
caption=file,
parse_mode="html",
caption=cap_mono,
duration=duration,
performer=artist,
title=title,
Expand All @@ -99,8 +104,7 @@ def upload_file(self, up_path, file):
elif file.upper().endswith(IMAGE_SUFFIXES):
self.sent_msg = self.sent_msg.reply_photo(photo=up_path,
quote=True,
caption=file,
parse_mode="html",
caption=cap_mono,
supports_streaming=True,
disable_notification=True,
progress=self.upload_progress)
Expand All @@ -110,8 +114,7 @@ def upload_file(self, up_path, file):
self.sent_msg = self.sent_msg.reply_document(document=up_path,
quote=True,
thumb=thumb,
caption=file,
parse_mode="html",
caption=cap_mono,
disable_notification=True,
progress=self.upload_progress)
except FloodWait as f:
Expand Down
2 changes: 1 addition & 1 deletion bot/modules/mirror.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def onUploadComplete(self, link: str, size, files, folders, typ):
chat_id = str(self.message.chat.id)
count = len(files)
if OWNER_ID == int(chat_id):
msg = f'<b>Name:</b> {link}\n'
msg = f'<b>Name:</b> <code>{link}</code>\n'
msg += f'<b>Total Files:</b> {count}'
sendMessage(msg, self.bot, self.update)
else:
Expand Down
3 changes: 1 addition & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ attrdict
beautifulsoup4
cloudscrape
feedparser
filesplit
google-api-python-client
google-auth-httplib2
google-auth-oauthlib
Expand All @@ -15,7 +14,7 @@ hachoir
js2py
lk21
lxml
Pillow
pillow
psutil
psycopg2-binary
pybase64
Expand Down

0 comments on commit deb90cc

Please sign in to comment.