merge pull request #22 from levina-lab/main

push commit from base
This commit is contained in:
levina 2021-10-31 19:45:30 +07:00 committed by GitHub
commit 8fea38869d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 49 additions and 0 deletions

View File

@ -29,6 +29,7 @@
- Inline Search support - Inline Search support
- YouTube direct search support - YouTube direct search support
- YouTube/Local/Radio/Live stream support - YouTube/Local/Radio/Live stream support
- Inline Search support
## 🛠 Commands: ## 🛠 Commands:
- `/play (query)` - play music from youtube - `/play (query)` - play music from youtube

48
program/inline.py Normal file
View File

@ -0,0 +1,48 @@
from pyrogram import Client, errors
from pyrogram.types import (
InlineQuery,
InlineQueryResultArticle,
InputTextMessageContent,
)
from youtubesearchpython import VideosSearch
@Client.on_inline_query()
async def inline(client: Client, query: InlineQuery):
answers = []
search_query = query.query.lower().strip().rstrip()
if search_query == "":
await client.answer_inline_query(
query.id,
results=answers,
switch_pm_text="type a youtube video name...",
switch_pm_parameter="help",
cache_time=0,
)
else:
search = VideosSearch(search_query, limit=50)
for result in search.result()["result"]:
answers.append(
InlineQueryResultArticle(
title=result["title"],
description="{}, {} views.".format(
result["duration"], result["viewCount"]["short"]
),
input_message_content=InputTextMessageContent(
"🔗 https://www.youtube.com/watch?v={}".format(result["id"])
),
thumb_url=result["thumbnails"][0]["url"],
)
)
try:
await query.answer(results=answers, cache_time=0)
except errors.QueryIdInvalid:
await query.answer(
results=answers,
cache_time=0,
switch_pm_text="error: search timed out",
switch_pm_parameter="",
)