diff --git a/discord.py b/discord.py new file mode 100644 index 0000000..c2ec840 --- /dev/null +++ b/discord.py @@ -0,0 +1,9 @@ +from pypresence import Presence +import os + +def get_rpc(): + app_id = os.getenv('DISCORD_APP_ID') + RPC = Presence(app_id) + RPC.connect() + return RPC + diff --git a/main.py b/main.py index aaeeddc..6404942 100644 --- a/main.py +++ b/main.py @@ -1,9 +1,29 @@ 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() -media_list = get_active_media(client) -print(media_list) +while True: + media_list = get_active_media(client) + + if len(media_list) == 0: + print("No active media found.") + continue + + media = media_list[0] + + 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'], + ) + time.sleep(15)