diff --git a/config.py b/config.py index 87da0dad..83f57135 100644 --- a/config.py +++ b/config.py @@ -54,7 +54,8 @@ class Config: #heroku API_KEY=os.environ.get("HEROKU_API_KEY", None) APP_NAME=os.environ.get("HEROKU_APP_NAME", None) - + + #Optional Configuration SHUFFLE=is_enabled(os.environ.get("SHUFFLE", 'True')) ADMIN_ONLY=is_enabled(os.environ.get("ADMIN_ONLY", "False")) @@ -92,6 +93,10 @@ class Config: SCHEDULE_LIST=[] playlist=[] + CONFIG_LIST = ["ADMINS", "IS_VIDEO", "IS_LOOP", "REPLY_PM", "ADMIN_ONLY", "SHUFFLE", "EDIT_TITLE", "CHAT", + "SUDO", "REPLY_MESSAGE", "STREAM_URL", "DELAY", "LOG_GROUP", "SCHEDULED_STREAM", "SCHEDULE_LIST", + "IS_VIDEO_RECORD", "IS_RECORDING", "WAS_RECORDING", "RECORDING_TITLE", "PORTRAIT", "RECORDING_DUMP", "HAS_SCHEDULE", + "CUSTOM_QUALITY"] STARTUP_ERROR=None @@ -133,7 +138,7 @@ class Config: REPLY_PM=True LOGGER.info("Reply Message Found, Enabled PM MSG") else: - REPLY_MESSAGE=None + REPLY_MESSAGE=False REPLY_PM=False if E_BITRATE: diff --git a/main.py b/main.py index f06268b8..b39b5fd2 100644 --- a/main.py +++ b/main.py @@ -16,7 +16,8 @@ play, start_stream, startup_check, - sync_from_db + sync_from_db, + check_changes ) from user import group_call, USER from utils import LOGGER @@ -25,6 +26,7 @@ from bot import bot import asyncio import os + if Config.DATABASE_URI: from utils import db @@ -43,6 +45,7 @@ async def main(): await db.del_config("RESTART") except: pass + await check_changes() await sync_from_db() except Exception as e: LOGGER.error(f"Errors occured while setting up database for VCPlayerBot, check the value of DATABASE_URI. Full error - {str(e)}", exc_info=True) diff --git a/plugins/commands.py b/plugins/commands.py index 0d079ac4..05dd56fa 100644 --- a/plugins/commands.py +++ b/plugins/commands.py @@ -241,11 +241,27 @@ async def set_heroku_var(client, message): m = await message.reply("Checking config vars..") if " " in message.text: cmd, env = message.text.split(" ", 1) - if not "=" in env: - await m.edit("You should specify the value for env.\nExample: /env CHAT=-100213658211") - await delete_messages([message, m]) - return - var, value = env.split("=", 1) + if "=" in env: + var, value = env.split("=", 1) + else: + if env == "STARTUP_STREAM": + env_ = "STREAM_URL" + elif env == "QUALITY": + env_ = "CUSTOM_QUALITY" + else: + env_ = env + ENV_VARS = ["ADMINS", "SUDO", "CHAT", "LOG_GROUP", "STREAM_URL", "SHUFFLE", "ADMIN_ONLY", "REPLY_MESSAGE", + "EDIT_TITLE", "RECORDING_DUMP", "RECORDING_TITLE", "IS_VIDEO", "IS_LOOP", "DELAY", "PORTRAIT", + "IS_VIDEO_RECORD", "PTN", "CUSTOM_QUALITY"] + if env_ in ENV_VARS: + await m.edit(f"Current Value for `{env}` is `{getattr(Config, env_)}`") + await delete_messages([message]) + return + else: + await m.edit("This is an invalid env value. Read help on env to know about available env vars.") + await delete_messages([message, m]) + return + else: await m.edit("You haven't provided any value for env, you should follow the correct format.\nExample: /env CHAT=-1020202020202 to change or set CHAT var.\n/env REPLY_MESSAGE= To delete REPLY_MESSAGE.") await delete_messages([message, m]) diff --git a/plugins/controls.py b/plugins/controls.py index 7aeda3f3..5a2bda4a 100644 --- a/plugins/controls.py +++ b/plugins/controls.py @@ -175,7 +175,7 @@ async def set_vol(_, m: Message): -@Client.on_message(filters.command(['mute', f"mute@{Config.BOT_USERNAME}"]) & admin_filter & chat_filter) +@Client.on_message(filters.command(['vcmute', f"vcmute@{Config.BOT_USERNAME}"]) & admin_filter & chat_filter) async def set_mute(_, m: Message): if not Config.CALL_STATUS: await m.reply_text( @@ -197,7 +197,7 @@ async def set_mute(_, m: Message): k = await m.reply_text("Already muted.") await delete_messages([m, k]) -@Client.on_message(filters.command(['unmute', f"unmute@{Config.BOT_USERNAME}"]) & admin_filter & chat_filter) +@Client.on_message(filters.command(['vcunmute', f"vcunmute@{Config.BOT_USERNAME}"]) & admin_filter & chat_filter) async def set_unmute(_, m: Message): if not Config.CALL_STATUS: await m.reply_text( diff --git a/plugins/player.py b/plugins/player.py index 3d7b46fa..dabbd6ef 100644 --- a/plugins/player.py +++ b/plugins/player.py @@ -153,10 +153,17 @@ async def add_to_playlist(_, message: Message): nyav = now.strftime("%d-%m-%Y-%H:%M:%S") if type in ["video", "audio"]: if type == "audio": + if m_video.title is None: + if m_video.file_name is None: + title_ = "Music" + else: + title_ = m_video.file_name + else: + title_ = m_video.title if m_video.performer is not None: - title = f"{m_video.performer} - {m_video.title}" + title = f"{m_video.performer} - {title_}" else: - title=m_video.title + title=title_ unique = f"{nyav}_{m_video.file_size}_audio" else: title=m_video.file_name @@ -167,6 +174,8 @@ async def add_to_playlist(_, message: Message): if title_: title = title_ file_id=m_video.file_id + if title is None: + title = 'Music' data={1:title, 2:file_id, 3:"telegram", 4:user, 5:unique} if message.command[0] == "fplay": pla = [data] + Config.playlist @@ -462,11 +471,11 @@ async def stream(client, m: Message): -admincmds=["yplay", "leave", "pause", "resume", "skip", "restart", "volume", "shuffle", "clearplaylist", "export", "import", "update", 'replay', 'logs', 'stream', 'fplay', 'schedule', 'record', 'slist', 'cancel', 'cancelall', 'vcpromote', 'vcdemote', 'refresh', 'rtitle', 'seek', 'mute', 'unmute', +admincmds=["yplay", "leave", "pause", "resume", "skip", "restart", "volume", "shuffle", "clearplaylist", "export", "import", "update", 'replay', 'logs', 'stream', 'fplay', 'schedule', 'record', 'slist', 'cancel', 'cancelall', 'vcpromote', 'vcdemote', 'refresh', 'rtitle', 'seek', 'vcmute', 'unmute', f'stream@{Config.BOT_USERNAME}', f'logs@{Config.BOT_USERNAME}', f"replay@{Config.BOT_USERNAME}", f"yplay@{Config.BOT_USERNAME}", f"leave@{Config.BOT_USERNAME}", f"pause@{Config.BOT_USERNAME}", f"resume@{Config.BOT_USERNAME}", f"skip@{Config.BOT_USERNAME}", f"restart@{Config.BOT_USERNAME}", f"volume@{Config.BOT_USERNAME}", f"shuffle@{Config.BOT_USERNAME}", f"clearplaylist@{Config.BOT_USERNAME}", f"export@{Config.BOT_USERNAME}", f"import@{Config.BOT_USERNAME}", f"update@{Config.BOT_USERNAME}", f'play@{Config.BOT_USERNAME}', f'schedule@{Config.BOT_USERNAME}', f'record@{Config.BOT_USERNAME}', f'slist@{Config.BOT_USERNAME}', f'cancel@{Config.BOT_USERNAME}', f'cancelall@{Config.BOT_USERNAME}', f'vcpromote@{Config.BOT_USERNAME}', -f'vcdemote@{Config.BOT_USERNAME}', f'refresh@{Config.BOT_USERNAME}', f'rtitle@{Config.BOT_USERNAME}', f'seek@{Config.BOT_USERNAME}', f'mute@{Config.BOT_USERNAME}', f'unmute@{Config.BOT_USERNAME}' +f'vcdemote@{Config.BOT_USERNAME}', f'refresh@{Config.BOT_USERNAME}', f'rtitle@{Config.BOT_USERNAME}', f'seek@{Config.BOT_USERNAME}', f'mute@{Config.BOT_USERNAME}', f'vcunmute@{Config.BOT_USERNAME}' ] allcmd = ["play", "player", f"play@{Config.BOT_USERNAME}", f"player@{Config.BOT_USERNAME}"] + admincmds diff --git a/plugins/scheduler.py b/plugins/scheduler.py index 5390c5a3..81ef7c42 100644 --- a/plugins/scheduler.py +++ b/plugins/scheduler.py @@ -120,10 +120,17 @@ async def schedule_vc(bot, message): nyav = now.strftime("%d-%m-%Y-%H:%M:%S") if type in ["video", "audio"]: if type == "audio": + if m_video.title is None: + if m_video.file_name is None: + title_ = "Music" + else: + title_ = m_video.file_name + else: + title_ = m_video.title if m_video.performer is not None: - title = f"{m_video.performer} - {m_video.title}" + title = f"{m_video.performer} - {title_}" else: - title=m_video.title + title=title_ unique = f"{nyav}_{m_video.file_size}_audio" else: title=m_video.file_name @@ -133,6 +140,8 @@ async def schedule_vc(bot, message): title_ = ny.get("title") if title_: title = title_ + if title is None: + title = 'Music' data={'1':title, '2':m_video.file_id, '3':"telegram", '4':user, '5':unique} sid=f"{message.chat.id}_{msg.message_id}" Config.SCHEDULED_STREAM[sid] = data diff --git a/utils/database.py b/utils/database.py index ca6289f6..bb869e02 100644 --- a/utils/database.py +++ b/utils/database.py @@ -22,13 +22,14 @@ def __init__(self): self.db = self._client[Config.DATABASE_NAME] self.col = self.db.config self.playlist = self.db.playlist - def new_config(self, name, value): + def new_config(self, name, value, dvalue): return dict( name = name, + dvalue = dvalue, value = value, ) - def add_config(self, name, value): - config = self.new_config(name, value) + def add_config(self, name, value, dvalue=None): + config = self.new_config(name, value, dvalue) self.col.insert_one(config) def new_song(self, id_, song): @@ -48,6 +49,13 @@ async def is_saved(self, name): async def edit_config(self, name, value): await self.col.update_one({'name': name}, {'$set': {'value': value}}) + + async def edit_default(self, name, dvalue): + await self.col.update_one({'name': name}, {'$set': {'dvalue': dvalue}}) + + async def get_default(self, name): + config = await self.col.find_one({'name':name}) + return config.get('dvalue') async def get_config(self, name): config = await self.col.find_one({'name':name}) diff --git a/utils/utils.py b/utils/utils.py index cdd68818..8c42da8b 100644 --- a/utils/utils.py +++ b/utils/utils.py @@ -107,14 +107,19 @@ async def play(): file=Config.GET_FILE.get(song[5]) if not file: file = await dl.pyro_dl(song[2]) + if not file: + LOGGER.info("Downloading file from telegram") + file = await bot.download_media(song[2]) Config.GET_FILE[song[5]] = file await sleep(3) while not os.path.exists(file): file=Config.GET_FILE.get(song[5]) await sleep(1) - while not (os.stat(file).st_size) >= 0: + total=int(((song[5].split("_"))[1])) * 0.005 + while not (os.stat(file).st_size) >= total: LOGGER.info("Waiting for download") - await sleep(2) + LOGGER.info(str((os.stat(file).st_size))) + await sleep(1) elif song[3] == "url": file=song[2] else: @@ -710,28 +715,25 @@ def is_ytdl_supported(input_url: str) -> bool: async def set_up_startup(): - regex = r"^(?:https?:\/\/)?(?:www\.)?youtu\.?be(?:\.com)?\/?.*(?:watch|embed)?(?:.*v=|v\/|\/)([\w\-_]+)\&?" - # match = re.match(regex, Config.STREAM_URL) - match = is_ytdl_supported(Config.STREAM_URL) Config.YSTREAM=False Config.YPLAY=False Config.CPLAY=False + #regex = r"^(?:https?:\/\/)?(?:www\.)?youtu\.?be(?:\.com)?\/?.*(?:watch|embed)?(?:.*v=|v\/|\/)([\w\-_]+)\&?" + # match = re.match(regex, Config.STREAM_URL) + if Config.STREAM_URL.startswith("@") or (str(Config.STREAM_URL)).startswith("-100"): + Config.CPLAY = True + LOGGER.info(f"Channel Play enabled from {Config.STREAM_URL}") + Config.STREAM_SETUP=True + return + elif Config.STREAM_URL.startswith("https://t.me/DumpPlaylist"): + Config.YPLAY=True + LOGGER.info("YouTube Playlist is set as STARTUP STREAM") + Config.STREAM_SETUP=True + return + match = is_ytdl_supported(Config.STREAM_URL) if match: Config.YSTREAM=True LOGGER.info("YouTube Stream is set as STARTUP STREAM") - elif Config.STREAM_URL.startswith("https://t.me/DumpPlaylist"): - try: - msg_id=Config.STREAM_URL.split("/", 4)[4] - Config.STREAM_URL=int(msg_id) - Config.YPLAY=True - LOGGER.info("YouTube Playlist is set as STARTUP STREAM") - except: - Config.STREAM_URL="http://j78dp346yq5r-hls-live.5centscdn.com/safari/live.stream/playlist.m3u8" - LOGGER.error("Unable to fetch youtube playlist, starting Safari TV") - pass - elif Config.STREAM_URL.startswith("@") or (str(Config.STREAM_URL)).startswith("-100"): - Config.CPLAY = True - LOGGER.info(f"Channel Play enabled from {Config.STREAM_URL}") else: LOGGER.info("Direct link set as STARTUP_STREAM") pass @@ -743,7 +745,12 @@ async def start_stream(): if not Config.STREAM_SETUP: await set_up_startup() if Config.YPLAY: - await y_play(Config.STREAM_URL) + try: + msg_id=Config.STREAM_URL.split("/", 4)[4] + except: + LOGGER.error("Unable to fetch youtube playlist.Recheck your startup stream.") + pass + await y_play(int(msg_id)) return elif Config.CPLAY: await c_play(Config.STREAM_URL) @@ -833,6 +840,7 @@ async def chek_the_media(link, seek=False, pic=False, title="Music"): is_audio_ = False LOGGER.error("Unable to get Audio properties within time.") if not is_audio_: + LOGGER.error("No Audio Source found") Config.STREAM_LINK=False if Config.playlist or Config.STREAM_LINK: await skip() @@ -1241,12 +1249,19 @@ async def c_play(channel): now = datetime.now() nyav = now.strftime("%d-%m-%Y-%H:%M:%S") if filter == "audio": + if you.audio.title is None: + if you.audio.file_name is None: + title_ = "Music" + else: + title_ = you.audio.file_name + else: + title_ = you.audio.title if you.audio.performer is not None: - title = f"{you.audio.performer} - {you.audio.title}" + title = f"{you.audio.performer} - {title_}" else: - title = you.audio.title + title=title_ file_id = you.audio.file_id - unique = f"{nyav}_{m.message_id}_audio" + unique = f"{nyav}_{you.audio.file_size}_audio" elif filter == "video": file_id = you.video.file_id title = you.video.file_name @@ -1255,19 +1270,21 @@ async def c_play(channel): title_ = ny.get("title") if title_: title = title_ - unique = f"{nyav}_{m.message_id}_video" + unique = f"{nyav}_{you.video.file_size}_video" elif filter == "document": if not "video" in you.document.mime_type: LOGGER.info("Skiping Non-Video file") continue file_id=you.document.file_id title = you.document.file_name - unique = f"{nyav}_{m.message_id}_document" + unique = f"{nyav}_{you.document.file_size}_document" if Config.PTN: ny = parse(title) title_ = ny.get("title") if title_: title = title_ + if title is None: + title = "Music" data={1:title, 2:file_id, 3:"telegram", 4:f"[{chat.title}]({you.link})", 5:unique} Config.playlist.append(data) await add_to_db_playlist(data) @@ -1282,8 +1299,6 @@ async def c_play(channel): LOGGER.info(f"Downloading {title}") await download(Config.playlist[0]) await play() - for track in Config.playlist[:2]: - await download(track) if who == 0: LOGGER.warning(f"No files found in {chat.title}, Change filter settings if required. Current filters are {Config.FILTERS}") if Config.CPLAY: @@ -1294,10 +1309,14 @@ async def c_play(channel): await sync_to_db() return False, f"No files found on given channel, Please check your filters.\nCurrent filters are {Config.FILTERS}" else: + if Config.DATABASE_URI: + Config.playlist = await db.get_playlist() if len(Config.playlist) > 2 and Config.SHUFFLE: await shuffle_playlist() if Config.LOG_GROUP: - await send_playlist() + await send_playlist() + for track in Config.playlist[:2]: + await download(track) except Exception as e: LOGGER.error(f"Errors occured while fetching songs from given channel - {e}", exc_info=True) if Config.CPLAY: @@ -1590,59 +1609,16 @@ async def delete_messages(messages): #Database Config async def sync_to_db(): if Config.DATABASE_URI: - await check_db() - await db.edit_config("ADMINS", Config.ADMINS) - await db.edit_config("IS_VIDEO", Config.IS_VIDEO) - await db.edit_config("IS_LOOP", Config.IS_LOOP) - await db.edit_config("REPLY_PM", Config.REPLY_PM) - await db.edit_config("ADMIN_ONLY", Config.ADMIN_ONLY) - await db.edit_config("SHUFFLE", Config.SHUFFLE) - await db.edit_config("EDIT_TITLE", Config.EDIT_TITLE) - await db.edit_config("CHAT", Config.CHAT) - await db.edit_config("SUDO", Config.SUDO) - await db.edit_config("REPLY_MESSAGE", Config.REPLY_MESSAGE) - await db.edit_config("LOG_GROUP", Config.LOG_GROUP) - await db.edit_config("STREAM_URL", Config.STREAM_URL) - await db.edit_config("DELAY", Config.DELAY) - await db.edit_config("SCHEDULED_STREAM", Config.SCHEDULED_STREAM) - await db.edit_config("SCHEDULE_LIST", Config.SCHEDULE_LIST) - await db.edit_config("IS_VIDEO_RECORD", Config.IS_VIDEO_RECORD) - await db.edit_config("IS_RECORDING", Config.IS_RECORDING) - await db.edit_config("WAS_RECORDING", Config.WAS_RECORDING) - await db.edit_config("PORTRAIT", Config.PORTRAIT) - 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) - + await check_db() + for var in Config.CONFIG_LIST: + await db.edit_config(var, getattr(Config, var)) async def sync_from_db(): if Config.DATABASE_URI: - await check_db() - Config.ADMINS = await db.get_config("ADMINS") - Config.IS_VIDEO = await db.get_config("IS_VIDEO") - Config.IS_LOOP = await db.get_config("IS_LOOP") - Config.REPLY_PM = await db.get_config("REPLY_PM") - Config.ADMIN_ONLY = await db.get_config("ADMIN_ONLY") - Config.SHUFFLE = await db.get_config("SHUFFLE") - Config.EDIT_TITLE = await db.get_config("EDIT_TITLE") - Config.CHAT = int(await db.get_config("CHAT")) + await check_db() + for var in Config.CONFIG_LIST: + setattr(Config, var, await db.get_config(var)) Config.playlist = await db.get_playlist() - Config.LOG_GROUP = await db.get_config("LOG_GROUP") - Config.SUDO = await db.get_config("SUDO") - Config.REPLY_MESSAGE = await db.get_config("REPLY_MESSAGE") - Config.DELAY = await db.get_config("DELAY") - Config.STREAM_URL = await db.get_config("STREAM_URL") - Config.SCHEDULED_STREAM = await db.get_config("SCHEDULED_STREAM") - Config.SCHEDULE_LIST = await db.get_config("SCHEDULE_LIST") - Config.IS_VIDEO_RECORD = await db.get_config('IS_VIDEO_RECORD') - Config.IS_RECORDING = await db.get_config("IS_RECORDING") - Config.WAS_RECORDING = await db.get_config('WAS_RECORDING') - Config.PORTRAIT = await db.get_config("PORTRAIT") - 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: @@ -1657,52 +1633,25 @@ async def clear_db_playlist(song=None, all=False): await db.del_song(song[5]) async def check_db(): - if not await db.is_saved("ADMINS"): - db.add_config("ADMINS", Config.ADMINS) - if not await db.is_saved("IS_VIDEO"): - db.add_config("IS_VIDEO", Config.IS_VIDEO) - if not await db.is_saved("IS_LOOP"): - db.add_config("IS_LOOP", Config.IS_LOOP) - if not await db.is_saved("REPLY_PM"): - db.add_config("REPLY_PM", Config.REPLY_PM) - if not await db.is_saved("ADMIN_ONLY"): - db.add_config("ADMIN_ONLY", Config.ADMIN_ONLY) - if not await db.is_saved("SHUFFLE"): - db.add_config("SHUFFLE", Config.SHUFFLE) - if not await db.is_saved("EDIT_TITLE"): - db.add_config("EDIT_TITLE", Config.EDIT_TITLE) - if not await db.is_saved("CHAT"): - db.add_config("CHAT", Config.CHAT) - if not await db.is_saved("SUDO"): - db.add_config("SUDO", Config.SUDO) - if not await db.is_saved("REPLY_MESSAGE"): - db.add_config("REPLY_MESSAGE", Config.REPLY_MESSAGE) - if not await db.is_saved("STREAM_URL"): - db.add_config("STREAM_URL", Config.STREAM_URL) - if not await db.is_saved("DELAY"): - db.add_config("DELAY", Config.DELAY) - if not await db.is_saved("LOG_GROUP"): - db.add_config("LOG_GROUP", Config.LOG_GROUP) - if not await db.is_saved("SCHEDULED_STREAM"): - db.add_config("SCHEDULED_STREAM", Config.SCHEDULED_STREAM) - if not await db.is_saved("SCHEDULE_LIST"): - db.add_config("SCHEDULE_LIST", Config.SCHEDULE_LIST) - if not await db.is_saved("IS_VIDEO_RECORD"): - db.add_config("IS_VIDEO_RECORD", Config.IS_VIDEO_RECORD) - if not await db.is_saved("PORTRAIT"): - db.add_config("PORTRAIT", Config.PORTRAIT) - if not await db.is_saved("IS_RECORDING"): - db.add_config("IS_RECORDING", Config.IS_RECORDING) - if not await db.is_saved('WAS_RECORDING'): - db.add_config('WAS_RECORDING', Config.WAS_RECORDING) - if not await db.is_saved("RECORDING_DUMP"): - db.add_config("RECORDING_DUMP", Config.RECORDING_DUMP) - if not await db.is_saved("RECORDING_TITLE"): - 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) + for var in Config.CONFIG_LIST: + if not await db.is_saved(var): + db.add_config(var, getattr(Config, var)) + +async def check_changes(): + if Config.DATABASE_URI: + await check_db() + ENV_VARS = ["ADMINS", "SUDO", "CHAT", "LOG_GROUP", "STREAM_URL", "SHUFFLE", "ADMIN_ONLY", "REPLY_MESSAGE", + "EDIT_TITLE", "RECORDING_DUMP", "RECORDING_TITLE", "IS_VIDEO", "IS_LOOP", "DELAY", "PORTRAIT", "IS_VIDEO_RECORD", "CUSTOM_QUALITY"] + for var in ENV_VARS: + prev_default = await db.get_default(var) + if prev_default is None: + await db.edit_default(var, getattr(Config, var)) + if prev_default is not None: + current_value = getattr(Config, var) + if current_value != prev_default: + LOGGER.info("ENV change detected, Changing value in database.") + await db.edit_config(var, current_value) + await db.edit_default(var, current_value) async def is_audio(file): @@ -1731,12 +1680,20 @@ async def get_height_and_width(file): process = await asyncio.create_subprocess_exec( *ffprobe_cmd, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE ) - output = await process.communicate() - stream = output[0].decode('utf-8') + output, err = await process.communicate() + stream = output.decode('utf-8') out = json.loads(stream) try: n = out.get("streams") if not n: + LOGGER.error(err.decode()) + if os.path.isfile(file):#if ts a file, its a tg file + LOGGER.info("Play from DC6 Failed, Downloading the file") + total=int((((Config.playlist[0][5]).split("_"))[1])) + while not (os.stat(file).st_size) >= total: + LOGGER.info(f"Downloading {Config.playlist[0][1]} - Completed - {round(((int(os.stat(file).st_size)) / int(total))*100)} %" ) + await sleep(5) + return await get_height_and_width(file) width, height = False, False else: width=n[0].get("width")