add keyboard interrupt handling

This commit is contained in:
2025-12-10 01:16:12 +01:00
parent b577359381
commit a842db2d97
2 changed files with 23 additions and 9 deletions

View File

@@ -18,14 +18,19 @@ class JellyfinApiClient:
self.client.config.app('jellydisc', '0.0.1', machine_name, unique_id)
self.client.config.data['auth.ssl'] = True
self.authenticate()
self.logger.info("Connected to Jellyfin server.")
def authenticate(self):
self.logger.info("Authenticating with Jellyfin server...")
self.client.auth.connect_to_address(settings.jellyfin_server_url)
self.client.auth.login(
settings.jellyfin_server_url,
settings.jellyfin_username,
settings.jellyfin_password
)
self.logger.info("Connected to Jellyfin server.")
self.logger.info("Authenticated with Jellyfin server.")
def get_current_playback(self) -> JellyfinMediaItem | None:
self.logger.info("Fetching current playback information...")

23
main.py
View File

@@ -13,14 +13,23 @@ jellyfinApiClient = JellyfinApiClient()
def main():
while True:
media_item = jellyfinApiClient.get_current_playback()
if not media_item:
discordRPC.clear()
time.sleep(15)
continue
try:
media_item = jellyfinApiClient.get_current_playback()
if not media_item:
discordRPC.clear()
time.sleep(15)
continue
discordRPC.update(to_rpc_payload(media_item))
time.sleep(15)
discordRPC.update(to_rpc_payload(media_item))
time.sleep(15)
except KeyboardInterrupt:
logging.info("Shutting down...")
discordRPC.clear()
break
except:
logging.exception("An error occurred in the main loop.")
jellyfinApiClient.authenticate()
time.sleep(15)
if __name__ == "__main__":
main()