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:
anasty17 2024-01-07 20:26:47 +02:00
parent 9b671f7f51
commit eeb5bf2c85
7 changed files with 76 additions and 43 deletions

View File

@ -2,7 +2,7 @@ from os import path as ospath, cpu_count
from aiofiles.os import remove, path as aiopath, makedirs from aiofiles.os import remove, path as aiopath, makedirs
from time import time from time import time
from re import search as re_search 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 asyncio.subprocess import PIPE
from PIL import Image from PIL import Image
from aioshutil import move from aioshutil import move
@ -153,21 +153,40 @@ async def take_ss(video_file, ss_nb) -> list:
name, _ = ospath.splitext(name) name, _ = ospath.splitext(name)
dirpath = f"{dirpath}/screenshots/" dirpath = f"{dirpath}/screenshots/"
await makedirs(dirpath, exist_ok=True) await makedirs(dirpath, exist_ok=True)
interval = duration // ss_nb + 1 interval = duration // (ss_nb + 1)
cap_time = interval cap_time = interval
outputs = [] outputs = []
cmd = "" cmds = []
for i in range(ss_nb): for i in range(ss_nb):
output = f"{dirpath}SS.{name}_{i:02}.png" output = f"{dirpath}SS.{name}_{i:02}.png"
outputs.append(output) 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 cap_time += interval
if i + 1 != ss_nb: cmds.append(cmd_exec(cmd))
cmd += " && " try:
_, err, code = await cmd_exec(cmd, True) resutls = await wait_for(gather(*cmds), timeout=15)
if code != 0: 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( 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 []
return outputs return outputs
@ -216,7 +235,7 @@ async def create_thumbnail(video_file, duration):
"-loglevel", "-loglevel",
"error", "error",
"-ss", "-ss",
str(duration), f"{duration}",
"-i", "-i",
video_file, video_file,
"-vf", "-vf",
@ -225,10 +244,16 @@ async def create_thumbnail(video_file, duration):
"1", "1",
des_dir, des_dir,
] ]
_, err, code = await cmd_exec(cmd) try:
if code != 0 or not await aiopath.exists(des_dir): _, 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( 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 None
return des_dir return des_dir

View File

@ -171,7 +171,9 @@ async def add_jd_download(listener, path):
for link in links for link in links
if link["availability"].lower() != "online" 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 break
listener.name = listener.name or name listener.name = listener.name or name

View File

@ -217,7 +217,17 @@ class RcloneList:
self.item_type == itype self.item_type == itype
elif self.list_status == "rcu": elif self.list_status == "rcu":
self.item_type == "--dirs-only" 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: if self.is_cancelled:
return return
res, err, code = await cmd_exec(cmd) res, err, code = await cmd_exec(cmd)

View File

@ -111,11 +111,11 @@ class TgUploader:
) )
if self._sent_msg is None: if self._sent_msg is None:
self._sent_msg = await user.send_message( self._sent_msg = await user.send_message(
chat_id=self._listener.message.chat.id, chat_id=self._listener.message.chat.id,
text="Deleted Cmd Message! Don't delete the cmd message again!", text="Deleted Cmd Message! Don't delete the cmd message again!",
disable_web_page_preview=True, disable_web_page_preview=True,
disable_notification=True, disable_notification=True,
) )
else: else:
self._sent_msg = self._listener.message self._sent_msg = self._listener.message
return True return True
@ -139,7 +139,7 @@ class TgUploader:
self._up_path = new_path self._up_path = new_path
else: else:
cap_mono = f"<code>{file_}</code>" cap_mono = f"<code>{file_}</code>"
if len(file_) > 54: if len(file_) > 60:
if is_archive(file_): if is_archive(file_):
name = get_base_name(file_) name = get_base_name(file_)
ext = file_.split(name, 1)[1] ext = file_.split(name, 1)[1]
@ -153,7 +153,7 @@ class TgUploader:
name = file_ name = file_
ext = "" ext = ""
extn = len(ext) extn = len(ext)
remain = 54 - extn remain = 60 - extn
name = name[:remain] name = name[:remain]
if ( if (
self._listener.seed self._listener.seed
@ -198,16 +198,16 @@ class TgUploader:
inputs.append(InputMediaPhoto(m, cap)) inputs.append(InputMediaPhoto(m, cap))
else: else:
outputs.remove(m) outputs.remove(m)
if outputs: if outputs:
self._sent_msg = ( self._sent_msg = (
await self._sent_msg.reply_media_group( await self._sent_msg.reply_media_group(
media=inputs, media=inputs,
quote=True, quote=True,
disable_notification=True, disable_notification=True,
) )
)[-1] )[-1]
for m in outputs: for m in outputs:
await remove(m) await remove(m)
async def _send_media_group(self, subkey, key, msgs): async def _send_media_group(self, subkey, key, msgs):
msgs_list = await msgs[0].reply_to_message.reply_media_group( msgs_list = await msgs[0].reply_to_message.reply_media_group(

View File

@ -124,9 +124,7 @@ async def get_buttons(key=None, edit_type=None):
buttons.ibutton("Back", "botset back") buttons.ibutton("Back", "botset back")
buttons.ibutton("Close", "botset close") buttons.ibutton("Close", "botset close")
for x in range(0, len(config_dict), 10): for x in range(0, len(config_dict), 10):
buttons.ibutton( buttons.ibutton(f"{int(x/10)}", f"botset start var {x}", position="footer")
f"{int(x/10)}", f"botset start var {x}", position="footer"
)
msg = f"Config Variables | Page: {int(START/10)} | State: {STATE}" msg = f"Config Variables | Page: {int(START/10)} | State: {STATE}"
elif key == "private": elif key == "private":
buttons.ibutton("Back", "botset back") buttons.ibutton("Back", "botset back")
@ -146,9 +144,7 @@ Timeout: 60 sec"""
buttons.ibutton("Back", "botset back") buttons.ibutton("Back", "botset back")
buttons.ibutton("Close", "botset close") buttons.ibutton("Close", "botset close")
for x in range(0, len(aria2_options), 10): for x in range(0, len(aria2_options), 10):
buttons.ibutton( buttons.ibutton(f"{int(x/10)}", f"botset start aria {x}", position="footer")
f"{int(x/10)}", f"botset start aria {x}", position="footer"
)
msg = f"Aria2c Options | Page: {int(START/10)} | State: {STATE}" msg = f"Aria2c Options | Page: {int(START/10)} | State: {STATE}"
elif key == "qbit": elif key == "qbit":
for k in list(qbit_options.keys())[START : 10 + START]: for k in list(qbit_options.keys())[START : 10 + START]:
@ -160,9 +156,7 @@ Timeout: 60 sec"""
buttons.ibutton("Back", "botset back") buttons.ibutton("Back", "botset back")
buttons.ibutton("Close", "botset close") buttons.ibutton("Close", "botset close")
for x in range(0, len(qbit_options), 10): for x in range(0, len(qbit_options), 10):
buttons.ibutton( buttons.ibutton(f"{int(x/10)}", f"botset start qbit {x}", position="footer")
f"{int(x/10)}", f"botset start qbit {x}", position="footer"
)
msg = f"Qbittorrent Options | Page: {int(START/10)} | State: {STATE}" msg = f"Qbittorrent Options | Page: {int(START/10)} | State: {STATE}"
button = buttons.build_menu(1) if key is None else buttons.build_menu(2) button = buttons.build_menu(1) if key is None else buttons.build_menu(2)
return msg, button return msg, button

View File

@ -85,7 +85,9 @@ async def do(func, message):
try: try:
with redirect_stdout(stdout): 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: except Exception as e:
value = stdout.getvalue() value = stdout.getvalue()
return f"{value}{format_exc()}" return f"{value}{format_exc()}"

View File

@ -138,7 +138,7 @@ ODLS: {get_readable_file_size(dl_speed)}/s
OULS: {get_readable_file_size(up_speed)}/s OULS: {get_readable_file_size(up_speed)}/s
OSDS: {get_readable_file_size(seed_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( bot.add_handler(