Explorar o código

YTMUSIC NO SUDO

TheHamkerCat %!s(int64=5) %!d(string=hai) anos
pai
achega
b9a447e791
Modificáronse 5 ficheiros con 30 adicións e 24 borrados
  1. 1 2
      wbb/modules/inline.py
  2. 4 1
      wbb/modules/karma.py
  3. 12 11
      wbb/modules/music.py
  4. 1 1
      wbb/utils/functions.py
  5. 12 9
      wbb/utils/inlinefuncs.py

+ 1 - 2
wbb/modules/inline.py

@@ -347,8 +347,7 @@ async def inline_query_handler(client, query):
                 )
                 return
             tex = query.query.split(None, 1)[1].strip()
-            user_id = query.from_user.id
-            answerss = await yt_music_func(answers, tex, user_id)
+            answerss = await yt_music_func(answers, tex)
             await client.answer_inline_query(
                 query.id, results=answerss, cache_time=2
             )

+ 4 - 1
wbb/modules/karma.py

@@ -133,6 +133,9 @@ async def karma(_, message):
     if not message.reply_to_message:
         m = await message.reply_text("Analyzing Karma...Will Take 10 Seconds")
         karma = await get_karmas(chat_id)
+        if not karma:
+            await m.edit("No karma in DB for this chat.")
+            return
         msg = f"**Karma list of {message.chat.title}:- **\n"
         limit = 0
         karma_dicc = {}
@@ -145,7 +148,7 @@ async def karma(_, message):
                     karma_dicc.items(), key=lambda item: item[1], reverse=True
                 )
             )
-        if not karma_arranged:
+        if not karma_dicc:
             await m.edit("No karma in DB for this chat.")
             return
         for user_idd, karma_count in karma_arranged.items():

+ 12 - 11
wbb/modules/music.py

@@ -24,6 +24,8 @@ SOFTWARE.
 from __future__ import unicode_literals
 
 import os
+from asyncio import get_running_loop
+from functools import partial
 from random import randint
 from urllib.parse import urlparse
 
@@ -33,7 +35,7 @@ import ffmpeg
 import youtube_dl
 from pyrogram import filters
 
-from wbb import SUDOERS, app, arq
+from wbb import app, arq
 from wbb.core.decorators.errors import capture_err
 from wbb.utils.pastebin import paste
 
@@ -52,22 +54,19 @@ def get_file_extension_from_url(url):
     return basename.split(".")[-1]
 
 
-async def download_youtube_audio(url: str, m=0):
+def download_youtube_audio(url: str, m=0):
     global is_downloading
     with youtube_dl.YoutubeDL(
         {
             "format": "bestaudio",
             "writethumbnail": True,
+            "quiet": True,
         }
     ) as ydl:
         info_dict = ydl.extract_info(url, download=False)
         if int(float(info_dict["duration"])) > 600:
-            if m != 0:
-                await m.edit(
-                    "This music cannot be downloaded as it's too long."
-                )
             is_downloading = False
-            return
+            return []
         ydl.process_info(info_dict)
         audio_file = ydl.prepare_filename(info_dict)
         basename = audio_file.rsplit(".", 1)[-2]
@@ -88,9 +87,7 @@ async def download_youtube_audio(url: str, m=0):
     return [title, performer, duration, audio_file, thumbnail_file]
 
 
-@app.on_message(
-    filters.command("ytmusic") & ~filters.edited & filters.user(SUDOERS)
-)
+@app.on_message(filters.command("ytmusic"))
 @capture_err
 async def music(_, message):
     global is_downloading
@@ -108,13 +105,17 @@ async def music(_, message):
         f"Downloading {url}", disable_web_page_preview=True
     )
     try:
+        loop = get_running_loop()
+        music = await loop.run_in_executor(None, partial(download_youtube_audio, url, message))
+        if not music:
+            await m.edit("Too Long, Can't Download.")
         (
             title,
             performer,
             duration,
             audio_file,
             thumbnail_file,
-        ) = await download_youtube_audio(url, message)
+        ) = music 
     except Exception as e:
         is_downloading = False
         await m.edit(str(e))

+ 1 - 1
wbb/utils/functions.py

@@ -97,7 +97,7 @@ def generate_captcha():
     return [file, correct_answer, wrong_answers]
 
 
-async def test_speedtest():
+def test_speedtest():
     def speed_convert(size):
         power = 2 ** 10
         zero = 0

+ 12 - 9
wbb/utils/inlinefuncs.py

@@ -731,7 +731,8 @@ async def test_speedtest_cq(_, cq):
         return
     inline_message_id = cq.inline_message_id
     await app.edit_inline_text(inline_message_id, "**Testing**")
-    download, upload, info = await test_speedtest()
+    loop = asyncio.get_running_loop()
+    download, upload, info = await loop.run_in_executor(None, test_speedtest)
     msg = f"""
 **Download:** `{download}`
 **Upload:** `{upload}`
@@ -855,27 +856,29 @@ async def nsfw_scan_func(answers, url: str):
     return answers
 
 
-async def yt_music_func(answers, url, user_id):
-    if user_id not in SUDOERS:
-        msg = "**ERROR**\n__THIS FEATURE IS ONLY FOR SUDO USERS__"
+async def yt_music_func(answers, url):
+    if "http" not in url:
+        url = (await arq.youtube(url)).result[0]
+        url = f"https://youtube.com{url.url_suffix}"
+    loop = asyncio.get_running_loop()
+    music = await loop.run_in_executor(None, download_youtube_audio, url)
+    if not music:
+        msg = "**ERROR**\n__MUSIC TOO LONG__"
         answers.append(
             InlineQueryResultArticle(
                 title="ERROR",
-                description="THIS FEATURE IS ONLY FOR SUDO USERS",
+                description="MUSIC TOO LONG",
                 input_message_content=InputTextMessageContent(msg),
             )
         )
         return answers
-    if "http" not in url:
-        url = (await arq.youtube(url)).result[0]
-        url = f"https://youtube.com{url.url_suffix}"
     (
         title,
         performer,
         duration,
         audio,
         thumbnail,
-    ) = await download_youtube_audio(url)
+    ) = music
     m = await app.send_audio(
         MESSAGE_DUMP_CHAT,
         audio,