From 884d90ad131eb95de8363151310aa23e67aac29f Mon Sep 17 00:00:00 2001 From: subinps <64341611+subinps@users.noreply.github.com> Date: Sun, 10 Oct 2021 19:21:14 +0530 Subject: [PATCH] live quality change --- plugins/callback.py | 5 +++-- plugins/commands.py | 38 ++++++++++++++++++++++++++++++++------ utils/utils.py | 6 ++++++ 3 files changed, 41 insertions(+), 8 deletions(-) diff --git a/plugins/callback.py b/plugins/callback.py index abf0579f..6fdade24 100644 --- a/plugins/callback.py +++ b/plugins/callback.py @@ -487,9 +487,10 @@ async def cb_handler(client: Client, query: CallbackQuery): Config.IS_VIDEO = set_config(Config.IS_VIDEO) await query.message.edit_reply_markup(reply_markup=await settings_panel()) data=Config.DATA.get('FILE_DATA') - if not data.get('dur', 0) or \ - data.get('dur') == 0: + if not data \ + or data.get('dur', 0) == 0: await restart_playout() + return k, reply = await seek_file(0) if k == False: await restart_playout() diff --git a/plugins/commands.py b/plugins/commands.py index 409dddc1..0d079ac4 100644 --- a/plugins/commands.py +++ b/plugins/commands.py @@ -41,12 +41,14 @@ is_admin, chat_filter, sudo_filter, - delete_messages + delete_messages, + seek_file ) from pyrogram import ( Client, filters ) + IST = pytz.timezone(Config.TIME_ZONE) if Config.DATABASE_URI: from utils import db @@ -249,7 +251,7 @@ async def set_heroku_var(client, message): await delete_messages([message, m]) return - if Config.DATABASE_URI and var in ["STARTUP_STREAM", "CHAT", "LOG_GROUP", "REPLY_MESSAGE", "DELAY", "RECORDING_DUMP"]: + if Config.DATABASE_URI and var in ["STARTUP_STREAM", "CHAT", "LOG_GROUP", "REPLY_MESSAGE", "DELAY", "RECORDING_DUMP", "QUALITY"]: await m.edit("Mongo DB Found, Setting up config vars...") await asyncio.sleep(2) if not value: @@ -264,13 +266,27 @@ async def set_heroku_var(client, message): await delete_messages([message, m]) return else: - if var in ["CHAT", "LOG_GROUP", "RECORDING_DUMP"]: + if var in ["CHAT", "LOG_GROUP", "RECORDING_DUMP", "QUALITY"]: try: value=int(value) except: - await m.edit("You should give me a chat id . It should be an interger.") - await delete_messages([message, m]) - return + if var == "QUALITY": + if not value.lower() in ["low", "medium", "high"]: + await m.edit("You should specify a value between 10 - 100.") + await delete_messages([message, m]) + return + else: + value = value.lower() + if value == "high": + value = 100 + elif value == "medium": + value = 66.9 + elif value == "low": + value = 50 + else: + await m.edit("You should give me a chat id . It should be an interger.") + await delete_messages([message, m]) + return if var == "CHAT": await leave_call() Config.ADMIN_CACHE=False @@ -280,6 +296,16 @@ async def set_heroku_var(client, message): Config.CHAT=int(value) await restart() await edit_config(var, int(value)) + if var == "QUALITY": + if Config.CALL_STATUS: + data=Config.DATA.get('FILE_DATA') + if not data \ + or data.get('dur', 0) == 0: + await restart_playout() + return + k, reply = await seek_file(0) + if k == False: + await restart_playout() await m.edit(f"Succesfully changed {var} to {value}") await delete_messages([message, m]) return diff --git a/utils/utils.py b/utils/utils.py index 7118af20..a46b86dd 100644 --- a/utils/utils.py +++ b/utils/utils.py @@ -1610,6 +1610,7 @@ async def sync_to_db(): await db.edit_config("RECORDING_DUMP", Config.RECORDING_DUMP) await db.edit_config("RECORDING_TITLE", Config.RECORDING_TITLE) await db.edit_config("HAS_SCHEDULE", Config.HAS_SCHEDULE) + await db.edit_config("CUSTOM_QUALITY", Config.CUSTOM_QUALITY) async def sync_from_db(): @@ -1638,6 +1639,7 @@ async def sync_from_db(): Config.RECORDING_DUMP = await db.get_config("RECORDING_DUMP") Config.RECORDING_TITLE = await db.get_config("RECORDING_TITLE") Config.HAS_SCHEDULE = await db.get_config("HAS_SCHEDULE") + Config.CUSTOM_QUALITY = await db.get_config("CUSTOM_QUALITY") async def add_to_db_playlist(song): if Config.DATABASE_URI: @@ -1696,6 +1698,8 @@ async def check_db(): db.add_config("RECORDING_TITLE", Config.RECORDING_TITLE) if not await db.is_saved('HAS_SCHEDULE'): db.add_config("HAS_SCHEDULE", Config.HAS_SCHEDULE) + if not await db.is_saved("CUSTOM_QUALITY"): + db.add_config("CUSTOM_QUALITY", Config.CUSTOM_QUALITY) async def is_audio(file): @@ -1876,6 +1880,8 @@ async def edit_config(var, value): Config.REPLY_MESSAGE = value elif var == "RECORDING_DUMP": Config.RECORDING_DUMP = value + elif var == "QUALITY": + Config.CUSTOM_QUALITY = value await sync_to_db()