Ver Fonte

Added youtube search inline

TheHamkerCat há 5 anos atrás
pai
commit
bbe177fccf
3 ficheiros alterados com 51 adições e 3 exclusões
  1. 1 1
      sample_config.py
  2. 11 2
      wbb/modules/inline.py
  3. 39 0
      wbb/utils/inlinefuncs.py

+ 1 - 1
sample_config.py

@@ -12,4 +12,4 @@ MONGO_DB_URI = "mongodb+srv://username:password@cluster0.ksiis.mongodb.net/YourD
 
 
 # NOTE Don't make changes below this line
-ARQ_API_BASE_URL = "http://35.240.133.234:8000"
+ARQ_API_BASE_URL = "http://thearq.tech"

+ 11 - 2
wbb/modules/inline.py

@@ -3,7 +3,7 @@ from wbb.utils.inlinefuncs import (
     google_search_func, urban_func, translate_func,
     alive_function, webss, shortify, wall_func,
     saavn_func, deezer_func, inline_help_func,
-    torrent_func
+    torrent_func, youtube_func
 )
 from pyrogram import filters
 
@@ -18,7 +18,8 @@ __HELP__ = """
 **wall [Query]** - __Find Wallpapers.__
 **saavn [SONG_NAME]** - __Get Songs From Saavn.__
 **deezer [SONG_NAME]** - __Get Songs From Deezer.__
-**torrent [QUERY] - __Torrent Search.__"""
+**yt [Query]** - __Youtube Search.__
+**torrent [QUERY]** - __Torrent Search.__"""
 
 
 @app.on_message(filters.command("inline"))
@@ -121,5 +122,13 @@ async def inline_query_handler(client, query):
                 cache_time=10
             )
 
+        elif text.split()[0] == "yt":
+            tex = text.split(None, 1)[1]
+            answerss = await youtube_func(answers, tex)
+            await client.answer_inline_query(
+                query.id,
+                results=answerss
+            )
+
     except (IndexError, TypeError, KeyError, ValueError):
         return

+ 39 - 0
wbb/utils/inlinefuncs.py

@@ -320,3 +320,42 @@ async def torrent_func(answers, text):
         except (KeyError, ValueError):
             pass
     return answers
+
+
+async def youtube_func(answers, text):
+    buttons_list = []
+    results = await arq.youtube(text)
+    for i in results:
+        buttons = InlineKeyboard(row_width=1)
+        video_url = f"https://youtube.com{results[i].url_suffix}"
+        buttons.add(
+            InlineKeyboardButton(
+                'Watch',
+                url=video_url
+            )
+        )
+        buttons_list.append(buttons)
+        caption = f"""
+**Title:** {results[i].title}
+**Views:** {results[i].views}
+**Channel:** {results[i].channel}
+**Duration:** {results[i].duration}
+**Uploaded:** {results[i].publish_time}
+**Description:** {results[i].long_desc}"""
+        description = f"{results[i].views} | {results[i].channel} | " \
+                       + f"{results[i].duration} | {results[i].publish_time}"
+        try:
+            answers.append(
+                InlineQueryResultArticle(
+                    title=results[i].title,
+                    thumb_url=results[i].thumbnails[0],
+                    description=description,
+                    input_message_content=InputTextMessageContent(
+                        caption,
+                        disable_web_page_preview=True
+                    ),
+                    reply_markup=buttons_list[i]
+                ))
+        except (KeyError, ValueError):
+            pass
+    return answers