-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTrickmint radio.exe Source.py
205 lines (174 loc) · 5.7 KB
/
Trickmint radio.exe Source.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
205
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from pypresence import Presence
import pickle
import os
import keyboard
import time
import requests
import sys
import webbrowser
# Version checker
CURRENT_VERSION = '1.0'
GITHUB_REPO = 'aleksa07/Trickmint-Radio.exe-Discord-rich-presence'
RELEASE_URL = f'https://api.github.com/repos/{GITHUB_REPO}/releases/latest'
def get_latest_release():
response = requests.get(RELEASE_URL)
response.raise_for_status()
return response.json()
def is_new_version(latest_release):
latest_version = latest_release['tag_name']
return latest_version != CURRENT_VERSION and not latest_release.get('prerelease', False)
def main():
latest_release = get_latest_release()
if is_new_version(latest_release):
print(f"New version available: {latest_release['tag_name']}.")
answer = input("Do you want to open the GitHub releases page to dwonload the update? (y/n): ").strip().lower()
if answer == 'y':
webbrowser.open(f'https://github.com/{GITHUB_REPO}/releases/latest')
sys.exit()
else:
print("You are already using the latest version.")
if __name__ == '__main__':
main()
# The code that makes it work
configfile = 'config.pkl'
def loadconfig():
if os.path.exists(configfile):
with open(configfile, 'rb') as file:
return pickle.load(file)
else:
return {}
def saveconfig(config):
with open(configfile, 'wb') as file:
pickle.dump(config, file)
config = loadconfig()
setup = True
if config.get('Setup'):
if config.get('Browser') == 'Firefox':
driver = webdriver.Firefox()
driver.get('https://trickmint.gay/')
elif config.get('Browser') == 'Chrome':
driver = webdriver.Chrome()
driver.get('https://trickmint.gay/')
elif config.get('Browser') == 'Edge':
driver = webdriver.Edge()
driver.get('https://trickmint.gay/')
elif config.get('Browser') == 'Safari':
driver = webdriver.Safari()
driver.get('https://trickmint.gay/')
else:
print("Runing first time Setup.")
setup = False
def Setup():
num = input("Which browser would you like to use: 1 = Firefox, 2 = Chrome, 3 = Edge, 4 = Safari (untested): ")
try:
if int(num) == 1:
config['Browser'] = 'Firefox'
config['Setup'] = True
saveconfig(config)
return webdriver.Firefox()
elif int(num) == 2:
config['Browser'] = 'Chrome'
config['Setup'] = True
saveconfig(config)
return webdriver.Chrome()
elif int(num) == 3:
config['Browser'] = 'Edge'
config['Setup'] = True
saveconfig(config)
return webdriver.Edge()
elif int(num) == 4:
config['Browser'] = 'Safari'
config['Setup'] = True
saveconfig(config)
return webdriver.Safari()
else:
print("Please enter a number from 1 to 4. Try again.")
return Setup()
except Exception as e:
print(f"Invalid input or browser not installed. Error: {e}")
config['Setup'] = False
saveconfig(config)
return Setup()
if not setup:
driver = Setup()
driver.get('https://trickmint.gay/')
play = True
client_id = '1299741681452843139'
discord_presence = Presence(client_id)
def Connect():
try:
discord_presence.connect()
except Exception as e:
print("Unable to connect to Discord. Retrying in 5 seconds...")
time.sleep(5)
Connect()
Connect()
def playbutton():
try:
play_button = driver.find_element(By.ID, 'playtoggle')
play_button.click()
except Exception as e:
print(f"Error clicking play button: {e}")
def Song():
global play
if not play:
play = True
playbutton()
else:
play = False
playbutton()
def Spearmint():
driver.execute_script("refreshSpearmint();")
def Skipsong():
driver.execute_script("skipSong();")
keyboard.add_hotkey("alt+f9", Song)
keyboard.add_hotkey("alt+f10", Skipsong)
keyboard.add_hotkey("alt+f11", Spearmint)
def whatsong():
global play
if play:
song = driver.execute_script("return titleTxt.textContent;")
return song
def getimgurl():
img = driver.find_element(By.ID, "spearmint")
img = img.get_attribute("src")
return img
def whodraw():
draw = driver.find_element(By.ID, "spearCred")
draw = draw.text
if draw == "by me!":
draw = "by trickmint"
return draw
playbutton()
while True:
try:
Image = getimgurl()
CREDITS = whodraw()
current_song = whatsong()
time.sleep(1)
if play:
discord_presence.update(
state=current_song,
details="Now Playing",
large_image="radioicon",
large_text="Trickmint Radio",
small_image=Image,
small_text=f"spearmint {CREDITS}",
buttons=[{"label": "Trickmint's website", "url": "https://trickmint.gay/"}]
)
else:
discord_presence.update(
state="Not Listening to anything",
details="Boo",
large_image="radioicon",
large_text="Trickmint Radio",
small_image=Image,
small_text=f"spearmint {CREDITS}",
buttons=[{"label": "Trickmint's website", "url": "https://trickmint.gay/"}]
)
except Exception as e:
print(f"Error on discord rich presence: {e}")