Spaces:
Running
Running
Upload 6 files
Browse files- Zaid/helpers/__init__.py +1 -0
- Zaid/helpers/chattitle.py +54 -0
- Zaid/helpers/joiner.py +49 -0
- Zaid/helpers/queues.py +40 -0
- Zaid/helpers/thumbnail.py +138 -0
- Zaid/helpers/yt_dlp.py +69 -0
Zaid/helpers/__init__.py
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
|
Zaid/helpers/chattitle.py
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
async def CHAT_TITLE(ctitle):
|
2 |
+
string = ctitle
|
3 |
+
font1 = list("𝔄𝔅ℭ𝔇𝔈𝔉𝔊ℌℑ𝔍𝔎𝔏𝔐𝔑𝔒𝔓𝔔ℜ𝔖𝔗𝔘𝔙𝔚𝔛𝔜ℨ")
|
4 |
+
font2 = list("𝕬𝕭𝕮𝕯𝕰𝕱𝕲𝕳𝕴𝕵𝕶𝕷𝕸𝕹𝕺𝕻𝕼𝕽𝕾𝕿𝖀𝖁𝖂𝖃𝖄𝖅")
|
5 |
+
font3 = list("𝓐𝓑𝓒𝓓𝓔𝓕𝓖𝓗𝓘𝓙𝓚𝓛𝓜𝓝𝓞𝓟𝓠𝓡𝓢𝓣𝓤𝓥𝓦𝓧𝓨𝓩")
|
6 |
+
font4 = list("𝒜𝐵𝒞𝒟𝐸𝐹𝒢𝐻𝐼𝒥𝒦𝐿𝑀𝒩𝒪𝒫𝒬𝑅𝒮𝒯𝒰𝒱𝒲𝒳𝒴𝒵")
|
7 |
+
font5 = list("𝔸𝔹ℂ𝔻𝔼𝔽𝔾ℍ𝕀𝕁𝕂𝕃𝕄ℕ𝕆ℙℚℝ𝕊𝕋𝕌𝕍𝕎𝕏𝕐ℤ")
|
8 |
+
font6 = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
|
9 |
+
font26 = list("𝐀𝐁𝐂𝐃𝐄𝐅𝐆𝐇𝐈𝐉𝐊𝐋𝐌𝐍𝐎𝐏𝐐𝐑𝐒𝐓𝐔𝐕𝐖𝐗𝐘𝐙")
|
10 |
+
font27 = list("𝗔𝗕𝗖𝗗𝗘𝗙𝗚𝗛𝗜𝗝𝗞𝗟𝗠𝗡𝗢𝗣𝗤𝗥𝗦𝗧𝗨𝗩𝗪𝗫𝗬𝗭")
|
11 |
+
font28 = list("𝘈𝘉𝘊𝘋𝘌𝘍𝘎𝘏𝘐𝘑𝘒𝘓𝘔𝘕𝘖𝘗𝘘𝘙𝘚𝘛𝘜𝘝𝘞𝘟𝘠𝘡")
|
12 |
+
font29 = list("𝘼𝘽𝘾𝘿𝙀𝙁𝙂𝙃𝙄𝙅𝙆𝙇𝙈𝙉𝙊𝙋𝙌𝙍𝙎𝙏𝙐𝙑𝙒𝙓𝙔𝙕")
|
13 |
+
font30 = list("𝙰𝙱𝙲𝙳𝙴𝙵𝙶𝙷𝙸𝙹𝙺𝙻𝙼𝙽𝙾𝙿𝚀𝚁𝚂𝚃𝚄𝚅𝚆𝚇𝚈𝚉")
|
14 |
+
font1L = list("𝔞𝔟𝔠𝔡𝔢𝔣𝔤𝔥𝔦𝔧𝔨𝔩𝔪𝔫𝔬𝔭𝔮𝔯𝔰𝔱𝔲𝔳𝔴𝔵𝔶𝔷")
|
15 |
+
font2L = list("𝖆𝖇𝖈𝖉𝖊𝖋𝖌𝖍𝖎𝖏𝖐𝖑𝖒𝖓𝖔𝖕𝖖𝖗𝖘𝖙𝖚𝖛𝖜𝖝𝖞𝖟")
|
16 |
+
font3L = list("𝓪𝓫𝓬𝓭𝓮𝓯𝓰𝓱𝓲𝓳𝓴𝓵𝓶𝓷𝓸𝓹𝓺𝓻𝓼𝓽𝓾𝓿𝔀𝔁𝔂𝔃")
|
17 |
+
font4L = list("𝒶𝒷𝒸𝒹𝑒𝒻𝑔𝒽𝒾𝒿𝓀𝓁𝓂𝓃𝑜𝓅𝓆𝓇𝓈𝓉𝓊𝓋𝓌𝓍𝓎𝓏")
|
18 |
+
font5L = list("𝕒𝕓𝕔𝕕𝕖𝕗𝕘𝕙𝕚𝕛𝕜𝕝𝕞𝕟𝕠𝕡𝕢𝕣𝕤𝕥𝕦𝕧𝕨𝕩𝕪𝕫")
|
19 |
+
font6L = list("abcdefghijklmnopqrstuvwxyz")
|
20 |
+
font27L = list("𝐚𝐛𝐜𝐝𝐞𝐟𝐠𝐡𝐢𝐣𝐤𝐥𝐦𝐧𝐨𝐩𝐪𝐫𝐬𝐭𝐮𝐯𝐰𝐱𝐲𝐳")
|
21 |
+
font28L = list("𝗮𝗯𝗰𝗱𝗲𝗳𝗴𝗵𝗶𝗷𝗸𝗹𝗺𝗻𝗼𝗽𝗾𝗿𝘀𝘁𝘂𝘃𝘄𝘅𝘆𝘇")
|
22 |
+
font29L = list("𝘢𝘣𝘤𝘥𝘦𝘧𝘨𝘩𝘪𝘫𝘬𝘭𝘮𝘯𝘰𝘱𝘲𝘳𝘴𝘵𝘶𝘷𝘸𝘹𝘺𝘻")
|
23 |
+
font30L = list("𝙖𝙗𝙘𝙙𝙚𝙛𝙜𝙝𝙞𝙟𝙠𝙡𝙢𝙣𝙤𝙥𝙦𝙧𝙨𝙩𝙪𝙫𝙬𝙭𝙮𝙯")
|
24 |
+
font31L = list("𝚊𝚋𝚌𝚍𝚎𝚏𝚐𝚑𝚒𝚓𝚔𝚕𝚖𝚗𝚘𝚙𝚚𝚛𝚜𝚝𝚞𝚟𝚠𝚡𝚢𝚣")
|
25 |
+
normal = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
|
26 |
+
normalL = list("abcdefghijklmnopqrstuvwxyz")
|
27 |
+
# small = list("ᴀʙᴄᴅᴇғɢʜɪᴊᴋʟᴍɴᴏᴘʀsᴛᴜᴠᴡxʏᴢ")
|
28 |
+
cout = 0
|
29 |
+
for XCB in font1:
|
30 |
+
# string = string.replace(small[cout], normal[cout])
|
31 |
+
string = string.replace(font1[cout], normal[cout])
|
32 |
+
string = string.replace(font2[cout], normal[cout])
|
33 |
+
string = string.replace(font3[cout], normal[cout])
|
34 |
+
string = string.replace(font4[cout], normal[cout])
|
35 |
+
string = string.replace(font5[cout], normal[cout])
|
36 |
+
string = string.replace(font6[cout], normal[cout])
|
37 |
+
string = string.replace(font26[cout], normal[cout])
|
38 |
+
string = string.replace(font27[cout], normal[cout])
|
39 |
+
string = string.replace(font28[cout], normal[cout])
|
40 |
+
string = string.replace(font29[cout], normal[cout])
|
41 |
+
string = string.replace(font30[cout], normal[cout])
|
42 |
+
string = string.replace(font1L[cout], normalL[cout])
|
43 |
+
string = string.replace(font2L[cout], normalL[cout])
|
44 |
+
string = string.replace(font3L[cout], normalL[cout])
|
45 |
+
string = string.replace(font4L[cout], normalL[cout])
|
46 |
+
string = string.replace(font5L[cout], normalL[cout])
|
47 |
+
string = string.replace(font6L[cout], normalL[cout])
|
48 |
+
string = string.replace(font27L[cout], normalL[cout])
|
49 |
+
string = string.replace(font28L[cout], normalL[cout])
|
50 |
+
string = string.replace(font29L[cout], normalL[cout])
|
51 |
+
string = string.replace(font30L[cout], normalL[cout])
|
52 |
+
string = string.replace(font31L[cout], normalL[cout])
|
53 |
+
cout += 1
|
54 |
+
return string
|
Zaid/helpers/joiner.py
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from typing import *
|
2 |
+
import random
|
3 |
+
from typing import Dict, List, Union
|
4 |
+
|
5 |
+
from Zaid import *
|
6 |
+
from telethon import *
|
7 |
+
from telethon.errors.rpcerrorlist import (
|
8 |
+
UserAlreadyParticipantError,
|
9 |
+
UserNotParticipantError
|
10 |
+
)
|
11 |
+
from telethon.tl.types import PeerChannel,InputChannel
|
12 |
+
from telethon.tl.functions.channels import *
|
13 |
+
from telethon.tl.functions.channels import GetParticipantsRequest
|
14 |
+
from telethon.tl.types import ChannelParticipantsSearch
|
15 |
+
import telethon
|
16 |
+
from telethon.tl import functions
|
17 |
+
from telethon.tl.functions.channels import LeaveChannelRequest
|
18 |
+
from telethon.tl.functions.messages import ImportChatInviteRequest
|
19 |
+
from telethon.tl.functions.channels import LeaveChannelRequest
|
20 |
+
from telethon.tl.functions.messages import ImportChatInviteRequest
|
21 |
+
from telethon.tl.functions.messages import ExportChatInviteRequest
|
22 |
+
|
23 |
+
|
24 |
+
def AssistantAdd(mystic):
|
25 |
+
async def wrapper(event):
|
26 |
+
try:
|
27 |
+
permissions = await event.client.get_permissions(int(event.chat_id), int(ASSISTANT_ID))
|
28 |
+
except UserNotParticipantError:
|
29 |
+
if event.is_group:
|
30 |
+
try:
|
31 |
+
link = await event.client(ExportChatInviteRequest(event.chat_id))
|
32 |
+
invitelinkk = link.link
|
33 |
+
invitelink = invitelinkk.replace(
|
34 |
+
"https://t.me/+", ""
|
35 |
+
)
|
36 |
+
await client(ImportChatInviteRequest(invitelink))
|
37 |
+
await event.reply(
|
38 |
+
f"Joined Successfully",
|
39 |
+
)
|
40 |
+
except UserAlreadyParticipantError:
|
41 |
+
pass
|
42 |
+
except Exception as e:
|
43 |
+
await event.reply(
|
44 |
+
f"__Assistant Failed To Join__\n\n**Reason**: {e}"
|
45 |
+
)
|
46 |
+
return
|
47 |
+
return await mystic(event)
|
48 |
+
|
49 |
+
return wrapper
|
Zaid/helpers/queues.py
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
QUEUE = {}
|
2 |
+
|
3 |
+
active = []
|
4 |
+
|
5 |
+
async def get_active_chats() -> list:
|
6 |
+
return active
|
7 |
+
|
8 |
+
|
9 |
+
def add_to_queue(chat_id, songname, link, ref, type, quality):
|
10 |
+
if chat_id in QUEUE:
|
11 |
+
chat_queue = QUEUE[chat_id]
|
12 |
+
chat_queue.append([songname, link, ref, type, quality])
|
13 |
+
return int(len(chat_queue) - 1)
|
14 |
+
if chat_id not in active:
|
15 |
+
active.append(chat_id)
|
16 |
+
|
17 |
+
QUEUE[chat_id] = [[songname, link, ref, type, quality]]
|
18 |
+
|
19 |
+
|
20 |
+
def get_queue(chat_id):
|
21 |
+
if chat_id in QUEUE:
|
22 |
+
return QUEUE[chat_id]
|
23 |
+
return 0
|
24 |
+
|
25 |
+
|
26 |
+
def pop_an_item(chat_id):
|
27 |
+
if chat_id not in QUEUE:
|
28 |
+
return 0
|
29 |
+
chat_queue = QUEUE[chat_id]
|
30 |
+
chat_queue.pop(0)
|
31 |
+
return 1
|
32 |
+
|
33 |
+
|
34 |
+
def clear_queue(chat_id: int):
|
35 |
+
if chat_id not in QUEUE:
|
36 |
+
return 0
|
37 |
+
QUEUE.pop(chat_id)
|
38 |
+
if chat_id in active:
|
39 |
+
active.remove(chat_id)
|
40 |
+
return 1
|
Zaid/helpers/thumbnail.py
ADDED
@@ -0,0 +1,138 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import re
|
3 |
+
import textwrap
|
4 |
+
|
5 |
+
import random
|
6 |
+
import aiofiles
|
7 |
+
import aiohttp
|
8 |
+
from PIL import Image, ImageDraw, ImageEnhance, ImageFilter, ImageFont, ImageOps, ImageChops
|
9 |
+
from youtubesearchpython.__future__ import VideosSearch
|
10 |
+
|
11 |
+
MUSIC_BOT_NAME = "Telethon Music"
|
12 |
+
YOUTUBE_IMG_URL = "https://telegra.ph/file/95d96663b73dbf278f28c.jpg"
|
13 |
+
files = []
|
14 |
+
|
15 |
+
for filename in os.listdir("./thumbnail"):
|
16 |
+
if filename.endswith("png"):
|
17 |
+
files.append(filename[:-4])
|
18 |
+
|
19 |
+
def changeImageSize(maxWidth, maxHeight, image):
|
20 |
+
widthRatio = maxWidth / image.size[0]
|
21 |
+
heightRatio = maxHeight / image.size[1]
|
22 |
+
newWidth = int(widthRatio * image.size[0])
|
23 |
+
newHeight = int(heightRatio * image.size[1])
|
24 |
+
newImage = image.resize((newWidth, newHeight))
|
25 |
+
return newImage
|
26 |
+
|
27 |
+
|
28 |
+
def add_corners(im):
|
29 |
+
bigsize = (im.size[0] * 3, im.size[1] * 3)
|
30 |
+
mask = Image.new('L', bigsize, 0)
|
31 |
+
ImageDraw.Draw(mask).ellipse((0, 0) + bigsize, fill=255)
|
32 |
+
mask = mask.resize(im.size, Image.ANTIALIAS)
|
33 |
+
mask = ImageChops.darker(mask, im.split()[-1])
|
34 |
+
im.putalpha(mask)
|
35 |
+
|
36 |
+
|
37 |
+
async def gen_thumb(videoid):
|
38 |
+
anime = random.choice(files)
|
39 |
+
if os.path.isfile(f"cache/{videoid}_{anime}.png"):
|
40 |
+
return f"cache/{videoid}_{anime}.png"
|
41 |
+
url = f"https://www.youtube.com/watch?v={videoid}"
|
42 |
+
try:
|
43 |
+
results = VideosSearch(url, limit=1)
|
44 |
+
for result in (await results.next())["result"]:
|
45 |
+
try:
|
46 |
+
title = result["title"]
|
47 |
+
title = re.sub("\W+", " ", title)
|
48 |
+
title = title.title()
|
49 |
+
except:
|
50 |
+
title = "Unsupported Title"
|
51 |
+
try:
|
52 |
+
duration = result["duration"]
|
53 |
+
except:
|
54 |
+
duration = "Unknown"
|
55 |
+
thumbnail = result["thumbnails"][0]["url"].split("?")[0]
|
56 |
+
try:
|
57 |
+
views = result["viewCount"]["short"]
|
58 |
+
except:
|
59 |
+
views = "Unknown Views"
|
60 |
+
try:
|
61 |
+
channel = result["channel"]["name"]
|
62 |
+
except:
|
63 |
+
channel = "Unknown Channel"
|
64 |
+
|
65 |
+
async with aiohttp.ClientSession() as session:
|
66 |
+
async with session.get(thumbnail) as resp:
|
67 |
+
if resp.status == 200:
|
68 |
+
f = await aiofiles.open(f"cache/thumb{videoid}.png", mode="wb")
|
69 |
+
await f.write(await resp.read())
|
70 |
+
await f.close()
|
71 |
+
|
72 |
+
|
73 |
+
|
74 |
+
youtube = Image.open(f"cache/thumb{videoid}.png")
|
75 |
+
bg = Image.open(f"thumbnail/{anime}.png")
|
76 |
+
image1 = changeImageSize(1280, 720, youtube)
|
77 |
+
image2 = image1.convert("RGBA")
|
78 |
+
background = image2.filter(filter=ImageFilter.BoxBlur(30))
|
79 |
+
enhancer = ImageEnhance.Brightness(background)
|
80 |
+
background = enhancer.enhance(0.6)
|
81 |
+
cir = Image.open(f"thumbnail/IMG_20221129_201846_195.png")
|
82 |
+
image3 = changeImageSize(1280, 720, bg)
|
83 |
+
circle = changeImageSize(1280, 720, cir)
|
84 |
+
image5 = image3.convert("RGBA")
|
85 |
+
Image.alpha_composite(background, image5).save(f"cache/temp{videoid}.png")
|
86 |
+
|
87 |
+
Xcenter = youtube.width / 2
|
88 |
+
Ycenter = youtube.height / 2
|
89 |
+
x1 = Xcenter - 250
|
90 |
+
y1 = Ycenter - 250
|
91 |
+
x2 = Xcenter + 250
|
92 |
+
y2 = Ycenter + 250
|
93 |
+
logo = youtube.crop((x1, y1, x2, y2))
|
94 |
+
logo.thumbnail((520, 520), Image.ANTIALIAS)
|
95 |
+
logo.save(f"cache/chop{videoid}.png")
|
96 |
+
if not os.path.isfile(f"cache/cropped{videoid}.png"):
|
97 |
+
im = Image.open(f"cache/chop{videoid}.png").convert('RGBA')
|
98 |
+
add_corners(im)
|
99 |
+
im.save(f"cache/cropped{videoid}.png")
|
100 |
+
|
101 |
+
crop_img = Image.open(f"cache/cropped{videoid}.png")
|
102 |
+
logo = crop_img.convert("RGBA")
|
103 |
+
logo.thumbnail((365, 365), Image.ANTIALIAS)
|
104 |
+
width = int((1280 - 365)/ 2)
|
105 |
+
background = Image.open(f"cache/temp{videoid}.png")
|
106 |
+
background.paste(logo, (width + 2, 134), mask=logo)
|
107 |
+
background.paste(circle, mask=circle)
|
108 |
+
draw = ImageDraw.Draw(background)
|
109 |
+
font = ImageFont.truetype("thumbnail/font2.ttf", 45)
|
110 |
+
font2 = ImageFont.truetype("thumbnail/font2.ttf", 70)
|
111 |
+
arial = ImageFont.truetype("thumbnail/font2.ttf", 30)
|
112 |
+
name_font = ImageFont.truetype("thumbnail/font.ttf", 30)
|
113 |
+
para = textwrap.wrap(title, width=32)
|
114 |
+
j = 0
|
115 |
+
try:
|
116 |
+
if para[0]:
|
117 |
+
text_w, text_h = draw.textsize(f"{para[0]}", font=font)
|
118 |
+
draw.text(((1280 - text_w)/2, 530), f"{para[0]}", fill="white", stroke_width=1, stroke_fill="white", font=font)
|
119 |
+
if para[1]:
|
120 |
+
text_w, text_h = draw.textsize(f"{para[1]}", font=font)
|
121 |
+
draw.text(((1280 - text_w)/2, 580), f"{para[1]}", fill="white", stroke_width=1, stroke_fill="white", font=font)
|
122 |
+
except:
|
123 |
+
pass
|
124 |
+
text_w, text_h = draw.textsize(f"Duration: {duration} Mins", font=arial)
|
125 |
+
draw.text(((1280 - text_w)/2, 660), f"Duration: {duration} Mins", fill="white", font=arial)
|
126 |
+
|
127 |
+
|
128 |
+
|
129 |
+
|
130 |
+
try:
|
131 |
+
os.remove(f"cache/thumb{videoid}.png")
|
132 |
+
except:
|
133 |
+
pass
|
134 |
+
background.save(f"cache/{videoid}_{anime}.png")
|
135 |
+
return f"cache/{videoid}_{anime}.png"
|
136 |
+
except Exception as e:
|
137 |
+
print(e)
|
138 |
+
return YOUTUBE_IMG_URL
|
Zaid/helpers/yt_dlp.py
ADDED
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import re
|
2 |
+
import hashlib
|
3 |
+
import asyncio
|
4 |
+
import shlex
|
5 |
+
import os
|
6 |
+
from os.path import basename
|
7 |
+
import os.path
|
8 |
+
from PIL import Image
|
9 |
+
from yt_dlp import YoutubeDL
|
10 |
+
from typing import Optional, Union
|
11 |
+
from Zaid import Zaid as bot
|
12 |
+
LOGS = {}
|
13 |
+
SUDO_USERS = {}
|
14 |
+
|
15 |
+
from telethon.tl.functions.channels import GetParticipantRequest
|
16 |
+
from telethon.tl.types import ChannelParticipantAdmin, ChannelParticipantCreator, DocumentAttributeFilename
|
17 |
+
|
18 |
+
|
19 |
+
|
20 |
+
|
21 |
+
async def is_admin(chat_id, user_id):
|
22 |
+
req_jo = await bot(GetParticipantRequest(
|
23 |
+
channel=chat_id,
|
24 |
+
user_id=user_id
|
25 |
+
))
|
26 |
+
chat_participant = req_jo.participant
|
27 |
+
if isinstance(
|
28 |
+
chat_participant,
|
29 |
+
ChannelParticipantCreator) or isinstance(
|
30 |
+
chat_participant,
|
31 |
+
ChannelParticipantAdmin):
|
32 |
+
return True
|
33 |
+
return False
|
34 |
+
|
35 |
+
|
36 |
+
|
37 |
+
|
38 |
+
|
39 |
+
# https://github.com/TeamUltroid/pyUltroid/blob/31c271cf4d35ab700e5880e952e54c82046812c2/pyUltroid/functions/helper.py#L154
|
40 |
+
|
41 |
+
|
42 |
+
async def bash(cmd):
|
43 |
+
process = await asyncio.create_subprocess_shell(
|
44 |
+
cmd,
|
45 |
+
stdout=asyncio.subprocess.PIPE,
|
46 |
+
stderr=asyncio.subprocess.PIPE,
|
47 |
+
)
|
48 |
+
stdout, stderr = await process.communicate()
|
49 |
+
err = stderr.decode().strip()
|
50 |
+
out = stdout.decode().strip()
|
51 |
+
return out, err
|
52 |
+
|
53 |
+
|
54 |
+
ydl_opts = {
|
55 |
+
"format": "best",
|
56 |
+
"geo-bypass": True,
|
57 |
+
"noprogress": True,
|
58 |
+
"user-agent": "Mozilla/5.0 (Linux; Android 7.0; k960n_mt6580_32_n) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.101 Safari/537.36",
|
59 |
+
"extractor-args": "youtube:player_client=all",
|
60 |
+
"nocheckcertificate": True,
|
61 |
+
"outtmpl": "downloads/%(id)s.%(ext)s",
|
62 |
+
}
|
63 |
+
ydl = YoutubeDL(ydl_opts)
|
64 |
+
|
65 |
+
|
66 |
+
def download_lagu(url: str) -> str:
|
67 |
+
info = ydl.extract_info(url, download=False)
|
68 |
+
ydl.download([url])
|
69 |
+
return os.path.join("downloads", f"{info['id']}.{info['ext']}")
|