forked from itzme1on/spotify-music-broadcaster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
71 lines (55 loc) · 2.5 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
import time
from bs4 import BeautifulSoup
import requests
from telethon import functions
from telethon.sync import TelegramClient
import bd
api_id = bd.api_id
api_hash = bd.api_hash
default_status = bd.status
current_playing = ''
def shorten_track_name():
tools = [
lambda a: (a.split('—')[0] + '—' + a.split('—')[1].split('(')[0]).strip(),
lambda a: (', '.join(a.split('—')[0].split(', ')[:3]) + ' —' + a.split('—')[1]).strip(),
lambda a: (', '.join(a.split('—')[0].split(', ')[:2]) + ' —' + a.split('—')[1]).strip(),
lambda a: (a.split('—')[0].split(', ')[0] + ' —' + a.split('—')[1]).strip(),
lambda a: (a.split('—')[0].split(' feat. ')[0] + ' —' + a.split('—')[1]).strip(),
lambda a: (a.split('—')[0].split(' ft ')[0] + ' —' + a.split('—')[1]).strip(),
lambda a: (a.split('—')[0].split(' & ')[0] + ' —' + a.split('—')[1]).strip(),
lambda a: (a.split('—')[1]).strip()
]
for tool in tools:
yield tool
def update_status(_current_playing):
response = requests.get(bd.group_link)
current = BeautifulSoup(response.text, features="html.parser").find_all(class_='pp_status')
if current:
track = current[0].contents[0]
music_status = "🎧 VK Музыка | " + track
shorter = shorten_track_name()
while len(music_status) > 70:
try:
track = next(shorter)(track)
music_status = "🎧 VK Музыка | " + track
except StopIteration:
music_status = default_status
if _current_playing != track:
with TelegramClient('anon', api_id, api_hash) as client:
client(functions.account.UpdateProfileRequest(about=music_status))
print(f"🆗 Установил статус: «{music_status}»")
return track
if _current_playing is not None:
with TelegramClient('anon', api_id, api_hash) as client:
client(functions.account.UpdateProfileRequest(about=default_status))
print(f"🆗 Установил статус: «{default_status}»")
time.sleep(10)
return None
if __name__ == '__main__':
print('🚀 Запускаем...')
while True:
try:
time.sleep(5)
current_playing = update_status(current_playing)
except Exception as e:
print(f'⚡ Ошибка: {str(e)}')