-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRPC.py
204 lines (168 loc) · 7.18 KB
/
RPC.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
import requests
from bs4 import BeautifulSoup
import re
from pypresence import Presence
import time
import os
from colorama import Fore
import ctypes
from tabulate import tabulate
cfp = "config.txt"
def GetStatus():
try:
with open("index.html", "r", encoding="utf-8") as file:
html_content = file.read()
match = re.search(r'"status_audio":\s*({.*?})', html_content, re.DOTALL)
if match:
status_audio_json = match.group(1)
print("Found 'status_audio' in the HTML content:")
print(status_audio_json)
return status_audio_json
else:
print("where is status_audio")
except Exception as e:
print(f"cant read html: {e}")
try:
with open(cfp, "r") as file:
lines = file.read().strip().split("\n")
if len(lines) < 2:
raise ValueError("Invalid format in config.txt")
username = lines[0].strip()
lang = lines[1].strip()
if not username:
raise ValueError("Username is empty in config.txt")
if not lang:
raise ValueError("Language is empty in config.txt")
except FileNotFoundError:
print(f"ваше имя пользователя VK, (vk username): ")
username = input().strip()
lang = input("выберите язык [RU/EN], (choose language [EN/RU]) : ").strip()
with open(cfp, "w") as file:
file.write(username + "\n" + lang)
def language():
if lang.lower() == "en":
return "en"
elif lang.lower() == "ru":
return "ru"
else:
return "en"
url = f"https://vk.com/{username}"
def set_cmd_window_size(width, height):
std_output_handle = -11
handle = ctypes.windll.kernel32.GetStdHandle(std_output_handle)
buf_size = ctypes.wintypes._COORD(width, height)
ctypes.windll.kernel32.SetConsoleScreenBufferSize(handle, buf_size)
rect = ctypes.wintypes.SMALL_RECT(0, 0, width - 1, height - 1)
ctypes.windll.kernel32.SetConsoleWindowInfo(handle, True, ctypes.byref(rect))
width, height = 70, 21
set_cmd_window_size(width, height)
RPC = Presence(client_id="1184547216287862844")
RPC.connect()
def pro():
print(
Fore.CYAN
+ """
██╗░░░██╗██╗░░██╗ ██████╗░██████╗░░█████╗░
██║░░░██║██║░██╔╝ ██╔══██╗██╔══██╗██╔══██╗
╚██╗░██╔╝█████═╝░ ██████╔╝██████╔╝██║░░╚═╝
░╚████╔╝░██╔═██╗░ ██╔══██╗██╔═══╝░██║░░██╗
░░╚██╔╝░░██║░╚██╗ ██║░░██║██║░░░░░╚█████╔╝
░░░╚═╝░░░╚═╝░░╚═╝ ╚═╝░░╚═╝╚═╝░░░░░░╚════╝░
"""
+ Fore.WHITE
)
def clear():
if os.name == "nt":
os.system("cls")
os.system("title VkRPC")
else:
os.system("clear")
DEFAULT_LARGE_IMAGE_URL = "https://upload.wikimedia.org/wikipedia/commons/thumb/f/f3/VK_Compact_Logo_%282021-present%29.svg/2048px-VK_Compact_Logo_%282021-present%29.svg.png"
DEFAULT_SMALL_IMAGE_URL = "https://cdn.sussy.dev/augustf.gif"
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"
}
old_audio_id = "null"
while True:
response = requests.get(url, headers=headers)
if response.status_code == 200:
try:
with open("index.html", "w", encoding="utf-8") as file:
file.write(response.text)
script_tag = GetStatus()
if script_tag:
match = re.search(
r'"artist":"([^"]+)","id":(\d+),"owner_id":(-?\d+),"title":"([^"]+)","duration":(\d+)',
script_tag,
)
if match:
artist = match.group(1)
title = match.group(4)
duration = match.group(5)
audio_id = match.group(2)
owner_id = match.group(3)
if not owner_id.startswith("-"):
owner_id = "-" + owner_id
clear()
pro()
if language() == "en":
data = [
["Artist", artist],
["Title", title],
["Duration", duration],
["Audio ID", audio_id],
["Owner ID", owner_id],
]
else:
data = [
["Исполнитель", artist],
["Название", title],
["Длительность", duration],
["ID аудиозаписи", audio_id],
["ID владельца", owner_id],
]
table = tabulate(
data,
tablefmt="rounded_grid",
numalign="center",
stralign="center",
)
print(table)
if audio_id == old_audio_id:
time.sleep(5)
continue
old_audio_id = audio_id
titleReady = requests.get(
f"https://vk.com/audio{owner_id}_{audio_id}", headers=headers
)
imgSoup = BeautifulSoup(titleReady.content, "html.parser")
imageUrl = DEFAULT_LARGE_IMAGE_URL
img = imgSoup.select_one("div.AudioPlaylistSnippet__cover[style]")
if img:
imageUrl = img["style"].split("'")[1]
if language() == "en":
Rdetail = f"Listening to: {title + ' by ' + artist}"
Rstate = "In VKontakte"
else:
Rdetail = f"Слушает: {title + ' от ' + artist}"
Rstate = "ВКонтакте"
RPC.update(
details=Rdetail,
state=Rstate,
large_image=imageUrl if imageUrl else DEFAULT_LARGE_IMAGE_URL,
small_image=DEFAULT_SMALL_IMAGE_URL,
large_text="vk",
small_text="ivan",
)
else:
print("zesty error occurred couldent find regex thing")
else:
if language() == "ru":
clear()
pro()
print("не могу найти вашу песню, включена ли ваша трансляция?")
except Exception as e:
print(f"Error: {e}")
else:
print(f"request died: {response.status_code}")
time.sleep(3)