do not update rpc if it's same
This commit is contained in:
35
main.py
35
main.py
@@ -8,22 +8,37 @@ load_dotenv()
|
||||
rpc = get_rpc()
|
||||
client = get_client()
|
||||
|
||||
while True:
|
||||
def generate_media_id(media):
|
||||
return f"{media['artist']}-{media['title']}"
|
||||
|
||||
def main_loop(last_media_id):
|
||||
media_list = get_active_media(client)
|
||||
|
||||
if len(media_list) == 0:
|
||||
print("No active media found.")
|
||||
continue
|
||||
return
|
||||
|
||||
media = media_list[0]
|
||||
media_id = generate_media_id(media)
|
||||
|
||||
print(f"Updating Discord RPC: Listening to {media['title']} by {media['artist']}")
|
||||
if media_id != last_media_id:
|
||||
print(f"Updating Discord RPC: Listening to {media['title']} by {media['artist']}")
|
||||
|
||||
rpc.update(
|
||||
state=f"by {media['artist']}",
|
||||
details=f"Listening to {media['title']}",
|
||||
large_image=media['image'],
|
||||
large_text=media['title'],
|
||||
)
|
||||
return media_id
|
||||
else:
|
||||
print("No change in media. Skipping update.")
|
||||
return last_media_id
|
||||
|
||||
|
||||
rpc.update(
|
||||
state=f"by {media['artist']}",
|
||||
details=f"Listening to {media['title']}",
|
||||
large_image=media['image'],
|
||||
large_text=media['title'],
|
||||
)
|
||||
time.sleep(15)
|
||||
if __name__ == "__main__":
|
||||
last_media_id = None
|
||||
print("Starting Jellyfin Discord Rich Presence...")
|
||||
while True:
|
||||
last_media_id = main_loop(last_media_id)
|
||||
time.sleep(15)
|
||||
|
||||
Reference in New Issue
Block a user