-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathfind_music.py
More file actions
111 lines (98 loc) · 4.25 KB
/
find_music.py
File metadata and controls
111 lines (98 loc) · 4.25 KB
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
import asyncio
import json
import os
from pyrogram import Client, filters
from command import fox_command, fox_sudo, who_message
from requirements_installer import install_library
install_library("lyricsgenius requests -U")
import requests
from lyricsgenius import Genius
api_token = '9JiBRxKAEgfssIWg3Yw8uxKyDO0HZr1IQS5qVYQiKMLwJ4d_9tEMxxYlm3w_mIML'
l = Genius(api_token)
@Client.on_message(fox_command(["l", "lyrics"], "FindMusic", os.path.basename(__file__), "[song_name]") & fox_sudo())
async def send_music(client, message):
message = await who_message(client, message)
if len(message.text.split()) >= 2:
await client.edit_message_text(message.chat.id, message.id, 'Searching text...')
url = {"Authorization": f"Bearer {api_token}"}
song_name = ' '.join(message.text.split()[1:])
text = song_name.lower().replace(' ', '%20')
q = requests.get(f'https://api.genius.com/search?q={text}', headers=url).text
data_dict = json.loads(q)
try:
url_song = data_dict['response']['hits'][0]['result']['url']
lyrics = l.lyrics(song_url=url_song).replace('Embed','')
with open('song_text.txt','w+',encoding='utf-8') as file:
file.write(lyrics)
await client.send_document(message.chat.id, 'song_text.txt', caption='Keep the lyrics this song!',message_thread_id=message.message_thread_id)
os.remove('song_text.txt')
except Exception as e:
await client.edit_message_text(message.chat.id, message.id, "I can't find text!")
else:
await client.edit_message_text(message.chat.id, message.id, 'Give me a name song!')
@Client.on_message(fox_command(["dm", "dmusic"], "FindMusic", os.path.basename(__file__), "[song_name]") & fox_sudo())
async def d_send_music(client, message):
message = await who_message(client, message)
bots = "DeezerMusicBot"
await message.edit("Search...")
song_name = ""
if len(message.command) > 1:
song_name = " ".join(message.command[1:])
elif message.reply_to_message and len(message.command) == 1:
song_name = (
message.reply_to_message.text or message.reply_to_message.caption
)
elif not message.reply_to_message and len(message.command) == 1:
await message.edit("Enter the name of the music")
await asyncio.sleep(2)
await message.delete()
return
song_results = await client.get_inline_bot_results(bots, song_name)
try:
saved = await client.send_inline_bot_result(
chat_id="me",
query_id=song_results.query_id,
result_id=song_results.results[0].id,
)
await client.send_audio(
chat_id=message.chat.id,
audio=str(saved.audio.file_id),
message_thread_id=message.message_thread_id
)
await client.delete_messages("me", saved.id)
except TimeoutError:
await message.edit("That didn't work out")
except:
await message.edit("I can't find music!")
await asyncio.sleep(2)
await message.delete()
@Client.on_message(fox_command(["lm", "lmusic"], "FindMusic", os.path.basename(__file__), "[song_name]") & fox_sudo())
async def l_send_music(client, message):
message = await who_message(client, message)
bots = "LosslessRobot"
await message.edit("Search...")
song_name = ""
if len(message.command) > 1:
song_name = " ".join(message.command[1:])
elif message.reply_to_message and len(message.command) == 1:
song_name = (
message.reply_to_message.text or message.reply_to_message.caption
)
elif not message.reply_to_message and len(message.command) == 1:
await message.edit("Enter the name of the music")
await asyncio.sleep(2)
await message.delete()
return
song_results = await client.get_inline_bot_results(bots, song_name)
try:
saved = await client.send_inline_bot_result(
chat_id=message.chat.id,
query_id=song_results.query_id,
result_id=song_results.results[0].id,
)
except TimeoutError:
await message.edit("That didn't work out")
except:
await message.edit("I can't find music!")
await asyncio.sleep(2)
await message.delete()