diff --git a/driver/utils.py b/driver/utils.py index d3a1234..3af746a 100644 --- a/driver/utils.py +++ b/driver/utils.py @@ -1,33 +1,26 @@ -import os import asyncio + +from driver.queues import QUEUE, clear_queue, get_queue, pop_an_item from driver.veez import bot, call_py +from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup from pytgcalls.types import Update from pytgcalls.types.input_stream import AudioPiped, AudioVideoPiped -from driver.queues import QUEUE, clear_queue, get_queue, pop_an_item from pytgcalls.types.input_stream.quality import ( HighQualityAudio, HighQualityVideo, LowQualityVideo, MediumQualityVideo, ) -from pyrogram.types import ( - CallbackQuery, - InlineKeyboardButton, - InlineKeyboardMarkup, - Message, -) -from pyrogram import Client, filters -from pytgcalls.types.stream import StreamAudioEnded, StreamVideoEnded - +from pytgcalls.types.stream import StreamAudioEnded keyboard = InlineKeyboardMarkup( + [ [ - [ - InlineKeyboardButton(text="• Mᴇɴᴜ", callback_data="cbmenu"), - InlineKeyboardButton(text="• Cʟᴏsᴇ", callback_data="cls"), - ] + InlineKeyboardButton(text="• Mᴇɴᴜ", callback_data="cbmenu"), + InlineKeyboardButton(text="• Cʟᴏsᴇ", callback_data="cls"), ] - ) + ] +) async def skip_current_song(chat_id): @@ -110,14 +103,22 @@ async def stream_end_handler(_, u: Update): chat_id = u.chat_id print(chat_id) op = await skip_current_song(chat_id) - if op==1: - await bot.send_message(chat_id, "✅ streaming end") - elif op==2: - await bot.send_message(chat_id, "❌ an error occurred\n\n» **Clearing** __Queues__ and leaving video chat.") + if op == 1: + await bot.send_message(chat_id, "✅ streaming end") + elif op == 2: + await bot.send_message( + chat_id, + "❌ an error occurred\n\n» **Clearing** __Queues__ and leaving video chat.", + ) else: - await bot.send_message(chat_id, f"💡 **Streaming next track**\n\n🗂 **Name:** [{op[0]}]({op[1]}) | `{op[2]}`\n💭 **Chat:** `{chat_id}`", disable_web_page_preview=True, reply_markup=keyboard) + await bot.send_message( + chat_id, + f"💡 **Streaming next track**\n\n🗂 **Name:** [{op[0]}]({op[1]}) | `{op[2]}`\n💭 **Chat:** `{chat_id}`", + disable_web_page_preview=True, + reply_markup=keyboard, + ) else: - pass + pass async def bash(cmd): diff --git a/program/music.py b/program/music.py index 13ac7d7..41d8ea0 100644 --- a/program/music.py +++ b/program/music.py @@ -2,25 +2,27 @@ # Commit Start Date 20/10/2021 # Finished On 28/10/2021 +from config import BOT_USERNAME, IMG_1, IMG_2 +from driver.design.chatname import CHAT_TITLE +from driver.design.thumbnail import thumb +from driver.filters import command, other_filters +from driver.queues import QUEUE, add_to_queue +from driver.utils import bash +from driver.veez import call_py, user + +# repository stuff +from program.utils.inline import stream_markup + # important things -import re -import asyncio # pyrogram stuff from pyrogram import Client from pyrogram.errors import UserAlreadyParticipant, UserNotParticipant -from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup, Message +from pyrogram.types import InlineKeyboardMarkup, Message + # pytgcalls stuff from pytgcalls import StreamType from pytgcalls.types.input_stream import AudioPiped -# repository stuff -from program.utils.inline import stream_markup -from driver.design.thumbnail import thumb -from driver.design.chatname import CHAT_TITLE -from driver.filters import command, other_filters -from driver.queues import QUEUE, add_to_queue -from driver.veez import call_py, user -from driver.utils import bash -from config import ASSISTANT_NAME, BOT_USERNAME, IMG_1, IMG_2 + # youtube-dl stuff from youtubesearchpython import VideosSearch @@ -39,10 +41,12 @@ def ytsearch(query: str): return 0 -async def ytdl(format: str, link: str): - stdout, stderr = await bash(f'youtube-dl -g -f "{format}" {link}') +async def ytdl(link: str): + stdout, stderr = await bash( + f'youtube-dl -g -f "best[height<=?720][width<=?1280]" {link}' + ) if stdout: - return 1, stdout.split("\n")[0] + return 1, stdout return 0, stderr @@ -53,7 +57,9 @@ async def play(c: Client, m: Message): chat_id = m.chat.id user_id = m.from_user.id if m.sender_chat: - return await m.reply_text("you're an __Anonymous__ Admin !\n\n» revert back to user account from admin rights.") + return await m.reply_text( + "you're an __Anonymous__ Admin !\n\n» revert back to user account from admin rights." + ) try: aing = await c.get_me() except Exception as e: @@ -66,37 +72,40 @@ async def play(c: Client, m: Message): return if not a.can_manage_voice_chats: await m.reply_text( - "💡 To use me, Give me the following permission below:" - + "\n\n» ❌ __Manage video chat__\n\nOnce done, try again.") + "💡 To use me, Give me the following permission below:" + + "\n\n» ❌ __Manage video chat__\n\nOnce done, try again." + ) return if not a.can_delete_messages: await m.reply_text( - "💡 To use me, Give me the following permission below:" - + "\n\n» ❌ __Delete messages__\n\nOnce done, try again.") + "💡 To use me, Give me the following permission below:" + + "\n\n» ❌ __Delete messages__\n\nOnce done, try again." + ) return if not a.can_invite_users: await m.reply_text( - "💡 To use me, Give me the following permission below:" - + "\n\n» ❌ __Add users__\n\nOnce done, try again.") + "💡 To use me, Give me the following permission below:" + + "\n\n» ❌ __Add users__\n\nOnce done, try again." + ) return try: ubot = (await user.get_me()).id - b = await c.get_chat_member(chat_id, ubot) + b = await c.get_chat_member(chat_id, ubot) if b.status == "kicked": await c.unban_chat_member(chat_id, ubot) invitelink = await c.export_chat_invite_link(chat_id) if invitelink.startswith("https://t.me/+"): - invitelink = invitelink.replace( - "https://t.me/+", "https://t.me/joinchat/" - ) + invitelink = invitelink.replace( + "https://t.me/+", "https://t.me/joinchat/" + ) await user.join_chat(invitelink) except UserNotParticipant: try: invitelink = await c.export_chat_invite_link(chat_id) if invitelink.startswith("https://t.me/+"): - invitelink = invitelink.replace( - "https://t.me/+", "https://t.me/joinchat/" - ) + invitelink = invitelink.replace( + "https://t.me/+", "https://t.me/joinchat/" + ) await user.join_chat(invitelink) except UserAlreadyParticipant: pass @@ -130,27 +139,29 @@ async def play(c: Client, m: Message): caption=f"💡 **Track added to queue »** `{pos}`\n\n🗂 **Name:** [{songname}]({link}) | `music`\n💭 **Chat:** `{chat_id}`\n🧸 **Request by:** {requester}", ) else: - try: - await suhu.edit("🔄 **Joining vc...**") - await call_py.join_group_call( - chat_id, - AudioPiped( - dl, - ), - stream_type=StreamType().local_stream, - ) - add_to_queue(chat_id, songname, dl, link, "Audio", 0) - await suhu.delete() - buttons = stream_markup(user_id) - requester = f"[{m.from_user.first_name}](tg://user?id={m.from_user.id})" - await m.reply_photo( - photo=f"{IMG_2}", - reply_markup=InlineKeyboardMarkup(buttons), - caption=f"🗂 **Name:** [{songname}]({link}) | `music`\n💭 **Chat:** `{chat_id}`\n🧸 **Request by:** {requester}", - ) - except Exception as e: - await suhu.delete() - await m.reply_text(f"🚫 error:\n\n» {e}") + try: + await suhu.edit("🔄 **Joining vc...**") + await call_py.join_group_call( + chat_id, + AudioPiped( + dl, + ), + stream_type=StreamType().local_stream, + ) + add_to_queue(chat_id, songname, dl, link, "Audio", 0) + await suhu.delete() + buttons = stream_markup(user_id) + requester = ( + f"[{m.from_user.first_name}](tg://user?id={m.from_user.id})" + ) + await m.reply_photo( + photo=f"{IMG_2}", + reply_markup=InlineKeyboardMarkup(buttons), + caption=f"🗂 **Name:** [{songname}]({link}) | `music`\n💭 **Chat:** `{chat_id}`\n🧸 **Request by:** {requester}", + ) + except Exception as e: + await suhu.delete() + await m.reply_text(f"🚫 error:\n\n» {e}") else: if len(m.command) < 2: await m.reply( @@ -172,8 +183,7 @@ async def play(c: Client, m: Message): gcname = m.chat.title ctitle = await CHAT_TITLE(gcname) image = await thumb(thumbnail, title, userid, ctitle) - format = "bestaudio[ext=m4a]" - veez, ytlink = await ytdl(format, url) + veez, ytlink = await ytdl(url) if veez == 0: await suhu.edit(f"❌ yt-dl issues detected\n\n» `{ytlink}`") else: @@ -233,15 +243,16 @@ async def play(c: Client, m: Message): gcname = m.chat.title ctitle = await CHAT_TITLE(gcname) image = await thumb(thumbnail, title, userid, ctitle) - format = "bestaudio[ext=m4a]" - veez, ytlink = await ytdl(format, url) + veez, ytlink = await ytdl(url) if veez == 0: await suhu.edit(f"❌ yt-dl issues detected\n\n» `{ytlink}`") else: if chat_id in QUEUE: pos = add_to_queue(chat_id, songname, ytlink, url, "Audio", 0) await suhu.delete() - requester = f"[{m.from_user.first_name}](tg://user?id={m.from_user.id})" + requester = ( + f"[{m.from_user.first_name}](tg://user?id={m.from_user.id})" + ) buttons = stream_markup(user_id) await m.reply_photo( photo=image, diff --git a/program/video.py b/program/video.py index 746db9e..1f90dd7 100644 --- a/program/video.py +++ b/program/video.py @@ -2,19 +2,19 @@ # Commit Start Date 20/10/2021 # Finished On 28/10/2021 -import re import asyncio +import re -from config import ASSISTANT_NAME, BOT_USERNAME, IMG_1, IMG_2 -from program.utils.inline import stream_markup -from driver.design.thumbnail import thumb +from config import BOT_USERNAME, IMG_1, IMG_2 from driver.design.chatname import CHAT_TITLE +from driver.design.thumbnail import thumb from driver.filters import command, other_filters from driver.queues import QUEUE, add_to_queue from driver.veez import call_py, user +from program.utils.inline import stream_markup from pyrogram import Client from pyrogram.errors import UserAlreadyParticipant, UserNotParticipant -from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup, Message +from pyrogram.types import InlineKeyboardMarkup, Message from pytgcalls import StreamType from pytgcalls.types.input_stream import AudioVideoPiped from pytgcalls.types.input_stream.quality import ( @@ -64,7 +64,9 @@ async def vplay(c: Client, m: Message): chat_id = m.chat.id user_id = m.from_user.id if m.sender_chat: - return await m.reply_text("you're an __Anonymous__ Admin !\n\n» revert back to user account from admin rights.") + return await m.reply_text( + "you're an __Anonymous__ Admin !\n\n» revert back to user account from admin rights." + ) try: aing = await c.get_me() except Exception as e: @@ -77,37 +79,40 @@ async def vplay(c: Client, m: Message): return if not a.can_manage_voice_chats: await m.reply_text( - "💡 To use me, Give me the following permission below:" - + "\n\n» ❌ __Manage video chat__\n\nOnce done, try again.") + "💡 To use me, Give me the following permission below:" + + "\n\n» ❌ __Manage video chat__\n\nOnce done, try again." + ) return if not a.can_delete_messages: await m.reply_text( - "💡 To use me, Give me the following permission below:" - + "\n\n» ❌ __Delete messages__\n\nOnce done, try again.") + "💡 To use me, Give me the following permission below:" + + "\n\n» ❌ __Delete messages__\n\nOnce done, try again." + ) return if not a.can_invite_users: await m.reply_text( - "💡 To use me, Give me the following permission below:" - + "\n\n» ❌ __Add users__\n\nOnce done, try again.") + "💡 To use me, Give me the following permission below:" + + "\n\n» ❌ __Add users__\n\nOnce done, try again." + ) return try: ubot = (await user.get_me()).id - b = await c.get_chat_member(chat_id, ubot) + b = await c.get_chat_member(chat_id, ubot) if b.status == "kicked": await c.unban_chat_member(chat_id, ubot) invitelink = await c.export_chat_invite_link(chat_id) if invitelink.startswith("https://t.me/+"): - invitelink = invitelink.replace( - "https://t.me/+", "https://t.me/joinchat/" - ) + invitelink = invitelink.replace( + "https://t.me/+", "https://t.me/joinchat/" + ) await user.join_chat(invitelink) except UserNotParticipant: try: invitelink = await c.export_chat_invite_link(chat_id) if invitelink.startswith("https://t.me/+"): - invitelink = invitelink.replace( - "https://t.me/+", "https://t.me/joinchat/" - ) + invitelink = invitelink.replace( + "https://t.me/+", "https://t.me/joinchat/" + ) await user.join_chat(invitelink) except UserAlreadyParticipant: pass @@ -270,7 +275,9 @@ async def vplay(c: Client, m: Message): if chat_id in QUEUE: pos = add_to_queue(chat_id, songname, ytlink, url, "Video", Q) await loser.delete() - requester = f"[{m.from_user.first_name}](tg://user?id={m.from_user.id})" + requester = ( + f"[{m.from_user.first_name}](tg://user?id={m.from_user.id})" + ) buttons = stream_markup(user_id) await m.reply_photo( photo=image, @@ -309,7 +316,9 @@ async def vstream(c: Client, m: Message): chat_id = m.chat.id user_id = m.from_user.id if m.sender_chat: - return await m.reply_text("you're an __Anonymous__ Admin !\n\n» revert back to user account from admin rights.") + return await m.reply_text( + "you're an __Anonymous__ Admin !\n\n» revert back to user account from admin rights." + ) try: aing = await c.get_me() except Exception as e: @@ -322,37 +331,40 @@ async def vstream(c: Client, m: Message): return if not a.can_manage_voice_chats: await m.reply_text( - "💡 To use me, Give me the following permission below:" - + "\n\n» ❌ __Manage video chat__\n\nOnce done, try again.") + "💡 To use me, Give me the following permission below:" + + "\n\n» ❌ __Manage video chat__\n\nOnce done, try again." + ) return if not a.can_delete_messages: await m.reply_text( - "💡 To use me, Give me the following permission below:" - + "\n\n» ❌ __Delete messages__\n\nOnce done, try again.") + "💡 To use me, Give me the following permission below:" + + "\n\n» ❌ __Delete messages__\n\nOnce done, try again." + ) return if not a.can_invite_users: await m.reply_text( - "💡 To use me, Give me the following permission below:" - + "\n\n» ❌ __Add users__\n\nOnce done, try again.") + "💡 To use me, Give me the following permission below:" + + "\n\n» ❌ __Add users__\n\nOnce done, try again." + ) return try: ubot = (await user.get_me()).id - b = await c.get_chat_member(chat_id, ubot) + b = await c.get_chat_member(chat_id, ubot) if b.status == "kicked": await c.unban_chat_member(chat_id, ubot) invitelink = await c.export_chat_invite_link(chat_id) if invitelink.startswith("https://t.me/+"): - invitelink = invitelink.replace( - "https://t.me/+", "https://t.me/joinchat/" - ) + invitelink = invitelink.replace( + "https://t.me/+", "https://t.me/joinchat/" + ) await user.join_chat(invitelink) except UserNotParticipant: try: invitelink = await c.export_chat_invite_link(chat_id) if invitelink.startswith("https://t.me/+"): - invitelink = invitelink.replace( - "https://t.me/+", "https://t.me/joinchat/" - ) + invitelink = invitelink.replace( + "https://t.me/+", "https://t.me/joinchat/" + ) await user.join_chat(invitelink) except UserAlreadyParticipant: pass @@ -424,7 +436,9 @@ async def vstream(c: Client, m: Message): ) add_to_queue(chat_id, "Live Stream", livelink, link, "Video", Q) await loser.delete() - requester = f"[{m.from_user.first_name}](tg://user?id={m.from_user.id})" + requester = ( + f"[{m.from_user.first_name}](tg://user?id={m.from_user.id})" + ) buttons = stream_markup(user_id) await m.reply_photo( photo=f"{IMG_2}",