47 lines
1.2 KiB
Python
47 lines
1.2 KiB
Python
from dotenv import load_dotenv
|
|
from jellyfin import get_client, get_active_media
|
|
from discord import get_rpc
|
|
from pypresence.types import ActivityType
|
|
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 = get_active_media(client)
|
|
|
|
if media is None:
|
|
print("No active media found.")
|
|
rpc.clear()
|
|
return None
|
|
|
|
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(
|
|
activity_type=ActivityType.LISTENING,
|
|
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)
|