parent
bebd49be1e
commit
11c3e5a711
|
|
@ -208,7 +208,6 @@ try:
|
|||
STATUS_LIMIT = int(STATUS_LIMIT)
|
||||
except KeyError:
|
||||
STATUS_LIMIT = None
|
||||
|
||||
try:
|
||||
MEGA_API_KEY = getConfig('MEGA_API_KEY')
|
||||
except KeyError:
|
||||
|
|
|
|||
|
|
@ -163,27 +163,24 @@ def take_ss(video_file, duration):
|
|||
des_dir = f"Thumbnails"
|
||||
if not os.path.exists(des_dir):
|
||||
os.mkdir(des_dir)
|
||||
des_dir = os.path.join(des_dir, f"{time.time()}.jpg")
|
||||
des_dir = os.path.join(des_dir, f"{round(time.time())}.jpg")
|
||||
duration = int(duration) / 2
|
||||
subprocess.run(["ffmpeg", "-hide_banner", "-loglevel", "error", "-ss", str(duration),
|
||||
"-i", video_file, "-vframes", "1", des_dir])
|
||||
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")
|
||||
if os.path.lexists(des_dir):
|
||||
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
|
||||
else:
|
||||
return None, 0, 0
|
||||
|
||||
def split(path, size, split_size, start_time=0, i=1):
|
||||
ftype = get_mime_type(path)
|
||||
ftype = ftype.split("/")[0]
|
||||
ftype = ftype.lower().strip()
|
||||
out_dir = os.path.dirname(path)
|
||||
base_name = os.path.basename(path)
|
||||
if ftype == "video" or base_name.upper().endswith(VIDEO_SUFFIXES):
|
||||
if base_name.upper().endswith(VIDEO_SUFFIXES):
|
||||
base_name, extension = os.path.splitext(path)
|
||||
metadata = extractMetadata(createParser(path))
|
||||
total_duration = metadata.get('duration').seconds - 5
|
||||
|
|
|
|||
|
|
@ -11,13 +11,13 @@ from hachoir.parser import createParser
|
|||
from hachoir.metadata import extractMetadata
|
||||
|
||||
from bot import app, DOWNLOAD_DIR, AS_DOCUMENT, AS_DOC_USERS, AS_MEDIA_USERS
|
||||
from bot.helper.ext_utils.fs_utils import get_mime_type, take_ss
|
||||
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")
|
||||
AUDIO_SUFFIXES = ("MP3", "M4A", "M4B", "FLAC", "WAV", "AIF", "OGG", "AAC", "DTS", "MID", "AMR")
|
||||
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")
|
||||
|
||||
|
||||
|
|
@ -58,11 +58,8 @@ class TgUploader:
|
|||
thumb = self.thumb
|
||||
try:
|
||||
if not self.as_doc:
|
||||
ftype = get_mime_type(up_path)
|
||||
ftype = ftype.split("/")[0]
|
||||
ftype = ftype.lower().strip()
|
||||
duration = 0
|
||||
if ftype == "video" or file.upper().endswith(VIDEO_SUFFIXES):
|
||||
if file.upper().endswith(VIDEO_SUFFIXES):
|
||||
width = 0
|
||||
height = 0
|
||||
metadata = extractMetadata(createParser(up_path))
|
||||
|
|
@ -81,9 +78,9 @@ class TgUploader:
|
|||
supports_streaming=True,
|
||||
disable_notification=True,
|
||||
progress=self.upload_progress)
|
||||
if self.thumb is None:
|
||||
if self.thumb is None and thumb is not None and os.path.lexists(thumb):
|
||||
os.remove(thumb)
|
||||
elif ftype == "audio" or file.upper().endswith(AUDIO_SUFFIXES):
|
||||
elif file.upper().endswith(AUDIO_SUFFIXES):
|
||||
title = None
|
||||
artist = None
|
||||
metadata = extractMetadata(createParser(up_path))
|
||||
|
|
@ -103,7 +100,7 @@ class TgUploader:
|
|||
thumb=thumb,
|
||||
disable_notification=True,
|
||||
progress=self.upload_progress)
|
||||
elif ftype == "image" or file.upper().endswith(IMAGE_SUFFIXES):
|
||||
elif file.upper().endswith(IMAGE_SUFFIXES):
|
||||
self.sent_msg = self.sent_msg.reply_photo(photo=up_path,
|
||||
quote=True,
|
||||
caption=file,
|
||||
|
|
|
|||
|
|
@ -53,35 +53,27 @@ def setLeechType(update, context):
|
|||
elif data[0] == "doc":
|
||||
if user_id in AS_DOC_USERS:
|
||||
query.answer(text="Already As Document!", show_alert=True)
|
||||
query.message.delete()
|
||||
elif user_id in AS_MEDIA_USERS:
|
||||
AS_MEDIA_USERS.remove(user_id)
|
||||
AS_DOC_USERS.add(user_id)
|
||||
query.answer(text="Done!", show_alert=True)
|
||||
query.message.delete()
|
||||
elif AS_DOCUMENT:
|
||||
query.answer(text="Already As Document!", show_alert=True)
|
||||
query.message.delete()
|
||||
elif not AS_DOCUMENT:
|
||||
AS_DOC_USERS.add(user_id)
|
||||
query.answer(text="Done!", show_alert=True)
|
||||
query.message.delete()
|
||||
elif data[0] == "med":
|
||||
if user_id in AS_DOC_USERS:
|
||||
AS_DOC_USERS.remove(user_id)
|
||||
AS_MEDIA_USERS.add(user_id)
|
||||
query.answer(text="Done!", show_alert=True)
|
||||
query.message.delete()
|
||||
elif user_id in AS_MEDIA_USERS:
|
||||
query.answer(text="Already As Media!", show_alert=True)
|
||||
query.message.delete()
|
||||
elif AS_DOCUMENT:
|
||||
AS_MEDIA_USERS.add(user_id)
|
||||
query.answer(text="Done!", show_alert=True)
|
||||
query.message.delete()
|
||||
elif not AS_DOCUMENT:
|
||||
query.answer(text="Already As Media!", show_alert=True)
|
||||
query.message.delete()
|
||||
elif data[0] == "thumb":
|
||||
path = f"Thumbnails/{user_id}.jpg"
|
||||
if os.path.lexists(path):
|
||||
|
|
@ -89,14 +81,13 @@ def setLeechType(update, context):
|
|||
query.answer(text="Done!", show_alert=True)
|
||||
else:
|
||||
query.answer(text="No Thumbnail To Delete!", show_alert=True)
|
||||
query.message.delete()
|
||||
elif data[0] == "closeset":
|
||||
query.message.delete()
|
||||
|
||||
def setThumb(update, context):
|
||||
user_id = update.message.from_user.id
|
||||
reply_to = update.message.reply_to_message
|
||||
if reply_to.photo:
|
||||
if reply_to is not None and reply_to.photo:
|
||||
path = "Thumbnails"
|
||||
if not os.path.exists(path):
|
||||
os.mkdir(path)
|
||||
|
|
|
|||
Loading…
Reference in New Issue