diff --git a/driver/core.py b/driver/core.py index 6686a4b..07d9d84 100644 --- a/driver/core.py +++ b/driver/core.py @@ -1,6 +1,4 @@ -import asyncio from pyrogram import Client -from pyrogram.types import User from pytgcalls import PyTgCalls from config import API_HASH, API_ID, BOT_TOKEN, SESSION_NAME @@ -9,7 +7,8 @@ bot = Client( ":veez:", API_ID, API_HASH, - bot_token=BOT_TOKEN + bot_token=BOT_TOKEN, + plugins={"root": "program"}, ) user = Client( @@ -20,15 +19,7 @@ user = Client( calls = PyTgCalls(user, overload_quiet_mode=True) -with bot as app: +with Client(":veez:", API_ID, API_HASH, bot_token=BOT_TOKEN) as app: me_bot = app.get_me() with user as app: me_user = app.get_me() - -bot = Client( # type: ignore - ":veez:", - API_ID, - API_HASH, - bot_token=BOT_TOKEN, - plugins={"root": "program"}, -) diff --git a/driver/utils.py b/driver/utils.py index c56a33a..8db3b24 100644 --- a/driver/utils.py +++ b/driver/utils.py @@ -1,6 +1,8 @@ import asyncio import os -from driver.core import bot, calls + +from config import IMG_5 +from driver.core import bot, calls, user from driver.database.dbqueue import remove_active_chat from driver.queues import ( QUEUE, @@ -158,3 +160,14 @@ async def bash(cmd): def remove_if_exists(path): if os.path.exists(path): os.remove(path) + + +async def from_tg_get_msg(url: str): + data = url.split('/')[-2:] + if len(data) == 2: + cid = data[0] + if cid.isdigit(): + cid = int('-100' + cid) + mid = int(data[1]) + return await user.get_messages(cid, message_ids=mid) + return None diff --git a/program/admins.py b/program/admins.py index 8c2f540..aeb27e1 100644 --- a/program/admins.py +++ b/program/admins.py @@ -9,7 +9,6 @@ from driver.queues import QUEUE, clear_queue from driver.filters import command, other_filters from driver.decorators import authorized_users_only, check_blacklist from driver.utils import skip_current_song, skip_item, remove_if_exists -from driver.database.dbpunish import is_gbanned_user from driver.database.dbqueue import ( is_music_playing, diff --git a/program/callback.py b/program/callback.py index a2f4d03..f983e6a 100644 --- a/program/callback.py +++ b/program/callback.py @@ -3,7 +3,6 @@ from driver.core import me_bot from driver.decorators import check_blacklist from driver.queues import QUEUE -from driver.database.dbpunish import is_gbanned_user from pyrogram import Client, filters from program.utils.inline import menu_markup, stream_markup from pyrogram.types import CallbackQuery, InlineKeyboardButton, InlineKeyboardMarkup diff --git a/program/music.py b/program/music.py index ee3df87..03bd19f 100644 --- a/program/music.py +++ b/program/music.py @@ -20,10 +20,8 @@ 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.core import calls, user, bot, me_user -from driver.utils import bash, remove_if_exists -from driver.database.dbpunish import is_gbanned_user -from driver.database.dblockchat import blacklisted_chats +from driver.core import calls, user, me_user +from driver.utils import bash, remove_if_exists, from_tg_get_msg from driver.database.dbqueue import add_active_chat, remove_active_chat, music_on from config import BOT_USERNAME, IMG_5 # youtube-dl stuff @@ -61,6 +59,111 @@ def convert_seconds(seconds): return "%02d:%02d" % (minutes, seconds) +async def play_tg_file(c: Client, m: Message, replied: Message = None, link: str = None): + chat_id = m.chat.id + user_id = m.from_user.id + if link: + try: + replied = await from_tg_get_msg(link) + except Exception as e: + traceback.print_exc() + return await m.reply_text(f"๐Ÿšซ error:\n\nยป {e}") + if not replied: + return await m.reply( + "ยป reply to an **audio file** or **give something to search.**" + ) + if replied.audio or replied.voice: + if not link: + suhu = await replied.reply("๐Ÿ“ฅ downloading audio...") + else: + suhu = await m.reply("๐Ÿ“ฅ downloading audio...") + dl = await replied.download() + link = replied.link + songname = "Audio" + thumbnail = f"{IMG_5}" + duration = "00:00" + try: + if replied.audio: + if replied.audio.title: + songname = replied.audio.title[:80] + else: + songname = replied.audio.file_name[:80] + if replied.audio.thumbs: + if not link: + thumbnail = await c.download_media(replied.audio.thumbs[0].file_id) + else: + thumbnail = await user.download_media(replied.audio.thumbs[0].file_id) + duration = convert_seconds(replied.audio.duration) + elif replied.voice: + songname = "Voice Note" + duration = convert_seconds(replied.voice.duration) + except BaseException: + pass + + if chat_id in QUEUE: + await suhu.edit("๐Ÿ”„ Queueing Track...") + gcname = m.chat.title + ctitle = await CHAT_TITLE(gcname) + title = songname + userid = m.from_user.id + image = await thumb(thumbnail, title, userid, ctitle) + pos = add_to_queue(chat_id, songname, dl, link, "Audio", 0) + requester = f"[{m.from_user.first_name}](tg://user?id={m.from_user.id})" + buttons = stream_markup(user_id) + await suhu.delete() + await m.reply_photo( + photo=image, + reply_markup=InlineKeyboardMarkup(buttons), + caption=f"๐Ÿ’ก **Track added to queue ยป** `{pos}`\n\n" + f"๐Ÿ—‚ **Name:** [{songname}]({link}) | `music`\n" + f"โฑ๏ธ **Duration:** `{duration}`\n" + f"๐Ÿงธ **Request by:** {requester}", + ) + remove_if_exists(image) + else: + try: + gcname = m.chat.title + ctitle = await CHAT_TITLE(gcname) + title = songname + userid = m.from_user.id + image = await thumb(thumbnail, title, userid, ctitle) + await suhu.edit("๐Ÿ”„ Joining Group Call...") + await music_on(chat_id) + await add_active_chat(chat_id) + await calls.join_group_call( + chat_id, + AudioPiped( + dl, + HighQualityAudio(), + ), + stream_type=StreamType().pulse_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=image, + reply_markup=InlineKeyboardMarkup(buttons), + caption=f"๐Ÿ—‚ **Name:** [{songname}]({link}) | `music`\n" + f"โฑ๏ธ **Duration:** `{duration}`\n" + f"๐Ÿงธ **Request by:** {requester}", + ) + await idle() + remove_if_exists(image) + except Exception as e: + await suhu.delete() + await remove_active_chat(chat_id) + traceback.print_exc() + await m.reply_text(f"๐Ÿšซ error:\n\nยป {e}") + else: + await m.reply( + "ยป reply to an **audio file** or **give something to search.**" + ) + + @Client.on_message(command(["play", f"play@{BOT_USERNAME}"]) & other_filters) @check_blacklist() @require_admin(permissions=["can_manage_voice_chats", "can_delete_messages", "can_invite_users"], self=True) @@ -109,79 +212,7 @@ async def play(c: Client, m: Message): ) if replied: if replied.audio or replied.voice: - suhu = await replied.reply("๐Ÿ“ฅ downloading audio...") - dl = await replied.download() - link = replied.link - songname = "Audio" - thumbnail = f"{IMG_5}" - try: - if replied.audio: - if replied.audio.title: - songname = replied.audio.title[:80] - else: - songname = replied.audio.file_name[:80] - if replied.audio.thumbs: - thumbnail = await c.download_media(replied.audio.thumbs[0].file_id) - duration = convert_seconds(replied.audio.duration) - elif replied.voice: - songname = "Voice Note" - duration = convert_seconds(replied.voice.duration) - except BaseException: - pass - - if chat_id in QUEUE: - await suhu.edit("๐Ÿ”„ Queueing Track...") - gcname = m.chat.title - ctitle = await CHAT_TITLE(gcname) - title = songname - userid = m.from_user.id - image = await thumb(thumbnail, title, userid, ctitle) - pos = add_to_queue(chat_id, songname, dl, link, "Audio", 0) - requester = f"[{m.from_user.first_name}](tg://user?id={m.from_user.id})" - buttons = stream_markup(user_id) - await suhu.delete() - await m.reply_photo( - photo=image, - reply_markup=InlineKeyboardMarkup(buttons), - caption=f"๐Ÿ’ก **Track added to queue ยป** `{pos}`\n\n๐Ÿ—‚ **Name:** [{songname}]({link}) | `music`\nโฑ๏ธ **Duration:** `{duration}`\n๐Ÿงธ **Request by:** {requester}", - ) - remove_if_exists(image) - else: - try: - gcname = m.chat.title - ctitle = await CHAT_TITLE(gcname) - title = songname - userid = m.from_user.id - image = await thumb(thumbnail, title, userid, ctitle) - await suhu.edit("๐Ÿ”„ Joining Group Call...") - await music_on(chat_id) - await add_active_chat(chat_id) - await calls.join_group_call( - chat_id, - AudioPiped( - dl, - HighQualityAudio(), - ), - stream_type=StreamType().pulse_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=image, - reply_markup=InlineKeyboardMarkup(buttons), - caption=f"๐Ÿ—‚ **Name:** [{songname}]({link}) | `music`\nโฑ๏ธ **Duration:** `{duration}`\n๐Ÿงธ **Request by:** {requester}", - ) - await idle() - remove_if_exists(image) - except Exception as e: - await suhu.delete() - await remove_active_chat(chat_id) - traceback.print_exc() - await m.reply_text(f"๐Ÿšซ error:\n\nยป {e}") + await play_tg_file(c, m, replied) else: if len(m.command) < 2: await m.reply( @@ -257,6 +288,11 @@ async def play(c: Client, m: Message): await m.reply( "ยป reply to an **audio file** or **give something to search.**" ) + elif "t.me" in m.command[1]: + for i in m.command[1:]: + if "t.me" in i: + await play_tg_file(c, m, link=i) + continue else: suhu = await c.send_message(chat_id, "๐Ÿ” **Loading...**") query = m.text.split(None, 1)[1] diff --git a/program/playlist.py b/program/playlist.py index f454fe9..a35f3b0 100644 --- a/program/playlist.py +++ b/program/playlist.py @@ -4,18 +4,15 @@ from config import BOT_USERNAME from pyrogram.types import ( - CallbackQuery, InlineKeyboardButton, InlineKeyboardMarkup, Message, ) -from pyrogram import Client, filters +from pyrogram import Client from driver.decorators import check_blacklist from driver.queues import QUEUE, get_queue from driver.filters import command, other_filters -from driver.database.dbpunish import is_gbanned_user - keyboard = InlineKeyboardMarkup( [[InlineKeyboardButton("๐Ÿ—‘ Close", callback_data="set_close")]] @@ -28,12 +25,17 @@ async def playlist(client, m: Message): chat_id = m.chat.id if chat_id in QUEUE: chat_queue = get_queue(chat_id) - if len(chat_queue)==1: - await m.reply(f"๐Ÿ’ก **Currently Streaming**`:`\n\n*๏ธโƒฃ [{chat_queue[0][0]}]({chat_queue[0][2]}) | `{chat_queue[0][3]}`", reply_markup=keyboard, disable_web_page_preview=True) + if len(chat_queue) == 1: + await m.reply( + f"๐Ÿ’ก **Currently Streaming**`:`\n\n" + f"*๏ธโƒฃ [{chat_queue[0][0]}]({chat_queue[0][2]}) | `{chat_queue[0][3]}`", + reply_markup=keyboard, disable_web_page_preview=True) else: - QUE = f"๐Ÿ’ก **Currently Streaming**`:`\n\n*๏ธโƒฃ [{chat_queue[0][0]}]({chat_queue[0][2]}) | `{chat_queue[0][3]}` \n\n**๐Ÿ“– Queue song list**`:`\n" + QUE = f"๐Ÿ’ก **Currently Streaming**`:`\n\n" \ + f"*๏ธโƒฃ [{chat_queue[0][0]}]({chat_queue[0][2]}) | `{chat_queue[0][3]}` \n\n" \ + f"**๐Ÿ“– Queue song list**`:`\n" l = len(chat_queue) - for x in range (1, l): + for x in range(1, l): han = chat_queue[x][0] hok = chat_queue[x][2] hap = chat_queue[x][3] diff --git a/program/punishment.py b/program/punishment.py index 346e429..1d04678 100644 --- a/program/punishment.py +++ b/program/punishment.py @@ -3,7 +3,7 @@ import asyncio -from pyrogram import Client, filters +from pyrogram import Client from pyrogram.types import Message from pyrogram.errors import FloodWait from driver.core import me_bot diff --git a/program/start.py b/program/start.py index 59c37f7..9cdcedb 100644 --- a/program/start.py +++ b/program/start.py @@ -15,13 +15,13 @@ from config import ( from driver.decorators import check_blacklist from program import __version__ from driver.core import bot, me_bot, me_user -from driver.filters import command, other_filters +from driver.filters import command from driver.database.dbchat import add_served_chat, is_served_chat from driver.database.dbpunish import is_gbanned_user from driver.database.dbusers import add_served_user from driver.database.dblockchat import blacklisted_chats from pyrogram import Client, filters, __version__ as pyrover -from pyrogram.errors import FloodWait, MessageNotModified +from pyrogram.errors import FloodWait from pytgcalls import (__version__ as pytover) from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup, Message, ChatJoinRequest diff --git a/program/userbot_tools.py b/program/userbot_tools.py index baa265c..c38184d 100644 --- a/program/userbot_tools.py +++ b/program/userbot_tools.py @@ -6,7 +6,6 @@ from driver.core import user, me_bot from driver.filters import command, other_filters from driver.database.dbchat import remove_served_chat from driver.database.dbqueue import remove_active_chat -from driver.database.dbpunish import is_gbanned_user from driver.decorators import authorized_users_only, bot_creator, check_blacklist from pyrogram.types import Message diff --git a/program/video.py b/program/video.py index a6843f6..17e49bb 100644 --- a/program/video.py +++ b/program/video.py @@ -14,11 +14,9 @@ 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.core import calls, user, bot, me_user -from driver.database.dbpunish import is_gbanned_user -from driver.database.dblockchat import blacklisted_chats +from driver.core import calls, user, me_user from driver.database.dbqueue import add_active_chat, remove_active_chat, music_on -from driver.utils import remove_if_exists +from driver.utils import remove_if_exists, from_tg_get_msg # pyrogram stuff from pyrogram import Client from pyrogram.errors import UserAlreadyParticipant, UserNotParticipant @@ -77,6 +75,112 @@ def convert_seconds(seconds): return "%02d:%02d" % (minutes, seconds) +async def play_tg_file(c: Client, m: Message, replied: Message = None, link: str = None): + chat_id = m.chat.id + user_id = m.from_user.id + if link: + try: + replied = await from_tg_get_msg(link) + except Exception as e: + traceback.print_exc() + return await m.reply_text(f"๐Ÿšซ error:\n\nยป {e}") + if not replied: + return await m.reply( + "ยป reply to an **audio file** or **give something to search.**" + ) + if replied.video or replied.document: + if not link: + loser = await replied.reply("๐Ÿ“ฅ downloading video...") + else: + loser = await m.reply("๐Ÿ“ฅ downloading video...") + dl = await replied.download() + link = replied.link + songname = "video" + duration = "00:00" + Q = 720 + pq = m.text.split(None, 1) + if ("t.me" not in m.text) and len(pq) > 1: + pq = pq[1] + if pq == "720" or pq == "480" or pq == "360": + Q = int(pq) + else: + await loser.edit( + "ยป only 720, 480, 360 allowed\n\n๐Ÿ’ก now streaming video in **720p**" + ) + try: + if replied.video: + songname = replied.video.file_name[:80] + duration = convert_seconds(replied.video.duration) + elif replied.document: + songname = replied.document.file_name[:80] + except BaseException: + songname = "Video" + + if chat_id in QUEUE: + await loser.edit("๐Ÿ”„ Queueing Track...") + gcname = m.chat.title + ctitle = await CHAT_TITLE(gcname) + title = songname + userid = m.from_user.id + thumbnail = f"{IMG_5}" + image = await thumb(thumbnail, title, userid, ctitle) + pos = add_to_queue(chat_id, songname, dl, link, "Video", Q) + await loser.delete() + 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, + reply_markup=InlineKeyboardMarkup(buttons), + caption=f"๐Ÿ’ก **Track added to queue ยป** `{pos}`\n\n" + f"๐Ÿ—‚ **Name:** [{songname}]({link}) | `video`\n" + f"โฑ๏ธ **Duration:** `{duration}`\n" + f"๐Ÿงธ **Request by:** {requester}", + ) + remove_if_exists(image) + else: + await loser.edit("๐Ÿ”„ Joining Group Call...") + gcname = m.chat.title + ctitle = await CHAT_TITLE(gcname) + title = songname + userid = m.from_user.id + thumbnail = f"{IMG_5}" + image = await thumb(thumbnail, title, userid, ctitle) + if Q == 720: + amaze = HighQualityVideo() + elif Q == 480: + amaze = MediumQualityVideo() + elif Q == 360: + amaze = LowQualityVideo() + await music_on(chat_id) + await add_active_chat(chat_id) + await calls.join_group_call( + chat_id, + AudioVideoPiped( + dl, + HighQualityAudio(), + amaze, + ), + stream_type=StreamType().pulse_stream, + ) + add_to_queue(chat_id, songname, dl, link, "Video", Q) + await loser.delete() + 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, + reply_markup=InlineKeyboardMarkup(buttons), + caption=f"๐Ÿ—‚ **Name:** [{songname}]({link}) | `video`\n" + f"โฑ๏ธ **Duration:** `{duration}`\n" + f"๐Ÿงธ **Request by:** {requester}", + ) + await idle() + remove_if_exists(image) + else: + await m.reply( + "ยป reply to an **video file** or **give something to search.**" + ) + + @Client.on_message(command(["vplay", f"vplay@{BOT_USERNAME}"]) & other_filters) @check_blacklist() @require_admin(permissions=["can_manage_voice_chats", "can_delete_messages", "can_invite_users"], self=True) @@ -125,84 +229,7 @@ async def vplay(c: Client, m: Message): ) if replied: if replied.video or replied.document: - loser = await replied.reply("๐Ÿ“ฅ downloading video...") - dl = await replied.download() - link = replied.link - if len(m.command) < 2: - Q = 720 - else: - pq = m.text.split(None, 1)[1] - if pq == "720" or "480" or "360": - Q = int(pq) - else: - Q = 720 - await loser.edit( - "ยป only 720, 480, 360 allowed\n\n๐Ÿ’ก now streaming video in **720p**" - ) - try: - if replied.video: - songname = replied.video.file_name[:80] - duration = convert_seconds(replied.video.duration) - elif replied.document: - songname = replied.document.file_name[:80] - duration = convert_seconds(replied.document.duration) - except BaseException: - songname = "Video" - - if chat_id in QUEUE: - await loser.edit("๐Ÿ”„ Queueing Track...") - gcname = m.chat.title - ctitle = await CHAT_TITLE(gcname) - title = songname - userid = m.from_user.id - thumbnail = f"{IMG_5}" - image = await thumb(thumbnail, title, userid, ctitle) - pos = add_to_queue(chat_id, songname, dl, link, "Video", Q) - await loser.delete() - 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, - reply_markup=InlineKeyboardMarkup(buttons), - caption=f"๐Ÿ’ก **Track added to queue ยป** `{pos}`\n\n๐Ÿ—‚ **Name:** [{songname}]({link}) | `video`\nโฑ๏ธ **Duration:** `{duration}`\n๐Ÿงธ **Request by:** {requester}", - ) - remove_if_exists(image) - else: - await loser.edit("๐Ÿ”„ Joining Group Call...") - gcname = m.chat.title - ctitle = await CHAT_TITLE(gcname) - title = songname - userid = m.from_user.id - thumbnail = f"{IMG_5}" - image = await thumb(thumbnail, title, userid, ctitle) - if Q == 720: - amaze = HighQualityVideo() - elif Q == 480: - amaze = MediumQualityVideo() - elif Q == 360: - amaze = LowQualityVideo() - await music_on(chat_id) - await add_active_chat(chat_id) - await calls.join_group_call( - chat_id, - AudioVideoPiped( - dl, - HighQualityAudio(), - amaze, - ), - stream_type=StreamType().pulse_stream, - ) - add_to_queue(chat_id, songname, dl, link, "Video", Q) - await loser.delete() - 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, - reply_markup=InlineKeyboardMarkup(buttons), - caption=f"๐Ÿ—‚ **Name:** [{songname}]({link}) | `video`\nโฑ๏ธ **Duration:** `{duration}`\n๐Ÿงธ **Request by:** {requester}", - ) - await idle() - remove_if_exists(image) + await play_tg_file(c, m, replied) else: if len(m.command) < 2: await m.reply( @@ -279,6 +306,11 @@ async def vplay(c: Client, m: Message): await m.reply( "ยป reply to an **video file** or **give something to search.**" ) + elif "t.me" in m.command[1]: + for i in m.command[1:]: + if "t.me" in i: + await play_tg_file(c, m, link=i) + continue else: loser = await c.send_message(chat_id, "๐Ÿ” **Loading...**") query = m.text.split(None, 1)[1]