diff --git a/program/video_stream.py b/program/video_stream.py index cd9bb07..6938025 100644 --- a/program/video_stream.py +++ b/program/video_stream.py @@ -36,7 +36,6 @@ from pyrogram import Client from pyrogram.errors import UserAlreadyParticipant, UserNotParticipant from pyrogram.types import InlineKeyboardMarkup, Message -from pytgcalls import idle from pytgcalls import StreamType from pytgcalls.types.input_stream import AudioVideoPiped from pytgcalls.types.input_stream.quality import ( @@ -45,6 +44,7 @@ from pytgcalls.types.input_stream.quality import ( LowQualityVideo, MediumQualityVideo, ) +from pytgcalls.exceptions import NoVideoSourceFound, NoActiveGroupCall, GroupCallNotFound from youtubesearchpython import VideosSearch @@ -152,6 +152,7 @@ async def play_tg_file(c: Client, m: Message, replied: Message = None, link: str ) remove_if_exists(image) else: + try: await loser.edit("šŸ”„ Joining Group Call...") gcname = m.chat.title ctitle = await CHAT_TITLE(gcname) @@ -187,8 +188,12 @@ async def play_tg_file(c: Client, m: Message, replied: Message = None, link: str f"ā±ļø **Duration:** `{duration}`\n" f"šŸ§ø **Request by:** {requester}", ) - await idle() remove_if_exists(image) + except (NoActiveGroupCall, GroupCallNotFound): + await suhu.delete() + await remove_active_chat(chat_id) + traceback.print_exc() + await m.reply_text("āŒ The bot can't find the Group call or it's inactive.\n\nĀ» Use /startvc command to turn on the Group call !") else: await m.reply( "Ā» reply to an **video file** or **give something to search.**" @@ -210,16 +215,17 @@ async def vplay(c: Client, m: Message): try: ubot = me_user.id b = await c.get_chat_member(chat_id, ubot) - if b.status == "kicked": - await c.unban_chat_member(chat_id, ubot) + if b.status == "banned": + await m.reply_text("āŒ The userbot is banned in this chat, unban the userbot first to be able to play music !") + return + invitelink = (await c.get_chat(chat_id)).invite_link + if not invitelink: + await c.export_chat_invite_link(chat_id) invitelink = (await c.get_chat(chat_id)).invite_link - if not invitelink: - await c.export_chat_invite_link(chat_id) - invitelink = (await c.get_chat(chat_id)).invite_link - if invitelink.startswith("https://t.me/+"): - invitelink = invitelink.replace( - "https://t.me/+", "https://t.me/joinchat/" - ) + if invitelink.startswith("https://t.me/+"): + invitelink = invitelink.replace( + "https://t.me/+", "https://t.me/joinchat/" + ) await user.join_chat(invitelink) await remove_active_chat(chat_id) except UserNotParticipant: @@ -308,12 +314,19 @@ async def vplay(c: Client, m: Message): reply_markup=InlineKeyboardMarkup(buttons), caption=f"šŸ—‚ **Name:** [{songname}]({url}) | `video`\nā± **Duration:** `{duration}`\nšŸ§ø **Request by:** {requester}", ) - await idle() remove_if_exists(image) - except Exception as ep: + except (NoActiveGroupCall, GroupCallNotFound): await loser.delete() await remove_active_chat(chat_id) - await m.reply_text(f"šŸš« error: `{ep}`") + await m.reply_text("āŒ The bot can't find the Group call or it's inactive.\n\nĀ» Use /startvc command to turn on the Group call !") + except NoVideoSourceFound: + await suhu.delete() + await remove_active_chat(chat_id) + await m.reply_text("āŒ The content you provide to play has no video source") + except NoAudioSourceFound: + await suhu.delete() + await remove_active_chat(chat_id) + await m.reply_text("āŒ The content you provide to play has no audio source") else: if len(m.command) < 2: @@ -384,12 +397,19 @@ async def vplay(c: Client, m: Message): reply_markup=InlineKeyboardMarkup(buttons), caption=f"šŸ—‚ **Name:** [{songname}]({url}) | `video`\nā± **Duration:** `{duration}`\nšŸ§ø **Request by:** {requester}", ) - await idle() remove_if_exists(image) - except Exception as ep: + except (NoActiveGroupCall, GroupCallNotFound): await loser.delete() await remove_active_chat(chat_id) - await m.reply_text(f"šŸš« error: `{ep}`") + await m.reply_text("āŒ The bot can't find the Group call or it's inactive.\n\nĀ» Use /startvc command to turn on the Group call !") + except NoVideoSourceFound: + await suhu.delete() + await remove_active_chat(chat_id) + await m.reply_text("āŒ The content you provide to play has no video source") + except NoAudioSourceFound: + await suhu.delete() + await remove_active_chat(chat_id) + await m.reply_text("āŒ The content you provide to play has no audio source") @Client.on_message(command(["vstream", f"vstream@{BOT_USERNAME}"]) & other_filters) @@ -406,16 +426,17 @@ async def vstream(c: Client, m: Message): try: ubot = me_user.id b = await c.get_chat_member(chat_id, ubot) - if b.status == "kicked": - await c.unban_chat_member(chat_id, ubot) + if b.status == "banned": + await m.reply_text("āŒ The userbot is banned in this chat, unban the userbot first to be able to play music !") + return + invitelink = (await c.get_chat(chat_id)).invite_link + if not invitelink: + await c.export_chat_invite_link(chat_id) invitelink = (await c.get_chat(chat_id)).invite_link - if not invitelink: - await c.export_chat_invite_link(chat_id) - invitelink = (await c.get_chat(chat_id)).invite_link - if invitelink.startswith("https://t.me/+"): - invitelink = invitelink.replace( - "https://t.me/+", "https://t.me/joinchat/" - ) + if invitelink.startswith("https://t.me/+"): + invitelink = invitelink.replace( + "https://t.me/+", "https://t.me/joinchat/" + ) await user.join_chat(invitelink) await remove_active_chat(chat_id) except UserNotParticipant: @@ -517,8 +538,11 @@ async def vstream(c: Client, m: Message): reply_markup=InlineKeyboardMarkup(buttons), caption=f"šŸ—‚ **Name:** [{songname}]({url}) | `live`\nšŸ§ø **Requested by:** {requester}", ) - await idle() - except Exception as ep: + except (NoActiveGroupCall, GroupCallNotFound): await loser.delete() await remove_active_chat(chat_id) - await m.reply_text(f"šŸš« error: `{ep}`") + await m.reply_text("āŒ The bot can't find the Group call or it's inactive.\n\nĀ» Use /startvc command to turn on the Group call !") + except BaseException as err: + await loser.delete() + await remove_active_chat(chat_id) + await m.reply_text(f"šŸš« error: `{err}`")