From 83fe62a2ecd92e4772634cf3437cad1100be443c Mon Sep 17 00:00:00 2001 From: levina <82658782+levina-lab@users.noreply.github.com> Date: Sun, 31 Oct 2021 10:15:18 +0700 Subject: [PATCH 1/2] added inline search --- program/inline.py | 48 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 program/inline.py diff --git a/program/inline.py b/program/inline.py new file mode 100644 index 0000000..a54377f --- /dev/null +++ b/program/inline.py @@ -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="", + ) From 4406927bd4d18a1a6a39bc1b870f23ae3a8dce51 Mon Sep 17 00:00:00 2001 From: levina <82658782+levina-lab@users.noreply.github.com> Date: Sun, 31 Oct 2021 10:16:44 +0700 Subject: [PATCH 2/2] feature info --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 4154dee..1209eb2 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ - Inline Search support - YouTube direct search support - YouTube/Local/Radio/Live stream support +- Inline Search support ## 🛠 Commands: - `/play (query)` - play music from youtube