Improve Leech
Signed-off-by: anas <e.anastayyar@gmail.com>
This commit is contained in:
parent
c4035d4ac5
commit
845a73738a
|
|
@ -156,35 +156,37 @@ def get_mime_type(file_path):
|
|||
mime_type = mime_type or "text/plain"
|
||||
return mime_type
|
||||
|
||||
def take_ss(video_file, duration):
|
||||
def take_ss(video_file):
|
||||
des_dir = 'Thumbnails'
|
||||
if not os.path.exists(des_dir):
|
||||
os.mkdir(des_dir)
|
||||
des_dir = os.path.join(des_dir, f"{time.time()}.jpg")
|
||||
metadata = extractMetadata(createParser(video_file))
|
||||
if metadata.has("duration"):
|
||||
duration = metadata.get('duration').seconds
|
||||
else:
|
||||
duration = 5
|
||||
duration = int(duration) / 2
|
||||
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
|
||||
return None
|
||||
|
||||
Image.open(des_dir).convert("RGB").save(des_dir)
|
||||
img = Image.open(des_dir)
|
||||
w, h = img.size
|
||||
img.resize((320, h))
|
||||
img.resize((480, 320))
|
||||
img.save(des_dir, "JPEG")
|
||||
return des_dir, 320
|
||||
return des_dir
|
||||
|
||||
def split(path, size, split_size, start_time=0, i=1):
|
||||
out_dir = os.path.dirname(path)
|
||||
base_name = os.path.basename(path)
|
||||
if base_name.upper().endswith(VIDEO_SUFFIXES):
|
||||
base_name, extension = os.path.splitext(path)
|
||||
def split(path, size, file, dirpath, split_size, start_time=0, i=1):
|
||||
if file.upper().endswith(VIDEO_SUFFIXES):
|
||||
base_name, extension = os.path.splitext(file)
|
||||
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(3), str(extension))
|
||||
out_path = os.path.join(out_dir, parted_name)
|
||||
out_path = os.path.join(dirpath, 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])
|
||||
|
|
@ -193,11 +195,11 @@ def split(path, size, split_size, start_time=0, i=1):
|
|||
dif = out_size - TG_SPLIT_SIZE
|
||||
split_size = TG_SPLIT_SIZE - dif
|
||||
os.remove(out_path)
|
||||
return split(path, size, split_size, start_time, i)
|
||||
return split(path, size, file, dirpath, split_size, start_time, i)
|
||||
metadata = extractMetadata(createParser(out_path))
|
||||
start_time = start_time + metadata.get('duration').seconds - 5
|
||||
i = i + 1
|
||||
else:
|
||||
out_path = os.path.join(out_dir, base_name + ".")
|
||||
out_path = os.path.join(dirpath, file + ".")
|
||||
subprocess.run(["split", "--numeric-suffixes=1", "--suffix-length=3", f"--bytes={split_size}", path, out_path])
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ from bot.helper.ext_utils.fs_utils import take_ss
|
|||
LOGGER = logging.getLogger(__name__)
|
||||
logging.getLogger("pyrogram").setLevel(logging.WARNING)
|
||||
|
||||
VIDEO_SUFFIXES = ("M4V", "MP4", "MOV", "FLV", "WMV", "3GP", "MPG", "WEBM", "MKV", "AVI")
|
||||
VIDEO_SUFFIXES = ("MKV", "MP4", "MOV", "WMV", "3GP", "MPG", "WEBM", "AVI", "FLV", "M4V")
|
||||
AUDIO_SUFFIXES = ("MP3", "M4A", "M4B", "FLAC", "WAV", "AIF", "OGG", "AAC", "DTS", "MID", "AMR", "MKA")
|
||||
IMAGE_SUFFIXES = ("JPG", "JPX", "PNG", "GIF", "WEBP", "CR2", "TIF", "BMP", "JXR", "PSD", "ICO", "HEIC")
|
||||
|
||||
|
|
@ -48,16 +48,15 @@ class TgUploader:
|
|||
if self.is_cancelled:
|
||||
return
|
||||
up_path = os.path.join(dirpath, file)
|
||||
self.upload_file(up_path, file)
|
||||
self.upload_file(up_path, file, dirpath)
|
||||
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):
|
||||
def upload_file(self, up_path, file, dirpath):
|
||||
cap_mono = f"<code>{file}</code>"
|
||||
notMedia = False
|
||||
thumb = self.thumb
|
||||
|
|
@ -65,26 +64,30 @@ class TgUploader:
|
|||
if not self.as_doc:
|
||||
duration = 0
|
||||
if file.upper().endswith(VIDEO_SUFFIXES):
|
||||
width = 0
|
||||
height = 0
|
||||
metadata = extractMetadata(createParser(up_path))
|
||||
if metadata.has("duration"):
|
||||
duration = metadata.get("duration").seconds
|
||||
if thumb is None:
|
||||
thumb, width = take_ss(up_path, duration)
|
||||
thumb = take_ss(up_path)
|
||||
if self.is_cancelled:
|
||||
return
|
||||
if not file.upper().endswith(("MKV", "MP4")):
|
||||
file = os.path.splitext(file)[0] + '.mp4'
|
||||
new_path = os.path.join(dirpath, file)
|
||||
os.rename(up_path, new_path)
|
||||
up_path = new_path
|
||||
self.sent_msg = self.sent_msg.reply_video(video=up_path,
|
||||
quote=True,
|
||||
caption=cap_mono,
|
||||
parse_mode="html",
|
||||
duration=duration,
|
||||
width=width,
|
||||
height=height,
|
||||
width=480,
|
||||
height=320,
|
||||
thumb=thumb,
|
||||
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):
|
||||
|
|
@ -103,6 +106,7 @@ class TgUploader:
|
|||
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,
|
||||
|
|
@ -110,9 +114,12 @@ class TgUploader:
|
|||
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)
|
||||
self.sent_msg = self.sent_msg.reply_document(document=up_path,
|
||||
quote=True,
|
||||
thumb=thumb,
|
||||
|
|
@ -120,6 +127,7 @@ class TgUploader:
|
|||
parse_mode="html",
|
||||
disable_notification=True,
|
||||
progress=self.upload_progress)
|
||||
os.remove(up_path)
|
||||
except FloodWait as f:
|
||||
LOGGER.info(f)
|
||||
time.sleep(f.x)
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ def leechSet(update, context):
|
|||
msg += "DOCUMENT"
|
||||
else:
|
||||
msg += "MEDIA"
|
||||
msg += "\nCustom Thmubnail "
|
||||
msg += "\nCustom Thumbnail "
|
||||
msg += "exists" if os.path.exists(path) else "not exists"
|
||||
buttons = button_build.ButtonMaker()
|
||||
buttons.sbutton("As Document", f"doc {user_id}")
|
||||
|
|
@ -93,9 +93,8 @@ def setThumb(update, context):
|
|||
des_dir = os.path.join(path, str(user_id) + ".jpg")
|
||||
# Image.open(photo_dir).convert("RGB").save(photo_dir)
|
||||
img = Image.open(photo_dir)
|
||||
w, h = img.size
|
||||
img.thumbnail((320, h))
|
||||
# img.resize((320, h))
|
||||
img.thumbnail((480, 320))
|
||||
# img.resize((480, 320))
|
||||
img.save(des_dir, "JPEG")
|
||||
os.remove(photo_dir)
|
||||
sendMessage(f"Custom thumbnail saved for {user_id} user.", context.bot, update)
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ from fnmatch import fnmatch
|
|||
from bot import Interval, INDEX_URL, BUTTON_FOUR_NAME, BUTTON_FOUR_URL, BUTTON_FIVE_NAME, BUTTON_FIVE_URL, \
|
||||
BUTTON_SIX_NAME, BUTTON_SIX_URL, BLOCK_MEGA_FOLDER, BLOCK_MEGA_LINKS, VIEW_LINK, aria2, \
|
||||
dispatcher, DOWNLOAD_DIR, download_dict, download_dict_lock, SHORTENER, SHORTENER_API, \
|
||||
TAR_UNZIP_LIMIT, TG_SPLIT_SIZE, OWNER_ID
|
||||
TAR_UNZIP_LIMIT, TG_SPLIT_SIZE
|
||||
from bot.helper.ext_utils import fs_utils, bot_utils
|
||||
from bot.helper.ext_utils.shortenurl import short_url
|
||||
from bot.helper.ext_utils.exceptions import DirectDownloadLinkException, NotSupportedExtractionArchive
|
||||
|
|
@ -150,7 +150,7 @@ class MirrorListener(listeners.MirrorListeners):
|
|||
with download_dict_lock:
|
||||
download_dict[self.uid] = SplitStatus(up_name, up_path, size)
|
||||
LOGGER.info(f"Splitting: {up_name}")
|
||||
fs_utils.split(f_path, f_size, TG_SPLIT_SIZE)
|
||||
fs_utils.split(f_path, f_size, file, dirpath, TG_SPLIT_SIZE)
|
||||
os.remove(f_path)
|
||||
LOGGER.info(f"Leech Name: {up_name}")
|
||||
tg = pyrogramEngine.TgUploader(up_name, self)
|
||||
|
|
@ -202,14 +202,13 @@ class MirrorListener(listeners.MirrorListeners):
|
|||
uname = f"@{self.message.from_user.username}"
|
||||
else:
|
||||
uname = f'<a href="tg://user?id={self.message.from_user.id}">{self.message.from_user.first_name}</a>'
|
||||
chat_id = str(self.message.chat.id)
|
||||
count = len(files)
|
||||
if OWNER_ID == int(chat_id) and count != 1:
|
||||
if self.message.chat.type == 'private':
|
||||
msg = f'<b>Name:</b> <code>{link}</code>\n'
|
||||
msg += f'<b>Total Files:</b> {count}'
|
||||
sendMessage(msg, self.bot, self.update)
|
||||
else:
|
||||
chat_id = chat_id[4:]
|
||||
chat_id = str(self.message.chat.id)[4:]
|
||||
msg = f"<b>Name:</b> <a href='https://t.me/c/{chat_id}/{self.uid}'>{link}</a>\n"
|
||||
msg += f'<b>Total Files:</b> {count}\n'
|
||||
msg += f'cc: {uname}\n\n'
|
||||
|
|
|
|||
Loading…
Reference in New Issue