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