35 lines
889 B
Python
35 lines
889 B
Python
from discord.rpc import DiscordRPC
|
|
from jellyfin.api_client import JellyfinApiClient
|
|
from settings import settings
|
|
import coloredlogs
|
|
import logging
|
|
import time
|
|
|
|
|
|
def main():
|
|
coloredlogs.install(
|
|
level=logging.INFO,
|
|
fmt='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
|
|
|
discord_rpc = DiscordRPC()
|
|
jellyfin_api_client = JellyfinApiClient()
|
|
|
|
while True:
|
|
try:
|
|
media_item = jellyfin_api_client.get_current_media()
|
|
if not media_item:
|
|
discord_rpc.clear()
|
|
time.sleep(settings.poll_interval)
|
|
continue
|
|
|
|
discord_rpc.update(media_item.to_rpc_payload())
|
|
time.sleep(settings.poll_interval)
|
|
except KeyboardInterrupt:
|
|
logging.info("Shutting down...")
|
|
discord_rpc.clear()
|
|
break
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|