Async library to react to events issued over Plex websockets.
importasyncioimportloggingfromplexapi.serverimportPlexServerfromplexwebsocketimportPlexWebsocket, SIGNAL_CONNECTION_STATElogging.basicConfig(level=logging.DEBUG)
baseurl='http://<PLEX_SERVER_IP>:32400'token='<YOUR_TOKEN_HERE>'plex=PlexServer(baseurl, token)
defprint_info(msgtype, data, error):
ifmsgtype==SIGNAL_CONNECTION_STATE:
print(f"State: {data} / Error: {error}")
else:
print(f"Data: {data}")
asyncdefmain():
ws=PlexWebsocket(plex, print_info, subscriptions=["playing", "status"])
awaitws.listen()
if__name__=='__main__':
loop=asyncio.get_event_loop()
loop.run_until_complete(main())