-
Notifications
You must be signed in to change notification settings - Fork 0
/
stt.py
125 lines (87 loc) · 3.88 KB
/
stt.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
import pymem
import requests
import html
import configparser
from win32clipboard import OpenClipboard, EmptyClipboard, SetClipboardText, CloseClipboard
config = configparser.ConfigParser()
config.read('config.ini')
saveToLog = config.getboolean("Config", "saveToLog")
saveToClipboard = config.getboolean("Config", "saveToClipboard")
prefix, linker, suffix = config["Text"]["prefix"], config["Text"]["linker"], config["Text"]["suffix"]
def getTitleAndArtistFromHtml(html: str):
title = ""
artist = ""
html = html.split("</title>")[0]
html = html.split("<title>")[1]
title, artist = html.split("song and lyrics")
title = title[:-3]
artist = artist[4:]
artist = artist.replace(" | Spotify", "")
return (title, artist)
#chrome_elf.dll+14FA3E string
pm = pymem.Pymem('Spotify.exe', exact_match=True)
client = pymem.process.module_from_name(pm.process_handle, "chrome_elf.dll").lpBaseOfDll
headers = {'Accept-Encoding': 'identity'}
def getStuffs():
songthing = pm.read_string(client + 0x14FA3E)
link = "https://open.spotify.com/track/" + songthing
r = requests.get(link, headers=headers)
content = r.content[:1000]
content = str(content.decode('utf-8'))
content = html.unescape(content)
# content = content.replace("'", "'")
# content = content.replace(""", "\"")
title, artist = getTitleAndArtistFromHtml(content)
return title, artist
def textToClipboard(text: str):
OpenClipboard()
EmptyClipboard()
SetClipboardText(text)
CloseClipboard()
import PySimpleGUI as sg
sg.theme('Dark Blue 3') # please make your windows colorful
layout = [
[sg.Text('Spotify To Text')],
[sg.Text('')],
[sg.Text('Prefix: ', size=(15, 1)), sg.InputText(prefix, key='prefix',size=(20, 1))],
[sg.Text('Linker: ', size=(15, 1)), sg.InputText(linker, key='linker',size=(20, 1))],
[sg.Text('Suffix: ', size=(15, 1)), sg.InputText(suffix, key='suffix',size=(20, 1))],
[sg.Checkbox("Save Output To Log File",default=saveToLog, key="saveToLog"), sg.Checkbox("Save Output To Clipboard",default=saveToClipboard, key="saveToClipboard")],
[sg.Text('')],
[sg.Button("Get Text"), sg.Button("Save to Config")],
[sg.Text('')],
[sg.Text('Output: ', key="output")]
]
window = sg.Window('Spotify To Text', layout, finalize=True)
while True:
event, values = window.read(timeout=20)
if event == sg.WIN_CLOSED:
break
if event == "__TIMEOUT__":
continue
if event != "Get Text" and event != "Save to Config":
continue
try:
saveToLog = window["saveToLog"].Get()
saveToClipboard = window["saveToClipboard"].Get()
prefix, linker, suffix = values['prefix'], values['linker'], values['suffix']
if event == "Save to Config":
if sg.popup_yes_no('Do you really want to save to config?') == 'Yes':
config["Config"]["saveToLog"] = str(saveToLog)
config["Config"]["saveToClipboard"] = str(saveToClipboard)
config["Text"]["prefix"], config["Text"]["linker"], config["Text"]["suffix"] = prefix, linker, suffix
with open('config.ini', 'w') as configfile:
config.write(configfile)
continue
title, artist = getStuffs()
text = prefix + " " + title + " " + linker + " " + artist + suffix
text = str(text)
window["output"].update("Output: " + text)
if saveToLog:
with open("log.txt", 'a', encoding="utf-8") as f:
f.write(text + "\n")
if saveToClipboard:
textToClipboard(text)
except Exception as error:
sg.popup_error(str(error))
window.close()