mirror of
https://github.com/anasty17/mirror-leech-telegram-bot.git
synced 2025-01-08 12:07:33 +08:00
Fix stuck getting screenshot on some arch using ffmpeg
fix screenshots number Signed-off-by: anasty17 <e.anastayyar@gmail.com>
This commit is contained in:
parent
9b671f7f51
commit
eeb5bf2c85
@ -2,7 +2,7 @@ from os import path as ospath, cpu_count
|
||||
from aiofiles.os import remove, path as aiopath, makedirs
|
||||
from time import time
|
||||
from re import search as re_search
|
||||
from asyncio import create_subprocess_exec, gather
|
||||
from asyncio import create_subprocess_exec, gather, wait_for
|
||||
from asyncio.subprocess import PIPE
|
||||
from PIL import Image
|
||||
from aioshutil import move
|
||||
@ -153,21 +153,40 @@ async def take_ss(video_file, ss_nb) -> list:
|
||||
name, _ = ospath.splitext(name)
|
||||
dirpath = f"{dirpath}/screenshots/"
|
||||
await makedirs(dirpath, exist_ok=True)
|
||||
interval = duration // ss_nb + 1
|
||||
interval = duration // (ss_nb + 1)
|
||||
cap_time = interval
|
||||
outputs = []
|
||||
cmd = ""
|
||||
cmds = []
|
||||
for i in range(ss_nb):
|
||||
output = f"{dirpath}SS.{name}_{i:02}.png"
|
||||
outputs.append(output)
|
||||
cmd += f'ffmpeg -hide_banner -loglevel error -ss {cap_time} -i "{video_file}" -q:v 1 -frames:v 1 "{output}"'
|
||||
cmd = [
|
||||
"ffmpeg",
|
||||
"-hide_banner",
|
||||
"-loglevel",
|
||||
"error",
|
||||
"-ss",
|
||||
f"{cap_time}",
|
||||
"-i",
|
||||
video_file,
|
||||
"-q:v",
|
||||
"1",
|
||||
"-frames:v",
|
||||
"1",
|
||||
output,
|
||||
]
|
||||
cap_time += interval
|
||||
if i + 1 != ss_nb:
|
||||
cmd += " && "
|
||||
_, err, code = await cmd_exec(cmd, True)
|
||||
if code != 0:
|
||||
cmds.append(cmd_exec(cmd))
|
||||
try:
|
||||
resutls = await wait_for(gather(*cmds), timeout=15)
|
||||
if resutls[0][2] != 0:
|
||||
LOGGER.error(
|
||||
f"Error while creating sreenshots from video. Path: {video_file}. stderr: {resutls[0][1]}"
|
||||
)
|
||||
return []
|
||||
except:
|
||||
LOGGER.error(
|
||||
f"Error while creating sreenshots from video. Path: {video_file} stderr: {err}"
|
||||
f"Error while creating sreenshots from video. Path: {video_file}. Error: Timeout some issues with ffmpeg with specific arch!"
|
||||
)
|
||||
return []
|
||||
return outputs
|
||||
@ -216,7 +235,7 @@ async def create_thumbnail(video_file, duration):
|
||||
"-loglevel",
|
||||
"error",
|
||||
"-ss",
|
||||
str(duration),
|
||||
f"{duration}",
|
||||
"-i",
|
||||
video_file,
|
||||
"-vf",
|
||||
@ -225,10 +244,16 @@ async def create_thumbnail(video_file, duration):
|
||||
"1",
|
||||
des_dir,
|
||||
]
|
||||
_, err, code = await cmd_exec(cmd)
|
||||
if code != 0 or not await aiopath.exists(des_dir):
|
||||
try:
|
||||
_, err, code = await wait_for(cmd_exec(cmd), timeout=15)
|
||||
if code != 0 or not await aiopath.exists(des_dir):
|
||||
LOGGER.error(
|
||||
f"Error while extracting thumbnail from video. Name: {video_file} stderr: {err}"
|
||||
)
|
||||
return None
|
||||
except:
|
||||
LOGGER.error(
|
||||
f"Error while extracting thumbnail from video. Name: {video_file} stderr: {err}"
|
||||
f"Error while extracting thumbnail from video. Name: {video_file}. Error: Timeout some issues with ffmpeg with specific arch!"
|
||||
)
|
||||
return None
|
||||
return des_dir
|
||||
|
@ -171,7 +171,9 @@ async def add_jd_download(listener, path):
|
||||
for link in links
|
||||
if link["availability"].lower() != "online"
|
||||
]:
|
||||
await retry_function(jdownloader.device.linkgrabber.remove_links, to_remove)
|
||||
await retry_function(
|
||||
jdownloader.device.linkgrabber.remove_links, to_remove
|
||||
)
|
||||
break
|
||||
|
||||
listener.name = listener.name or name
|
||||
|
@ -217,7 +217,17 @@ class RcloneList:
|
||||
self.item_type == itype
|
||||
elif self.list_status == "rcu":
|
||||
self.item_type == "--dirs-only"
|
||||
cmd = ["rclone", "lsjson", self.item_type, "--fast-list", "--no-mimetype", "--no-modtime", "--config", self.config_path, f"{self.remote}{self.path}"]
|
||||
cmd = [
|
||||
"rclone",
|
||||
"lsjson",
|
||||
self.item_type,
|
||||
"--fast-list",
|
||||
"--no-mimetype",
|
||||
"--no-modtime",
|
||||
"--config",
|
||||
self.config_path,
|
||||
f"{self.remote}{self.path}",
|
||||
]
|
||||
if self.is_cancelled:
|
||||
return
|
||||
res, err, code = await cmd_exec(cmd)
|
||||
|
@ -111,11 +111,11 @@ class TgUploader:
|
||||
)
|
||||
if self._sent_msg is None:
|
||||
self._sent_msg = await user.send_message(
|
||||
chat_id=self._listener.message.chat.id,
|
||||
text="Deleted Cmd Message! Don't delete the cmd message again!",
|
||||
disable_web_page_preview=True,
|
||||
disable_notification=True,
|
||||
)
|
||||
chat_id=self._listener.message.chat.id,
|
||||
text="Deleted Cmd Message! Don't delete the cmd message again!",
|
||||
disable_web_page_preview=True,
|
||||
disable_notification=True,
|
||||
)
|
||||
else:
|
||||
self._sent_msg = self._listener.message
|
||||
return True
|
||||
@ -139,7 +139,7 @@ class TgUploader:
|
||||
self._up_path = new_path
|
||||
else:
|
||||
cap_mono = f"<code>{file_}</code>"
|
||||
if len(file_) > 54:
|
||||
if len(file_) > 60:
|
||||
if is_archive(file_):
|
||||
name = get_base_name(file_)
|
||||
ext = file_.split(name, 1)[1]
|
||||
@ -153,7 +153,7 @@ class TgUploader:
|
||||
name = file_
|
||||
ext = ""
|
||||
extn = len(ext)
|
||||
remain = 54 - extn
|
||||
remain = 60 - extn
|
||||
name = name[:remain]
|
||||
if (
|
||||
self._listener.seed
|
||||
@ -198,16 +198,16 @@ class TgUploader:
|
||||
inputs.append(InputMediaPhoto(m, cap))
|
||||
else:
|
||||
outputs.remove(m)
|
||||
if outputs:
|
||||
self._sent_msg = (
|
||||
await self._sent_msg.reply_media_group(
|
||||
media=inputs,
|
||||
quote=True,
|
||||
disable_notification=True,
|
||||
)
|
||||
)[-1]
|
||||
for m in outputs:
|
||||
await remove(m)
|
||||
if outputs:
|
||||
self._sent_msg = (
|
||||
await self._sent_msg.reply_media_group(
|
||||
media=inputs,
|
||||
quote=True,
|
||||
disable_notification=True,
|
||||
)
|
||||
)[-1]
|
||||
for m in outputs:
|
||||
await remove(m)
|
||||
|
||||
async def _send_media_group(self, subkey, key, msgs):
|
||||
msgs_list = await msgs[0].reply_to_message.reply_media_group(
|
||||
|
@ -124,9 +124,7 @@ async def get_buttons(key=None, edit_type=None):
|
||||
buttons.ibutton("Back", "botset back")
|
||||
buttons.ibutton("Close", "botset close")
|
||||
for x in range(0, len(config_dict), 10):
|
||||
buttons.ibutton(
|
||||
f"{int(x/10)}", f"botset start var {x}", position="footer"
|
||||
)
|
||||
buttons.ibutton(f"{int(x/10)}", f"botset start var {x}", position="footer")
|
||||
msg = f"Config Variables | Page: {int(START/10)} | State: {STATE}"
|
||||
elif key == "private":
|
||||
buttons.ibutton("Back", "botset back")
|
||||
@ -146,9 +144,7 @@ Timeout: 60 sec"""
|
||||
buttons.ibutton("Back", "botset back")
|
||||
buttons.ibutton("Close", "botset close")
|
||||
for x in range(0, len(aria2_options), 10):
|
||||
buttons.ibutton(
|
||||
f"{int(x/10)}", f"botset start aria {x}", position="footer"
|
||||
)
|
||||
buttons.ibutton(f"{int(x/10)}", f"botset start aria {x}", position="footer")
|
||||
msg = f"Aria2c Options | Page: {int(START/10)} | State: {STATE}"
|
||||
elif key == "qbit":
|
||||
for k in list(qbit_options.keys())[START : 10 + START]:
|
||||
@ -160,9 +156,7 @@ Timeout: 60 sec"""
|
||||
buttons.ibutton("Back", "botset back")
|
||||
buttons.ibutton("Close", "botset close")
|
||||
for x in range(0, len(qbit_options), 10):
|
||||
buttons.ibutton(
|
||||
f"{int(x/10)}", f"botset start qbit {x}", position="footer"
|
||||
)
|
||||
buttons.ibutton(f"{int(x/10)}", f"botset start qbit {x}", position="footer")
|
||||
msg = f"Qbittorrent Options | Page: {int(START/10)} | State: {STATE}"
|
||||
button = buttons.build_menu(1) if key is None else buttons.build_menu(2)
|
||||
return msg, button
|
||||
|
@ -85,7 +85,9 @@ async def do(func, message):
|
||||
|
||||
try:
|
||||
with redirect_stdout(stdout):
|
||||
func_return = await sync_to_async(rfunc) if func == "exec" else await rfunc()
|
||||
func_return = (
|
||||
await sync_to_async(rfunc) if func == "exec" else await rfunc()
|
||||
)
|
||||
except Exception as e:
|
||||
value = stdout.getvalue()
|
||||
return f"{value}{format_exc()}"
|
||||
|
@ -138,7 +138,7 @@ ODLS: {get_readable_file_size(dl_speed)}/s
|
||||
OULS: {get_readable_file_size(up_speed)}/s
|
||||
OSDS: {get_readable_file_size(seed_speed)}/s
|
||||
"""
|
||||
await query.answer(msg, show_alert=True, cache_time=30)
|
||||
await query.answer(msg, show_alert=True)
|
||||
|
||||
|
||||
bot.add_handler(
|
||||
|
Loading…
Reference in New Issue
Block a user