46 lines
1.1 KiB
Python
46 lines
1.1 KiB
Python
from dotenv import load_dotenv
|
|
from jellyfin import get_client, get_active_media
|
|
from discord import get_rpc
|
|
import time
|
|
|
|
load_dotenv()
|
|
|
|
rpc = get_rpc()
|
|
client = get_client()
|
|
|
|
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.")
|
|
rpc.clear()
|
|
return
|
|
|
|
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']}")
|
|
|
|
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
|
|
|
|
|
|
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)
|