add keyboard interrupt handling
This commit is contained in:
@@ -18,14 +18,19 @@ class JellyfinApiClient:
|
|||||||
self.client.config.app('jellydisc', '0.0.1', machine_name, unique_id)
|
self.client.config.app('jellydisc', '0.0.1', machine_name, unique_id)
|
||||||
self.client.config.data['auth.ssl'] = True
|
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.connect_to_address(settings.jellyfin_server_url)
|
||||||
self.client.auth.login(
|
self.client.auth.login(
|
||||||
settings.jellyfin_server_url,
|
settings.jellyfin_server_url,
|
||||||
settings.jellyfin_username,
|
settings.jellyfin_username,
|
||||||
settings.jellyfin_password
|
settings.jellyfin_password
|
||||||
)
|
)
|
||||||
|
self.logger.info("Authenticated with Jellyfin server.")
|
||||||
self.logger.info("Connected to Jellyfin server.")
|
|
||||||
|
|
||||||
def get_current_playback(self) -> JellyfinMediaItem | None:
|
def get_current_playback(self) -> JellyfinMediaItem | None:
|
||||||
self.logger.info("Fetching current playback information...")
|
self.logger.info("Fetching current playback information...")
|
||||||
|
|||||||
23
main.py
23
main.py
@@ -13,14 +13,23 @@ jellyfinApiClient = JellyfinApiClient()
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
while True:
|
while True:
|
||||||
media_item = jellyfinApiClient.get_current_playback()
|
try:
|
||||||
if not media_item:
|
media_item = jellyfinApiClient.get_current_playback()
|
||||||
discordRPC.clear()
|
if not media_item:
|
||||||
time.sleep(15)
|
discordRPC.clear()
|
||||||
continue
|
time.sleep(15)
|
||||||
|
continue
|
||||||
|
|
||||||
discordRPC.update(to_rpc_payload(media_item))
|
discordRPC.update(to_rpc_payload(media_item))
|
||||||
time.sleep(15)
|
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__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|||||||
Reference in New Issue
Block a user