Skip to content

Commit

Permalink
Minor fixes in leech
Browse files Browse the repository at this point in the history
Signed-off-by: anasty17 <[email protected]>
  • Loading branch information
anasty17 committed Dec 14, 2021
1 parent 6afbd7d commit 849c16c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
15 changes: 14 additions & 1 deletion bot/helper/ext_utils/fs_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ def take_ss(video_file):

if not os.path.lexists(des_dir):
return None

Image.open(des_dir).convert("RGB").save(des_dir, "JPEG")
return des_dir

Expand Down Expand Up @@ -202,6 +201,7 @@ def get_media_info(path):
"json", "-show_format", path]).decode('utf-8')
fields = json.loads(result)['format']
except Exception as e:
LOGGER.error(f"get_media_info: {e}")
return 0, None, None
try:
duration = round(float(fields['duration']))
Expand All @@ -217,3 +217,16 @@ def get_media_info(path):
title = None
return duration, artist, title

def get_video_resolution(path):
try:
result = subprocess.check_output(["ffprobe", "-hide_banner", "-loglevel", "error", "-select_streams", "v:0",
"-show_entries", "stream=width,height", "-of", "json", path]).decode('utf-8')
fields = json.loads(result)['streams'][0]

width = int(fields['width'])
height = int(fields['height'])
return width, height
except Exception as e:
LOGGER.error(f"get_video_resolution: {e}")
return 480, 320

17 changes: 12 additions & 5 deletions bot/helper/mirror_utils/upload_utils/pyrogramEngine.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from PIL import Image

from bot import app, DOWNLOAD_DIR, AS_DOCUMENT, AS_DOC_USERS, AS_MEDIA_USERS, CUSTOM_FILENAME
from bot.helper.ext_utils.fs_utils import take_ss, get_media_info
from bot.helper.ext_utils.fs_utils import take_ss, get_media_info, get_video_resolution

LOGGER = logging.getLogger(__name__)
logging.getLogger("pyrogram").setLevel(logging.ERROR)
Expand Down Expand Up @@ -50,7 +50,7 @@ def upload(self):
up_path = os.path.join(dirpath, filee)
fsize = os.path.getsize(up_path)
if fsize == 0:
LOGGER.error(f"{up_path} size is zero, telegram don't upload this file")
LOGGER.error(f"{up_path} size is zero, telegram don't upload zero size files")
self.corrupted += 1
continue
self.upload_file(up_path, filee, dirpath)
Expand All @@ -59,7 +59,9 @@ def upload(self):
self.msgs_dict[filee] = self.sent_msg.message_id
self.last_uploaded = 0
time.sleep(1.5)
LOGGER.info(f"Leech Done: {self.name}")
if len(self.msgs_dict) <= self.corrupted:
return self.__listener.onUploadError('Files Corrupted. Check logs')
LOGGER.info(f"Leech Completed: {self.name}")
self.__listener.onUploadComplete(self.name, None, self.msgs_dict, None, self.corrupted)

def upload_file(self, up_path, filee, dirpath):
Expand All @@ -84,8 +86,11 @@ def upload_file(self, up_path, filee, dirpath):
if self.thumb is None and thumb is not None and os.path.lexists(thumb):
os.remove(thumb)
return
img = Image.open(thumb)
width, height = img.size
if thumb is not None:
img = Image.open(thumb)
width, height = img.size
else:
width, height = get_video_resolution(up_path)
if not filee.upper().endswith(("MKV", "MP4")):
filee = os.path.splitext(filee)[0] + '.mp4'
new_path = os.path.join(dirpath, filee)
Expand Down Expand Up @@ -142,8 +147,10 @@ def upload_file(self, up_path, filee, dirpath):
time.sleep(f.x * 1.5)
except RPCError as e:
LOGGER.error(f"RPCError: {e} File: {up_path}")
self.corrupted += 1
except Exception as err:
LOGGER.error(f"{err} File: {up_path}")
self.corrupted += 1
if self.thumb is None and thumb is not None and os.path.lexists(thumb):
os.remove(thumb)
if not self.is_cancelled:
Expand Down

0 comments on commit 849c16c

Please sign in to comment.