-Fix cancel leech
-Fix wrong video height on telegram desktop
-Mono caption
-Improve splitting

Signed-off-by: anas <e.anastayyar@gmail.com>
This commit is contained in:
anas 2021-09-22 21:51:42 +03:00
parent 3f1b109801
commit deb90cc325
5 changed files with 25 additions and 29 deletions

View File

@ -10,15 +10,12 @@ import time
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}")
@ -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)
@ -184,8 +181,9 @@ 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),
@ -193,14 +191,13 @@ def split(path, size, 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 = 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])

View File

@ -53,12 +53,9 @@ class QbitTorrent:
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)

View File

@ -45,8 +45,12 @@ class TgUploader:
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
@ -54,6 +58,7 @@ class TgUploader:
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:
@ -66,11 +71,12 @@ class TgUploader:
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,
@ -88,8 +94,7 @@ class TgUploader:
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,
@ -99,8 +104,7 @@ class TgUploader:
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)
@ -110,8 +114,7 @@ class TgUploader:
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:

View File

@ -205,7 +205,7 @@ class MirrorListener(listeners.MirrorListeners):
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:

View File

@ -6,7 +6,6 @@ attrdict
beautifulsoup4
cloudscrape
feedparser
filesplit
google-api-python-client
google-auth-httplib2
google-auth-oauthlib
@ -15,7 +14,7 @@ hachoir
js2py
lk21
lxml
Pillow
pillow
psutil
psycopg2-binary
pybase64