mirror of
https://github.com/yasirarism/MissKatyPyro.git
synced 2026-01-07 04:14:51 +00:00
Fix ctx param, add mongo session, and fix ffmpeg
This commit is contained in:
parent
e03a0a6df2
commit
dc1d46505d
7 changed files with 18 additions and 14 deletions
|
|
@ -31,7 +31,6 @@ botStartTime = time.time()
|
||||||
misskaty_version = "v2.023.5.16 - Stable"
|
misskaty_version = "v2.023.5.16 - Stable"
|
||||||
|
|
||||||
pymonclient = MongoClient(DATABASE_URI)
|
pymonclient = MongoClient(DATABASE_URI)
|
||||||
mongo = AsyncIOMotorClient(DATABASE_URI)
|
|
||||||
|
|
||||||
# Pyrogram Bot Client
|
# Pyrogram Bot Client
|
||||||
app = Client(
|
app = Client(
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ from pyrogram.errors import FloodWait
|
||||||
from pyrogram.types import InputMediaPhoto
|
from pyrogram.types import InputMediaPhoto
|
||||||
|
|
||||||
from misskaty.plugins.dev import shell_exec
|
from misskaty.plugins.dev import shell_exec
|
||||||
|
from misskaty.vars import VCSI_NAME, FF_MPEG_NAME
|
||||||
|
|
||||||
|
|
||||||
def hhmmss(seconds):
|
def hhmmss(seconds):
|
||||||
|
|
@ -14,7 +15,7 @@ def hhmmss(seconds):
|
||||||
|
|
||||||
async def take_ss(video_file):
|
async def take_ss(video_file):
|
||||||
out_put_file_name = f"genss{str(time.time())}.png"
|
out_put_file_name = f"genss{str(time.time())}.png"
|
||||||
cmd = f"ssmedia '{video_file}' -t -w 1340 -g 4x4 --ffmpeg-name mediaextract --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}"
|
cmd = f"{VCSI_NAME} '{video_file}' -t -w 1340 -g 4x4 --ffmpeg-name {FF_MPEG_NAME} --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)
|
await shell_exec(cmd)
|
||||||
return out_put_file_name if os.path.lexists(out_put_file_name) else None
|
return out_put_file_name if os.path.lexists(out_put_file_name) else None
|
||||||
|
|
||||||
|
|
@ -22,7 +23,7 @@ async def take_ss(video_file):
|
||||||
async def ssgen_link(video, output_directory, ttl):
|
async def ssgen_link(video, output_directory, ttl):
|
||||||
out_put_file_name = f"{output_directory}/{str(time.time())}.png"
|
out_put_file_name = f"{output_directory}/{str(time.time())}.png"
|
||||||
cmd = [
|
cmd = [
|
||||||
"mediaextract",
|
FF_MPEG_NAME,
|
||||||
"-ss",
|
"-ss",
|
||||||
str(ttl),
|
str(ttl),
|
||||||
"-i",
|
"-i",
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,8 @@ from pathlib import Path
|
||||||
from pyrogram import enums
|
from pyrogram import enums
|
||||||
from pyrogram.types import InlineKeyboardButton, InputMediaPhoto
|
from pyrogram.types import InlineKeyboardButton, InputMediaPhoto
|
||||||
|
|
||||||
|
from misskaty.vars import FF_MPEG_NAME
|
||||||
|
|
||||||
|
|
||||||
async def run_subprocess(cmd):
|
async def run_subprocess(cmd):
|
||||||
process = await asyncio.create_subprocess_shell(cmd, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE)
|
process = await asyncio.create_subprocess_shell(cmd, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE)
|
||||||
|
|
@ -89,7 +91,7 @@ async def screenshot_flink(c, m):
|
||||||
|
|
||||||
for i, sec in enumerate(screenshot_secs):
|
for i, sec in enumerate(screenshot_secs):
|
||||||
thumbnail_template = output_folder.joinpath(f"{i+1}.png")
|
thumbnail_template = output_folder.joinpath(f"{i+1}.png")
|
||||||
ffmpeg_cmd = f"mediaextract -hide_banner -ss {sec} -i {shlex.quote(file_link)} -vframes 1 '{thumbnail_template}'"
|
ffmpeg_cmd = f"{FF_MPEG_NAME} -hide_banner -ss {sec} -i {shlex.quote(file_link)} -vframes 1 '{thumbnail_template}'"
|
||||||
output = await run_subprocess(ffmpeg_cmd)
|
output = await run_subprocess(ffmpeg_cmd)
|
||||||
await m.message.edit_msg(f"😀 `{i+1}` of `{num_screenshots}` generated!")
|
await m.message.edit_msg(f"😀 `{i+1}` of `{num_screenshots}` generated!")
|
||||||
if thumbnail_template.exists():
|
if thumbnail_template.exists():
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ from misskaty.helper.tools import get_random_string
|
||||||
from misskaty.helper.localization import use_chat_lang
|
from misskaty.helper.localization import use_chat_lang
|
||||||
from misskaty.helper.human_read import get_readable_time
|
from misskaty.helper.human_read import get_readable_time
|
||||||
from misskaty.plugins.dev import shell_exec
|
from misskaty.plugins.dev import shell_exec
|
||||||
from misskaty.vars import COMMAND_HANDLER
|
from misskaty.vars import COMMAND_HANDLER, FF_MPEG_NAME
|
||||||
|
|
||||||
LOGGER = getLogger(__name__)
|
LOGGER = getLogger(__name__)
|
||||||
|
|
||||||
|
|
@ -127,7 +127,7 @@ async def convertsrt(self: Client, ctx: Message, strings):
|
||||||
dl = await reply.download(file_name="downloads/")
|
dl = await reply.download(file_name="downloads/")
|
||||||
filename = dl.split("/", 3)[3]
|
filename = dl.split("/", 3)[3]
|
||||||
LOGGER.info(f"ConvertSub: {filename} by {ctx.from_user.first_name if ctx.from_user else ctx.sender_chat.title} [{ctx.from_user.id if ctx.from_user else ctx.sender_chat.id}]")
|
LOGGER.info(f"ConvertSub: {filename} by {ctx.from_user.first_name if ctx.from_user else ctx.sender_chat.title} [{ctx.from_user.id if ctx.from_user else ctx.sender_chat.id}]")
|
||||||
(await shell_exec(f"mediaextract -i '{dl}' 'downloads/{filename}.srt'"))[0]
|
(await shell_exec(f"{FF_MPEG_NAME} -i '{dl}' 'downloads/{filename}.srt'"))[0]
|
||||||
c_time = time()
|
c_time = time()
|
||||||
await ctx.reply_document(
|
await ctx.reply_document(
|
||||||
f"downloads/{filename}.srt",
|
f"downloads/{filename}.srt",
|
||||||
|
|
@ -170,7 +170,7 @@ async def stream_extract(self: Client, update: CallbackQuery, strings):
|
||||||
namafile = get_subname(lang, link, ext)
|
namafile = get_subname(lang, link, ext)
|
||||||
try:
|
try:
|
||||||
LOGGER.info(f"ExtractSub: {namafile} by {update.from_user.first_name} [{update.from_user.id}]")
|
LOGGER.info(f"ExtractSub: {namafile} by {update.from_user.first_name} [{update.from_user.id}]")
|
||||||
(await shell_exec(f"mediaextract -i {link} -map {map} '{namafile}'"))[0]
|
(await shell_exec(f"{FF_MPEG_NAME} -i {link} -map {map} '{namafile}'"))[0]
|
||||||
timelog = time() - start_time
|
timelog = time() - start_time
|
||||||
c_time = time()
|
c_time = time()
|
||||||
await update.message.reply_document(
|
await update.message.reply_document(
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ from misskaty import BOT_USERNAME, app
|
||||||
from misskaty.core.decorator.ratelimiter import ratelimiter
|
from misskaty.core.decorator.ratelimiter import ratelimiter
|
||||||
from misskaty.helper.http import http
|
from misskaty.helper.http import http
|
||||||
from misskaty.helper.localization import use_chat_lang
|
from misskaty.helper.localization import use_chat_lang
|
||||||
from misskaty.vars import COMMAND_HANDLER, LOG_CHANNEL
|
from misskaty.vars import COMMAND_HANDLER, LOG_CHANNEL, FF_MPEG_NAME
|
||||||
|
|
||||||
__MODULE__ = "Stickers"
|
__MODULE__ = "Stickers"
|
||||||
__HELP__ = """
|
__HELP__ = """
|
||||||
|
|
@ -335,7 +335,7 @@ async def convert_video(filename: str) -> str:
|
||||||
downpath, f_name = os.path.split(filename)
|
downpath, f_name = os.path.split(filename)
|
||||||
webm_video = os.path.join(downpath, f"{f_name.split('.', 1)[0]}.webm")
|
webm_video = os.path.join(downpath, f"{f_name.split('.', 1)[0]}.webm")
|
||||||
cmd = [
|
cmd = [
|
||||||
"mediaextract",
|
FF_MPEG_NAME,
|
||||||
"-loglevel",
|
"-loglevel",
|
||||||
"quiet",
|
"quiet",
|
||||||
"-i",
|
"-i",
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ from misskaty.core.misskaty_patch.listen.listen import ListenerTimeout
|
||||||
from misskaty.core.decorator.ratelimiter import ratelimiter
|
from misskaty.core.decorator.ratelimiter import ratelimiter
|
||||||
from misskaty.helper.http import http
|
from misskaty.helper.http import http
|
||||||
from misskaty.helper.localization import use_chat_lang
|
from misskaty.helper.localization import use_chat_lang
|
||||||
from misskaty.vars import COMMAND_HANDLER, LOG_CHANNEL
|
from misskaty.vars import COMMAND_HANDLER, LOG_CHANNEL, FF_MPEG_NAME
|
||||||
|
|
||||||
LOGGER = getLogger(__name__)
|
LOGGER = getLogger(__name__)
|
||||||
regex = recompile(r"(https?://)?(www\.)?(youtube|youtu|youtube-nocookie)\.(com|be)/(watch\?v=|embed/|v/|.+\?v=)?(?P<id>[A-Za-z0-9\-=_]{11})")
|
regex = recompile(r"(https?://)?(www\.)?(youtube|youtu|youtube-nocookie)\.(com|be)/(watch\?v=|embed/|v/|.+\?v=)?(?P<id>[A-Za-z0-9\-=_]{11})")
|
||||||
|
|
@ -70,7 +70,7 @@ async def ytdownv2(self: Client, ctx: Message, strings):
|
||||||
if len(ctx.command) == 1:
|
if len(ctx.command) == 1:
|
||||||
return await ctx.reply_msg(strings("invalid_link"))
|
return await ctx.reply_msg(strings("invalid_link"))
|
||||||
url = ctx.input
|
url = ctx.input
|
||||||
async with iYTDL(log_group_id=0, cache_path="cache", ffmpeg_location="/usr/bin/mediaextract") as ytdl:
|
async with iYTDL(log_group_id=0, cache_path="cache", ffmpeg_location=f"/usr/bin/{FF_MPEG_NAME}") as ytdl:
|
||||||
try:
|
try:
|
||||||
x = await ytdl.parse(url, extract=True)
|
x = await ytdl.parse(url, extract=True)
|
||||||
if x is None:
|
if x is None:
|
||||||
|
|
@ -96,7 +96,7 @@ async def ytdl_listall_callback(self: Client, cq: CallbackQuery, strings):
|
||||||
if cq.from_user.id != cq.message.reply_to_message.from_user.id:
|
if cq.from_user.id != cq.message.reply_to_message.from_user.id:
|
||||||
return await cq.answer(strings("unauth"), True)
|
return await cq.answer(strings("unauth"), True)
|
||||||
callback = cq.data.split("|")
|
callback = cq.data.split("|")
|
||||||
async with iYTDL(log_group_id=0, cache_path="cache", ffmpeg_location="/usr/bin/mediaextract") as ytdl:
|
async with iYTDL(log_group_id=0, cache_path="cache", ffmpeg_location=f"/usr/bin/{FF_MPEG_NAME}") as ytdl:
|
||||||
media, buttons = await ytdl.listview(callback[1])
|
media, buttons = await ytdl.listview(callback[1])
|
||||||
await cq.edit_message_media(media=media, reply_markup=buttons.add(cq.from_user.id))
|
await cq.edit_message_media(media=media, reply_markup=buttons.add(cq.from_user.id))
|
||||||
|
|
||||||
|
|
@ -109,7 +109,7 @@ async def ytdl_extractinfo_callback(self: Client, cq: CallbackQuery, strings):
|
||||||
return await cq.answer(strings("unauth"), True)
|
return await cq.answer(strings("unauth"), True)
|
||||||
await cq.answer(strings("wait"))
|
await cq.answer(strings("wait"))
|
||||||
callback = cq.data.split("|")
|
callback = cq.data.split("|")
|
||||||
async with iYTDL(log_group_id=0, cache_path="cache", ffmpeg_location="/usr/bin/mediaextract") as ytdl:
|
async with iYTDL(log_group_id=0, cache_path="cache", ffmpeg_location=f"/usr/bin/{FF_MPEG_NAME}") as ytdl:
|
||||||
try:
|
try:
|
||||||
if data := await ytdl.extract_info_from_key(callback[1]):
|
if data := await ytdl.extract_info_from_key(callback[1]):
|
||||||
if len(callback[1]) == 11:
|
if len(callback[1]) == 11:
|
||||||
|
|
@ -142,7 +142,7 @@ async def ytdl_gendl_callback(self: Client, cq: CallbackQuery, strings):
|
||||||
async with iYTDL(
|
async with iYTDL(
|
||||||
log_group_id=LOG_CHANNEL,
|
log_group_id=LOG_CHANNEL,
|
||||||
cache_path="cache",
|
cache_path="cache",
|
||||||
ffmpeg_location="/usr/bin/mediaextract",
|
ffmpeg_location=f"/usr/bin/{FF_MPEG_NAME}",
|
||||||
delete_media=True,
|
delete_media=True,
|
||||||
) as ytdl:
|
) as ytdl:
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,8 @@ except Exception as e:
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
USER_SESSION = environ.get("USER_SESSION")
|
USER_SESSION = environ.get("USER_SESSION")
|
||||||
|
FF_MPEG_NAME = environ.get("FF_MPEG_NAME", "ffmpeg")
|
||||||
|
VCSI_NAME = environ.get("VCSI_NAME", "vcsi")
|
||||||
DATABASE_NAME = environ.get("DATABASE_NAME", "MissKatyDB")
|
DATABASE_NAME = environ.get("DATABASE_NAME", "MissKatyDB")
|
||||||
TZ = environ.get("TZ", "Asia/Jakarta")
|
TZ = environ.get("TZ", "Asia/Jakarta")
|
||||||
COMMAND_HANDLER = environ.get("COMMAND_HANDLER", "! /").split()
|
COMMAND_HANDLER = environ.get("COMMAND_HANDLER", "! /").split()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue