-
-
Notifications
You must be signed in to change notification settings - Fork 26
/
main.py
169 lines (143 loc) · 4.43 KB
/
main.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import random
import time
from lyricsgenius import Genius
from pyrogram import Client, filters
from pyromod.helpers import ikb
from utils.configs import Tr, Var
from utils.telegraph import post_to_telegraph
Ly = Client(
"Lyrics Lite Bot",
bot_token=Var.BOT_TOKEN,
api_id=Var.API_ID,
api_hash=Var.API_HASH,
)
genius = Genius(Var.API)
STARTPIC = "https://i.imgur.com/gv2SzKr.jpg"
START_BTN = ikb(
[
[
("💬 Updates Channel", "t.me/damiensoukara", "url"),
("🗣 Support Group", "t.me/damienhelp", "url"),
],
[
("👾 About", "about"),
("📚 Help", "help"),
("❌", "close"),
],
[
(
"🔗 Source Code",
"https://github.com/AmineSoukara/PyLyricsBot/fork",
"url",
),
("👨💻 Developer", "https://bio.link/aminesoukara", "url"),
],
]
)
HOMEBTN = ikb([[("🏠", "home"), ("❌", "close")]])
CLOSEBTN = [("❌", "close")]
@Ly.on_callback_query()
async def cdata(c, q):
data = q.data
# userid = q.from_user.id
pwait = Tr.WAIT
if data == "home":
await q.answer(pwait)
await q.message.edit_text(
text=Tr.START_TEXT.format(q.from_user.mention),
reply_markup=START_BTN,
disable_web_page_preview=True,
)
elif data == "help":
await q.answer(pwait)
await q.message.edit_text(
text=Tr.HELP_TEXT, reply_markup=HOMEBTN, disable_web_page_preview=True
)
elif data == "about":
await q.answer(pwait)
await q.message.edit_text(
text=Tr.ABOUT_TEXT,
reply_markup=HOMEBTN,
disable_web_page_preview=True,
)
elif data == "close":
await q.message.delete(True)
try:
await q.message.reply_to_message.delete(True)
except BaseException:
pass
elif data.startswith("lytr_"):
id = data.split("_", 1)[1]
# lyrics = genius.lyrics(int(id)).replace("URLCopyEmbedCopy", "").replace("EmbedShare", "")
r = genius.search_song(song_id=int(id))
await q.answer(
f"{Tr.SEARCHING}\n\n{Tr.SONG} {r.title}\n{Tr.ARTIST} {r.artist}",
show_alert=True,
)
lyrics = r.lyrics.replace("URLCopyEmbedCopy", "").replace("EmbedShare", "")
test = f"""<p align="center"><a href="#"><img src="{r.song_art_image_url}" width="250"></a></p>"""
final = test + f"{lyrics}\n-\n📜 From : @PyLyricsBot"
song_title = r.title
song_artist = r.artist.replace("&", "ft")
name = f"{song_title} {song_artist}"
# name = f"{r.full_title}"
done = final.replace("\n", "<br/>")
link = post_to_telegraph(name, done)
time.sleep(random.randint(1, 6))
cap = f"{Tr.SONG} {r.title}\n{Tr.ARTIST} {r.artist}\n"
LyBTN = ikb(
[
[
("🔗 Genius", r.url, "url"),
("🔗 Telegraph", link, "url"),
],
[
("❌", "close"),
],
]
)
await q.message.reply_photo(
r.song_art_image_url, caption=cap, reply_markup=LyBTN
)
else:
await q.message.delete()
@Ly.on_message(filters.private & filters.command(["start"]))
async def start(c, m):
await m.reply_photo(
photo=STARTPIC,
caption=Tr.START_TEXT.format(m.from_user.mention),
reply_markup=START_BTN,
)
@Ly.on_message(filters.private & filters.text)
async def lytxt(c, m):
if not Var.API:
return await m.reply_text(
Tr.ERR_TEXT,
quote=True,
# reply_markup=ikb(CLOSEBTN),
)
await m.reply_chat_action("typing")
title = m.text
try:
request = genius.search_songs(title, Var.PAGENUM)
except BaseException:
return await m.reply(
Tr.ERRTOKEN_TEXT,
quote=True,
)
x = [
(f"• {hits['result']['full_title']}", f"lytr_{hits['result']['id']}")
for hits in request["hits"]
]
buttons = list(zip(x[::2], x[1::2]))
if len(x) % 2 == 1:
buttons.append((x[-1],))
if len(x) == 0:
return await m.reply(Tr.NORES)
buttons.append(CLOSEBTN)
await m.reply_text(
text=f"{Tr.SEARCHING} {title}",
quote=True,
reply_markup=ikb(buttons),
)
Ly.run()