diff --git a/misskaty/__init__.py b/misskaty/__init__.py index a22987e7..a10e927f 100644 --- a/misskaty/__init__.py +++ b/misskaty/__init__.py @@ -31,7 +31,6 @@ botStartTime = time.time() misskaty_version = "v2.023.5.16 - Stable" pymonclient = MongoClient(DATABASE_URI) -mongo = AsyncIOMotorClient(DATABASE_URI) # Pyrogram Bot Client app = Client( diff --git a/misskaty/helper/ffmpeg_helper.py b/misskaty/helper/ffmpeg_helper.py index da130aff..dc41147c 100644 --- a/misskaty/helper/ffmpeg_helper.py +++ b/misskaty/helper/ffmpeg_helper.py @@ -6,6 +6,7 @@ from pyrogram.errors import FloodWait from pyrogram.types import InputMediaPhoto from misskaty.plugins.dev import shell_exec +from misskaty.vars import VCSI_NAME, FF_MPEG_NAME def hhmmss(seconds): @@ -14,7 +15,7 @@ def hhmmss(seconds): async def take_ss(video_file): 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) 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): out_put_file_name = f"{output_directory}/{str(time.time())}.png" cmd = [ - "mediaextract", + FF_MPEG_NAME, "-ss", str(ttl), "-i", diff --git a/misskaty/helper/ssgen_helper.py b/misskaty/helper/ssgen_helper.py index 6b0fcc73..aac4f523 100644 --- a/misskaty/helper/ssgen_helper.py +++ b/misskaty/helper/ssgen_helper.py @@ -11,6 +11,8 @@ from pathlib import Path from pyrogram import enums from pyrogram.types import InlineKeyboardButton, InputMediaPhoto +from misskaty.vars import FF_MPEG_NAME + async def run_subprocess(cmd): 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): 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) await m.message.edit_msg(f"😀 `{i+1}` of `{num_screenshots}` generated!") if thumbnail_template.exists(): diff --git a/misskaty/plugins/media_extractor.py b/misskaty/plugins/media_extractor.py index 68e1de41..7025cbc8 100644 --- a/misskaty/plugins/media_extractor.py +++ b/misskaty/plugins/media_extractor.py @@ -24,7 +24,7 @@ from misskaty.helper.tools import get_random_string from misskaty.helper.localization import use_chat_lang from misskaty.helper.human_read import get_readable_time 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__) @@ -127,7 +127,7 @@ async def convertsrt(self: Client, ctx: Message, strings): dl = await reply.download(file_name="downloads/") 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}]") - (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() await ctx.reply_document( f"downloads/{filename}.srt", @@ -170,7 +170,7 @@ async def stream_extract(self: Client, update: CallbackQuery, strings): namafile = get_subname(lang, link, ext) try: 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 c_time = time() await update.message.reply_document( diff --git a/misskaty/plugins/stickers.py b/misskaty/plugins/stickers.py index 2bf40981..cfe508ca 100644 --- a/misskaty/plugins/stickers.py +++ b/misskaty/plugins/stickers.py @@ -17,7 +17,7 @@ from misskaty import BOT_USERNAME, app from misskaty.core.decorator.ratelimiter import ratelimiter from misskaty.helper.http import http 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" __HELP__ = """ @@ -335,7 +335,7 @@ async def convert_video(filename: str) -> str: downpath, f_name = os.path.split(filename) webm_video = os.path.join(downpath, f"{f_name.split('.', 1)[0]}.webm") cmd = [ - "mediaextract", + FF_MPEG_NAME, "-loglevel", "quiet", "-i", diff --git a/misskaty/plugins/ytdl_plugins.py b/misskaty/plugins/ytdl_plugins.py index 46f97853..5ddb912a 100644 --- a/misskaty/plugins/ytdl_plugins.py +++ b/misskaty/plugins/ytdl_plugins.py @@ -14,7 +14,7 @@ from misskaty.core.misskaty_patch.listen.listen import ListenerTimeout from misskaty.core.decorator.ratelimiter import ratelimiter from misskaty.helper.http import http 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__) regex = recompile(r"(https?://)?(www\.)?(youtube|youtu|youtube-nocookie)\.(com|be)/(watch\?v=|embed/|v/|.+\?v=)?(?P[A-Za-z0-9\-=_]{11})") @@ -70,7 +70,7 @@ async def ytdownv2(self: Client, ctx: Message, strings): if len(ctx.command) == 1: return await ctx.reply_msg(strings("invalid_link")) 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: x = await ytdl.parse(url, extract=True) 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: return await cq.answer(strings("unauth"), True) 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]) 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) await cq.answer(strings("wait")) 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: if data := await ytdl.extract_info_from_key(callback[1]): if len(callback[1]) == 11: @@ -142,7 +142,7 @@ async def ytdl_gendl_callback(self: Client, cq: CallbackQuery, strings): async with iYTDL( log_group_id=LOG_CHANNEL, cache_path="cache", - ffmpeg_location="/usr/bin/mediaextract", + ffmpeg_location=f"/usr/bin/{FF_MPEG_NAME}", delete_media=True, ) as ytdl: try: diff --git a/misskaty/vars.py b/misskaty/vars.py index d9066e24..8df14d97 100644 --- a/misskaty/vars.py +++ b/misskaty/vars.py @@ -44,6 +44,8 @@ except Exception as e: sys.exit(1) 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") TZ = environ.get("TZ", "Asia/Jakarta") COMMAND_HANDLER = environ.get("COMMAND_HANDLER", "! /").split()