This commit is contained in:
codey 2024-10-08 06:28:02 -04:00
parent b9c6f14273
commit 7c3742cc30

View File

@ -37,9 +37,11 @@ class DiscordPresence:
data = request.json().get('response')
track_artist = data.get('artist')
track_title = data.get('title')
start_time = data.get('start')
end_time = data.get('end')
track = f"{data.get('artist')} - {data.get('title')}"
if self.last_track == track or self.last_updated and (now - self.last_updated < 10):
print(f"Skip: {self.last_track} & {(now - self.last_updated)}")
# print(f"Skip: {self.last_track} & {(now - self.last_updated)}")
time.sleep(5)
continue
self.last_updated = now
@ -52,9 +54,8 @@ class DiscordPresence:
}, json={
'short': True,
}, timeout=(1, 2))
print(f"Rand msg text: {rand_msg_request.text}")
rand_msg = rand_msg_request.json().get('msg').strip()
rand_msg = re.sub(r'(<b>|</b>)', '', re.sub(r'(<br>|<br/>|<br />)', ' ', rand_msg))
rand_msg = re.sub(r'(<b>|</b>)', '', re.sub(r'(<br>|<br/>|<br />|\n|\r\n)', ' ', rand_msg))
if len(rand_msg) > 126:
rand_msg = None
except:
@ -63,23 +64,28 @@ class DiscordPresence:
print(RPC.update(
details=track_title,
state=f"by {track_artist}",
large_image=f"{self.album_art_url}?{now}",
large_text=f"~ {rand_msg}" if rand_msg else None,
state=track_artist,
large_image=f"{self.album_art_url}?t={now}",
large_text=f"{rand_msg}" if rand_msg else None,
start=start_time,
end=end_time,
activity_type=ActivityType.LISTENING,
buttons=[
{
"label": "Site",
"url": "https://codey.lol"
"label": "Listen",
"url": "https://codey.lol/radio"
},]
))
print(f"Track: {track}")
except:
print(traceback.format_exc())
time.sleep(5)
continue
except:
print(traceback.format_exc())
try:
self.loop()
except:
pass