mirror of
https://github.com/yasirarism/MissKatyPyro.git
synced 2025-12-29 17:44:50 +00:00
* ci: Update .deepsource.toml
* ci: Update .deepsource.toml
* style: format code with black and isort
Format code with black and isort
This commit fixes the style issues introduced in 0fb651a according to the output
from Black and isort.
Details: https://app.deepsource.com/gh/yasirarism/MissKatyPyro/transform/d8f2f66e-b496-4686-aca6-9830236eda12/
---------
Co-authored-by: deepsource-io[bot] <42547082+deepsource-io[bot]@users.noreply.github.com>
Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>
77 lines
2.5 KiB
Python
77 lines
2.5 KiB
Python
import asyncio
|
|
import os
|
|
import time
|
|
|
|
from pyrogram.errors import FloodWait
|
|
from pyrogram.types import InputMediaPhoto
|
|
|
|
from misskaty.plugins.dev import shell_exec
|
|
|
|
|
|
def hhmmss(seconds):
|
|
return time.strftime("%H:%M:%S", time.gmtime(seconds))
|
|
|
|
|
|
async def take_ss(video_file):
|
|
out_put_file_name = f"genss{str(time.time())}.png"
|
|
cmd = f"vcsi '{video_file}' -t -w 1340 -g 4x4 --template misskaty/helper/ssgen_template.html --quality 100 --end-delay-percent 20 --metadata-font-size 30 --timestamp-font-size 20 -o {out_put_file_name}"
|
|
await shell_exec(cmd)
|
|
return out_put_file_name if os.path.lexists(out_put_file_name) else None
|
|
|
|
|
|
async def ssgen_link(video, output_directory, ttl):
|
|
out_put_file_name = f"{output_directory}/{str(time.time())}.png"
|
|
cmd = [
|
|
"ffmpeg",
|
|
"-ss",
|
|
str(ttl),
|
|
"-i",
|
|
video,
|
|
"-vframes",
|
|
"1",
|
|
"-f",
|
|
"image2",
|
|
out_put_file_name,
|
|
]
|
|
process = await asyncio.create_subprocess_exec(
|
|
*cmd, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE
|
|
)
|
|
|
|
stdout, stderr = await process.communicate()
|
|
stderr.decode().strip()
|
|
stdout.decode().strip()
|
|
return out_put_file_name if os.path.isfile(out_put_file_name) else None
|
|
|
|
|
|
async def genss_link(msg, video_link, output_directory, min_duration, no_of_photos):
|
|
metadata = (
|
|
await shell_exec(
|
|
f"ffprobe -i {video_link} -show_entries format=duration -v quiet -of csv='p=0'"
|
|
)
|
|
)[0]
|
|
duration = round(float(metadata))
|
|
if duration > min_duration:
|
|
images = []
|
|
ttl_step = duration // no_of_photos
|
|
current_ttl = ttl_step
|
|
for looper in range(no_of_photos):
|
|
ss_img = await ssgen_link(video_link, output_directory, current_ttl)
|
|
images.append(
|
|
InputMediaPhoto(
|
|
media=ss_img, caption=f"Screenshot at {hhmmss(current_ttl)}"
|
|
)
|
|
)
|
|
try:
|
|
await msg.edit(
|
|
f"📸 <b>Take Screenshoot:</b>\n<code>{looper+1} of {no_of_photos} screenshot generated..</code>"
|
|
)
|
|
except FloodWait as e:
|
|
await asyncio.sleep(e.value)
|
|
await msg.edit(
|
|
f"📸 <b>Take Screenshoot:</b>\n<code>{looper+1} of {no_of_photos} screenshot generated..</code>"
|
|
)
|
|
current_ttl = current_ttl + ttl_step
|
|
await asyncio.sleep(2)
|
|
return images
|
|
else:
|
|
return None
|