Update video.py

This commit is contained in:
Tofik Denianto 2021-10-30 02:01:26 +07:00 committed by GitHub
parent 663f948e3d
commit ad0bb7868d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,298 +2,296 @@
# Commit Start Date 20/10/2021 # Commit Start Date 20/10/2021
# Finished On 28/10/2021 # Finished On 28/10/2021
import os
import re
import asyncio import asyncio
from driver.veez import call_py import re
from pytgcalls import StreamType
from pyrogram import Client, filters from config import BOT_USERNAME, GROUP_SUPPORT, IMG_1, IMG_2, UPDATES_CHANNEL
from driver.filters import command, other_filters from driver.filters import command, other_filters
from youtubesearchpython import VideosSearch
from driver.queues import QUEUE, add_to_queue from driver.queues import QUEUE, add_to_queue
from driver.veez import call_py
from pyrogram import Client
from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup, Message
from pytgcalls import StreamType
from pytgcalls.types.input_stream import AudioVideoPiped from pytgcalls.types.input_stream import AudioVideoPiped
from config import BOT_USERNAME, IMG_1, IMG_2, GROUP_SUPPORT, UPDATES_CHANNEL from pytgcalls.types.input_stream.quality import (
from pyrogram.types import Message, InlineKeyboardButton, InlineKeyboardMarkup HighQualityAudio,
from pytgcalls.types.input_stream.quality import HighQualityAudio, MediumQualityAudio HighQualityVideo,
from pytgcalls.types.input_stream.quality import HighQualityVideo, MediumQualityVideo, LowQualityVideo LowQualityVideo,
MediumQualityVideo,
)
from youtubesearchpython import VideosSearch
def ytsearch(query): def ytsearch(query):
try: try:
search = VideosSearch(query, limit=1) search = VideosSearch(query, limit=1)
for r in search.result()["result"]: for r in search.result()["result"]:
ytid = r['id'] ytid = r["id"]
if len(r['title']) > 34: if len(r["title"]) > 34:
songname = r['title'][:60] + "..." songname = r["title"][:60] + "..."
else: else:
songname = r['title'] songname = r["title"]
url = f"https://www.youtube.com/watch?v={ytid}" url = f"https://www.youtube.com/watch?v={ytid}"
return [songname, url] return [songname, url]
except Exception as e: except Exception as e:
print(e) print(e)
return 0 return 0
async def ytdl(link): async def ytdl(link):
proc = await asyncio.create_subprocess_exec( proc = await asyncio.create_subprocess_exec(
'yt-dlp', "yt-dlp",
'-g', "-g",
'-f', "-f",
'best[height<=?720][width<=?1280]', "best[height<=?720][width<=?1280]",
f'{link}', f"{link}",
stdout=asyncio.subprocess.PIPE, stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE,
) )
stdout, stderr = await proc.communicate() stdout, stderr = await proc.communicate()
if stdout: if stdout:
return 1, stdout.decode().split('\n')[0] return 1, stdout.decode().split("\n")[0]
else: else:
return 0, stderr.decode() return 0, stderr.decode()
@Client.on_message(command(["vplay", f"vplay@{BOT_USERNAME}"]) & other_filters) @Client.on_message(command(["vplay", f"vplay@{BOT_USERNAME}"]) & other_filters)
async def vplay(client, m: Message): async def vplay(client, m: Message):
keyboard = InlineKeyboardMarkup( keyboard = InlineKeyboardMarkup(
[
[ [
[ InlineKeyboardButton(
InlineKeyboardButton( text="✨ ɢʀᴏᴜᴘ", url=f"https://t.me/{GROUP_SUPPORT}"
text="✨ ɢʀᴏᴜᴘ", ),
url=f"https://t.me/{GROUP_SUPPORT}"), InlineKeyboardButton(
InlineKeyboardButton( text="🌻 ᴄʜᴀɴɴᴇʟ", url=f"https://t.me/{UPDATES_CHANNEL}"
text="🌻 ᴄʜᴀɴɴᴇʟ", ),
url=f"https://t.me/{UPDATES_CHANNEL}")
]
] ]
) ]
)
replied = m.reply_to_message
chat_id = m.chat.id replied = m.reply_to_message
if replied: chat_id = m.chat.id
if replied.video or replied.document: if replied:
loser = await replied.reply("📥 **downloading video...**") if replied.video or replied.document:
dl = await replied.download() loser = await replied.reply("📥 **downloading video...**")
link = replied.link dl = await replied.download()
if len(m.command) < 2: link = replied.link
Q = 720 if len(m.command) < 2:
else: Q = 720
pq = m.text.split(None, 1)[1]
if pq == "720" or "480" or "360":
Q = int(pq)
else: else:
Q = 720 pq = m.text.split(None, 1)[1]
await loser.edit("» __only 720, 480, 360 allowed__ \n💡 **now streaming video in 720p**") if pq == "720" or "480" or "360":
Q = int(pq)
if replied.video: else:
songname = replied.video.file_name[:60] + "..." Q = 720
elif replied.document: await loser.edit(
songname = replied.document.file_name[:60] + "..." "» __only 720, 480, 360 allowed__ \n💡 **now streaming video in 720p**"
)
if chat_id in QUEUE:
pos = add_to_queue(chat_id, songname, dl, link, "Video", Q) if replied.video:
await loser.delete() songname = replied.video.file_name[:60] + "..."
await m.reply_photo( elif replied.document:
photo=f"{IMG_1}", songname = replied.document.file_name[:60] + "..."
caption=f"💡 **Track added to the queue**\n\n🏷 **Name:** [{songname}]({link})\n💭 **Chat:** `{chat_id}`\n🎧 **Request by:** {m.from_user.mention()}\n🔢 **At position »** `{pos}`",
reply_markup=keyboard, if chat_id in QUEUE:
pos = add_to_queue(chat_id, songname, dl, link, "Video", Q)
await loser.delete()
await m.reply_photo(
photo=f"{IMG_1}",
caption=f"💡 **Track added to the queue**\n\n🏷 **Name:** [{songname}]({link})\n💭 **Chat:** `{chat_id}`\n🎧 **Request by:** {m.from_user.mention()}\n🔢 **At position »** `{pos}`",
reply_markup=keyboard,
)
else:
if Q == 720:
amaze = HighQualityVideo()
elif Q == 480:
amaze = MediumQualityVideo()
elif Q == 360:
amaze = LowQualityVideo()
await call_py.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()
await m.reply_photo(
photo=f"{IMG_2}",
caption=f"💡 **video streaming started.**\n\n🏷 **Name:** [{songname}]({link})\n💭 **Chat:** `{chat_id}`\n💡 **Status:** `Playing`\n🎧 **Request by:** {m.from_user.mention()}",
reply_markup=keyboard,
)
else:
if len(m.command) < 2:
await m.reply(
"» reply to an **video file** or **give something to search.**"
)
else:
loser = await m.reply("🔎 **searching...**")
query = m.text.split(None, 1)[1]
search = ytsearch(query)
Q = 720
amaze = HighQualityVideo()
if search == 0:
await loser.edit("❌ **no results found.**")
else:
songname = search[0]
url = search[1]
veez, ytlink = await ytdl(url)
if veez == 0:
await loser.edit(f"❌ yt-dl issues detected\n\n» `{ytlink}`")
else:
if chat_id in QUEUE:
pos = add_to_queue(
chat_id, songname, ytlink, url, "Video", Q
)
await loser.delete()
await m.reply_photo(
photo=f"{IMG_1}",
caption=f"💡 **Track added to the queue**\n\n🏷 **Name:** [{songname}]({url})\n💭 **Chat:** `{chat_id}`\n🎧 **Request by:** {m.from_user.mention()}\n🔢 **At position »** `{pos}`",
reply_markup=keyboard,
)
else:
try:
await call_py.join_group_call(
chat_id,
AudioVideoPiped(ytlink, HighQualityAudio(), amaze),
stream_type=StreamType().pulse_stream,
)
add_to_queue(chat_id, songname, ytlink, url, "Video", Q)
await loser.delete()
await m.reply_photo(
photo=f"{IMG_2}",
caption=f"💡 **video streaming started.**\n\n🏷 **Name:** [{songname}]({url})\n💭 **Chat:** `{chat_id}`\n💡 **Status:** `Playing`\n🎧 **Request by:** {m.from_user.mention()}",
reply_markup=keyboard,
)
except Exception as ep:
await m.reply_text(f"🚫 error: `{ep}`")
else:
if len(m.command) < 2:
await m.reply(
"» reply to an **video file** or **give something to search.**"
) )
else: else:
if Q==720:
amaze = HighQualityVideo()
elif Q==480:
amaze = MediumQualityVideo()
elif Q==360:
amaze = LowQualityVideo()
await call_py.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()
await m.reply_photo(
photo=f"{IMG_2}",
caption=f"💡 **video streaming started.**\n\n🏷 **Name:** [{songname}]({link})\n💭 **Chat:** `{chat_id}`\n💡 **Status:** `Playing`\n🎧 **Request by:** {m.from_user.mention()}",
reply_markup=keyboard,
)
else:
if len(m.command) < 2:
await m.reply("» reply to an **video file** or **give something to search.**")
else:
loser = await m.reply("🔎 **searching...**") loser = await m.reply("🔎 **searching...**")
query = m.text.split(None, 1)[1] query = m.text.split(None, 1)[1]
search = ytsearch(query) search = ytsearch(query)
Q = 720 Q = 720
amaze = HighQualityVideo() amaze = HighQualityVideo()
if search==0: if search == 0:
await loser.edit("❌ **no results found.**") await loser.edit("❌ **no results found.**")
else: else:
songname = search[0] songname = search[0]
url = search[1] url = search[1]
veez, ytlink = await ytdl(url) veez, ytlink = await ytdl(url)
if veez==0: if veez == 0:
await loser.edit(f"❌ yt-dl issues detected\n\n» `{ytlink}`") await loser.edit(f"❌ yt-dl issues detected\n\n» `{ytlink}`")
else: else:
if chat_id in QUEUE: if chat_id in QUEUE:
pos = add_to_queue(chat_id, songname, ytlink, url, "Video", Q) pos = add_to_queue(chat_id, songname, ytlink, url, "Video", Q)
await loser.delete()
await m.reply_photo(
photo=f"{IMG_1}",
caption=f"💡 **Track added to the queue**\n\n🏷 **Name:** [{songname}]({url})\n💭 **Chat:** `{chat_id}`\n🎧 **Request by:** {m.from_user.mention()}\n🔢 **At position »** `{pos}`",
reply_markup=keyboard,
)
else:
try:
await call_py.join_group_call(
chat_id,
AudioVideoPiped(
ytlink,
HighQualityAudio(),
amaze
),
stream_type=StreamType().pulse_stream,
)
add_to_queue(chat_id, songname, ytlink, url, "Video", Q)
await loser.delete() await loser.delete()
await m.reply_photo( await m.reply_photo(
photo=f"{IMG_2}", photo=f"{IMG_1}",
caption=f"💡 **video streaming started.**\n\n🏷 **Name:** [{songname}]({url})\n💭 **Chat:** `{chat_id}`\n💡 **Status:** `Playing`\n🎧 **Request by:** {m.from_user.mention()}", caption=f"💡 **Track added to the queue**\n\n🏷 **Name:** [{songname}]({url})\n💭 **Chat:** `{chat_id}`\n🎧 **Request by:** {m.from_user.mention()}\n🔢 **At position »** `{pos}`",
reply_markup=keyboard, reply_markup=keyboard,
) )
except Exception as ep: else:
await m.reply_text(f"🚫 error: `{ep}`") try:
await call_py.join_group_call(
else: chat_id,
if len(m.command) < 2: AudioVideoPiped(ytlink, HighQualityAudio(), amaze),
await m.reply("» reply to an **video file** or **give something to search.**") stream_type=StreamType().pulse_stream,
else: )
loser = await m.reply("🔎 **searching...**") add_to_queue(chat_id, songname, ytlink, url, "Video", Q)
query = m.text.split(None, 1)[1] await loser.delete()
search = ytsearch(query) await m.reply_photo(
Q = 720 photo=f"{IMG_2}",
amaze = HighQualityVideo() caption=f"💡 **video streaming started.**\n\n🏷 **Name:** [{songname}]({url})\n💭 **Chat:** `{chat_id}`\n💡 **Status:** `Playing`\n🎧 **Request by:** {m.from_user.mention()}",
if search==0: reply_markup=keyboard,
await loser.edit("❌ **no results found.**") )
else: except Exception as ep:
songname = search[0] await m.reply_text(f"🚫 error: `{ep}`")
url = search[1]
veez, ytlink = await ytdl(url)
if veez==0:
await loser.edit(f"❌ yt-dl issues detected\n\n» `{ytlink}`")
else:
if chat_id in QUEUE:
pos = add_to_queue(chat_id, songname, ytlink, url, "Video", Q)
await loser.delete()
await m.reply_photo(
photo=f"{IMG_1}",
caption=f"💡 **Track added to the queue**\n\n🏷 **Name:** [{songname}]({url})\n💭 **Chat:** `{chat_id}`\n🎧 **Request by:** {m.from_user.mention()}\n🔢 **At position »** `{pos}`",
reply_markup=keyboard,
)
else:
try:
await call_py.join_group_call(
chat_id,
AudioVideoPiped(
ytlink,
HighQualityAudio(),
amaze
),
stream_type=StreamType().pulse_stream,
)
add_to_queue(chat_id, songname, ytlink, url, "Video", Q)
await loser.delete()
await m.reply_photo(
photo=f"{IMG_2}",
caption=f"💡 **video streaming started.**\n\n🏷 **Name:** [{songname}]({url})\n💭 **Chat:** `{chat_id}`\n💡 **Status:** `Playing`\n🎧 **Request by:** {m.from_user.mention()}",
reply_markup=keyboard,
)
except Exception as ep:
await m.reply_text(f"🚫 error: `{ep}`")
@Client.on_message(command(["vstream", f"vstream@{BOT_USERNAME}"]) & other_filters) @Client.on_message(command(["vstream", f"vstream@{BOT_USERNAME}"]) & other_filters)
async def vstream(client, m: Message): async def vstream(client, m: Message):
keyboard = InlineKeyboardMarkup( keyboard = InlineKeyboardMarkup(
[
[ [
[ InlineKeyboardButton(
InlineKeyboardButton( text="✨ ɢʀᴏᴜᴘ", url=f"https://t.me/{GROUP_SUPPORT}"
text="✨ ɢʀᴏᴜᴘ", ),
url=f"https://t.me/{GROUP_SUPPORT}"), InlineKeyboardButton(
InlineKeyboardButton( text="🌻 ᴄʜᴀɴɴᴇʟ", url=f"https://t.me/{UPDATES_CHANNEL}"
text="🌻 ᴄʜᴀɴɴᴇʟ", ),
url=f"https://t.me/{UPDATES_CHANNEL}")
]
] ]
) ]
)
chat_id = m.chat.id
if len(m.command) < 2: chat_id = m.chat.id
await m.reply("» give me a live-link/m3u8 url/youtube link to stream.") if len(m.command) < 2:
else: await m.reply("» give me a live-link/m3u8 url/youtube link to stream.")
if len(m.command)==2: else:
link = m.text.split(None, 1)[1] if len(m.command) == 2:
Q = 720 link = m.text.split(None, 1)[1]
loser = await m.reply("🔄 **processing stream...**")
elif len(m.command)==3:
op = m.text.split(None, 1)[1]
link = op.split(None, 1)[0]
quality = op.split(None, 1)[1]
if quality == "720" or "480" or "360":
Q = int(quality)
else:
Q = 720 Q = 720
await m.reply("» __only 720, 480, 360 allowed__ \n💡 **now streaming video in 720p**") loser = await m.reply("🔄 **processing stream...**")
loser = await m.reply("🔄 **processing stream...**") elif len(m.command) == 3:
else: op = m.text.split(None, 1)[1]
await m.reply("**/vstream {link} {720/480/360}**") link = op.split(None, 1)[0]
quality = op.split(None, 1)[1]
if quality == "720" or "480" or "360":
Q = int(quality)
else:
Q = 720
await m.reply(
"» __only 720, 480, 360 allowed__ \n💡 **now streaming video in 720p**"
)
loser = await m.reply("🔄 **processing stream...**")
else:
await m.reply("**/vstream {link} {720/480/360}**")
regex = r"^(https?\:\/\/)?(www\.youtube\.com|youtu\.?be)\/.+" regex = r"^(https?\:\/\/)?(www\.youtube\.com|youtu\.?be)\/.+"
match = re.match(regex,link) match = re.match(regex, link)
if match: if match:
veez, livelink = await ytdl(link) veez, livelink = await ytdl(link)
else: else:
livelink = link livelink = link
veez = 1 veez = 1
if veez==0: if veez == 0:
await loser.edit(f"❌ yt-dl issues detected\n\n» `{ytlink}`") await loser.edit(f"❌ yt-dl issues detected\n\n» `{ytlink}`")
else: else:
if chat_id in QUEUE: if chat_id in QUEUE:
pos = add_to_queue(chat_id, "Live Stream", livelink, link, "Video", Q) pos = add_to_queue(chat_id, "Live Stream", livelink, link, "Video", Q)
await loser.delete() await loser.delete()
await m.reply_photo( await m.reply_photo(
photo=f"{IMG_1}", photo=f"{IMG_1}",
caption=f"💡 **Track added to the queue**\n\n💭 **Chat:** `{chat_id}`\n🎧 **Request by:** {m.from_user.mention()}\n🔢 **At position »** `{pos}`", caption=f"💡 **Track added to the queue**\n\n💭 **Chat:** `{chat_id}`\n🎧 **Request by:** {m.from_user.mention()}\n🔢 **At position »** `{pos}`",
reply_markup=keyboard, reply_markup=keyboard,
) )
else: else:
if Q==720: if Q == 720:
amaze = HighQualityVideo() amaze = HighQualityVideo()
elif Q==480: elif Q == 480:
amaze = MediumQualityVideo() amaze = MediumQualityVideo()
elif Q==360: elif Q == 360:
amaze = LowQualityVideo() amaze = LowQualityVideo()
try: try:
await call_py.join_group_call( await call_py.join_group_call(
chat_id, chat_id,
AudioVideoPiped( AudioVideoPiped(livelink, HighQualityAudio(), amaze),
livelink, stream_type=StreamType().pulse_stream,
HighQualityAudio(), )
amaze add_to_queue(chat_id, "Live Stream", livelink, link, "Video", Q)
), await loser.delete()
stream_type=StreamType().pulse_stream, await m.reply_photo(
) photo=f"{IMG_2}",
add_to_queue(chat_id, "Live Stream", livelink, link, "Video", Q) caption=f"💡 **[Live stream video]({link}) started.**\n\n💭 **Chat:** `{chat_id}`\n💡 **Status:** `Playing`\n🎧 **Request by:** {m.from_user.mention()}",
await loser.delete() reply_markup=keyboard,
await m.reply_photo( )
photo=f"{IMG_2}", except Exception as ep:
caption=f"💡 **[Live stream video]({link}) started.**\n\n💭 **Chat:** `{chat_id}`\n💡 **Status:** `Playing`\n🎧 **Request by:** {m.from_user.mention()}", await m.reply_text(f"🚫 error: `{ep}`")
reply_markup=keyboard,
)
except Exception as ep:
await m.reply_text(f"🚫 error: `{ep}`")