Skip to content

Commit

Permalink
Some Fixes
Browse files Browse the repository at this point in the history
Signed-off-by: anas <[email protected]>
  • Loading branch information
anasty17 committed Sep 22, 2021
1 parent bebd49b commit 11c3e5a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 30 deletions.
1 change: 0 additions & 1 deletion bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ def get_client() -> qba.TorrentsAPIMixIn:
STATUS_LIMIT = int(STATUS_LIMIT)
except KeyError:
STATUS_LIMIT = None

try:
MEGA_API_KEY = getConfig('MEGA_API_KEY')
except KeyError:
Expand Down
17 changes: 7 additions & 10 deletions bot/helper/ext_utils/fs_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 6 additions & 9 deletions bot/helper/mirror_utils/upload_utils/pyrogramEngine.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
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")


Expand Down Expand Up @@ -58,11 +58,8 @@ def upload_file(self, up_path, file):
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))
Expand All @@ -81,9 +78,9 @@ def upload_file(self, up_path, file):
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))
Expand All @@ -103,7 +100,7 @@ def upload_file(self, up_path, file):
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,
Expand Down
11 changes: 1 addition & 10 deletions bot/modules/leech_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,50 +53,41 @@ 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):
os.remove(path)
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)
Expand Down

0 comments on commit 11c3e5a

Please sign in to comment.