-
Notifications
You must be signed in to change notification settings - Fork 1
/
funcs.py
49 lines (45 loc) · 1.3 KB
/
funcs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import yt_dlp, json, re
from client import QUEUE
ydl_opts = {"format": "bestaudio", "no-playlist": True, "geo-bypass": True}
ydl = yt_dlp.YoutubeDL(ydl_opts)
def add_to_queue(chat_id, song_name, from_user):
try:
n = sorted(list(QUEUE[int(chat_id)].keys()))
play_at = n[-1] + 1
except BaseException:
play_at = 1
if QUEUE.get(int(chat_id)):
QUEUE[int(chat_id)].append(
{
"title": song_name,
"from_user": from_user,
}
)
else:
QUEUE.update(
{
int(chat_id): [
{
"title": song_name,
"from_user": from_user,
}
]
}
)
return QUEUE[int(chat_id)]
def get_from_queue(chat_id):
if not QUEUE.get(int(chat_id)):
return None
if len(QUEUE[int(chat_id)]) == 0:
return None
info = QUEUE[int(chat_id)][0]
title = info["title"]
from_user = info["from_user"]
return title, from_user
async def get_yt_dict(query):
if re.search("youtu", query):
omk = ydl.extract_info(f"{query}", download=False)
return omk
omk = ydl.extract_info(f"ytsearch:{query}", download=False)
yt = omk["entries"][0]
return yt