From a44135514a584f83d4a1d7b29c85ab3b69b05382 Mon Sep 17 00:00:00 2001 From: RemiRigal Date: Thu, 5 May 2022 08:48:41 +0200 Subject: [PATCH] Add plex alert listener tool script --- tools/plex_alert_listener.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 tools/plex_alert_listener.py diff --git a/tools/plex_alert_listener.py b/tools/plex_alert_listener.py new file mode 100644 index 0000000..0dea2a0 --- /dev/null +++ b/tools/plex_alert_listener.py @@ -0,0 +1,25 @@ +import time +import json +import argparse +from datetime import datetime +from plexapi.server import PlexServer + + +def callback(message): + message["time"] = datetime.now().isoformat() + print(json.dumps(message)) + + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument("--plex_url", type=str, default="http://localhost:32400", help="Plex URL") + parser.add_argument("--plex_token", type=str, required=True, help="Plex Token") + args = parser.parse_args() + + plex = PlexServer(args.plex_url, args.plex_token) + + notifier = plex.startAlertListener(callback) + + while notifier.is_alive(): + time.sleep(1) + time.sleep(1)