-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfinder.py
More file actions
102 lines (82 loc) · 3.89 KB
/
Copy pathfinder.py
File metadata and controls
102 lines (82 loc) · 3.89 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
# 0. Env
import requests
import telebot
import io
# 1. Backend
def finder(req):
req = req.replace(' ','+').lower()
user_headers = {
'User-Agent': 'PostmanRuntime/7.29.2',
'Accept': '*/*',
'Accept-Encoding': 'gzip, deflate, br',
'Connection': 'keep-alive',
'Sec-Fetch-Dest': 'script',
'Sec-Fetch-Mode': 'no-cors',
'Sec-Fetch-Site': 'same-origin'
}
url_req = 'https://musicstax.com/search?q=' + req
session = requests.session()
response = session.get(url_req).text.splitlines()
i = 0
while i < len(response):
if response[i].startswith('<a data-cy="song-image" class="song-image search-image" href="/') is True:
song_url = str(response[i])
break
else:
i += 1
try:
song_url = song_url[62:]
song_url = song_url[:(len(song_url)-2)]
song_url = 'https://musicstax.com' + song_url
song_response = session.get(song_url).text.splitlines()
j = 0
while j < len(song_response):
if song_response[j].startswith('<div class="song-meta-title">'):
info = song_response[j+3]
break
else:
j += 1
def trimmer(dump, phrase, starter, stopper):
dump = dump[(dump.find(phrase))+len(phrase):]
if starter is None:
dump = dump[:dump.find(stopper)]
else:
dump = dump[(dump.find(starter))+len(starter):dump.find(stopper)]
return dump
key = trimmer(info,'data-cy="meta-Key-value">',None,'</div>')
tempo = trimmer(info,'data-cy="meta-Tempo-value">',None,'</div>')
song_name = trimmer(info,'data-cy="meta-Name-value">',None,'</div>')
artist_name = trimmer(info,'data-cy="meta-Artist(s)-value"><','<u>','</u>')
album_name = trimmer(info,'data-cy="meta-Album-value"><','<u>','</u>')
release_date = trimmer(info,'data-cy="meta-Release+Date-value">',None,'</div>')
answer = f'I guess you mean <b>"{song_name}</b>"\n'\
f'by <b>{artist_name}</b>\n'\
f'from the album "{album_name}" released on {release_date}\n\n'\
f'-- -- -- -- -- -- -- -- --\n\n'\
f'The song is probably in \n <b>{key}</b> \n\nTempo:\n <b>{tempo}</b> BPM'
return answer
except:
answer = f"Sorry, I didn't find any song. Please specify your request"
return answer
# 2. Bot
tokenTG = io.open('token.txt', mode="r", encoding='utf-8').read()
bot = telebot.TeleBot(tokenTG)
@bot.message_handler(commands=['start', 'help'])
def start(message):
bot_resopnse_on_start = f'<b>Hello, {message.from_user.first_name}</b>\n\n'\
f' This bot will show you the Key and the Tempo of almost any song \n' \
f" Just send me the name of the song and (preferably) it's perfomer \n\n\n\n" \
f'<b>Привет, {message.from_user.first_name}</b>\n\n' \
f' Я умею искать тональность и темп почти любой (зарубежной) песни \n' \
f' Просто отправь мне её название и (чтобы было точнее) исполнителя '
bot.send_message(message.chat.id, bot_resopnse_on_start, parse_mode='html')
@bot.message_handler()
def main(message):
three_hundred_list = ['триста', '300', '150+150']
if message.text == 'testme':
bot.reply_to(message, f'<b>Your Technical Data:</b>\n\n{message}', parse_mode='html')
elif message.text.lower() in three_hundred_list:
bot.reply_to(message, f'<b>ОТСОСИ У ТРАКТОРИСТА АХАХХААХХАХА))))))</b>\n', parse_mode='html')
else:
bot.reply_to(message, finder(message.text), parse_mode='html')
bot.polling(none_stop=True)