commit fe0cf7b5200950de410c48487bbed194df1f0c50 Author: Gregory Salaun Date: Fri Dec 1 18:43:31 2023 +0700 first commit diff --git a/gotify.py b/gotify.py new file mode 100755 index 0000000..aefd298 --- /dev/null +++ b/gotify.py @@ -0,0 +1,132 @@ +import requests +import argparse + +# ## EDIT THESE SETTINGS ## +TAUTULLI_APIKEY = "f2083acefd774b05921ab053727a79a7" # Your Tautulli API key +TAUTULLI_URL = "http://localhost:8181/" # Your Tautulli URL +DEFAULT_PRIORITY = 10 +EXEMPTED_USERS = ["rouggy"] +STREAM_SECURED = "" +NOTIFICATONS_TITLE = "Plex-ROuGGy" +PLEX_TV_LIBRARIES = ["Series", "4K Series"] +PLEX_MOVIES_LIBRARIES = ["Movies", "4K-Movies", "Cartoons"] + + +""" +Script to send notifications through Gotify +Author: rouggy +""" + + +def sendNotifications(title, message, priority): + resp = requests.post('https://gotify.rouggy.com/message?token=AKMj5SsZblmpAJ_', json={ + "message": message, + "priority": priority, + "title": title + }) + + +if __name__ == "__main__": + parser = argparse.ArgumentParser( + description="Send notifications to Gotify.") + parser.add_argument('-a', '--action', default="", + help='Action triggering the script.') + parser.add_argument('-st', '--streams', default="", + help='The total number of concurrent streams.') + parser.add_argument('-u', '--user', default="", + help='The friendly name of the user streaming.') + parser.add_argument('-un', '--username', default="", + help='The username of the person streaming.') + parser.add_argument('-d', '--device', default="", + help='The type of client device being used for playback.') + parser.add_argument('-p', '--platform', default="", + help='The type of client platform being used for playback.') + parser.add_argument('-pl', '--player', default="", + help='The type of player being used for playback.') + parser.add_argument('-qp', '--quality_profile', default="", + help='The Plex quality profile of the stream.') + parser.add_argument('-s', '--secure', default="", + help='If the stream is using a secure connection.') + parser.add_argument('-t', '--title', default="", + help='The full title of the item.') + parser.add_argument('-mt', '--media_type', default="", + help='The type of media') + parser.add_argument('-ln', '--library_name', default="", + help='The Library name of the media') + parser.add_argument('-sn', '--show_name', default="", + help='The title of the TV Series') + parser.add_argument('-en', '--episode_name', default="", + help='The Episode name') + parser.add_argument('-snumber', '--season-number', default="", + help='The Season number of the TV Series') + parser.add_argument('-enumber', '--episode_number', default="", + help='Episode number of the TV Series') + + p = parser.parse_args() + + with open("log.txt", "a") as log: + log.write(p.action) + log.write("\n") + log.close() + + if p.secure == "1": + STREAM_SECURED = "Yes" + elif p.secure == "0": + STREAM_SECURED = "No" + + # Plex server is up + if p.action == "intup": + sendNotifications(NOTIFICATONS_TITLE, "The Plex Media Server is up again...", DEFAULT_PRIORITY) + + # Plex server is down + elif p.action == "intdown": + sendNotifications(NOTIFICATONS_TITLE, "The Plex Media Server is down...", DEFAULT_PRIORITY) + + # user starts playing + elif p.action == "play": + if p.user not in EXEMPTED_USERS: + if p.library_name in PLEX_TV_LIBRARIES: + sendNotifications(NOTIFICATONS_TITLE, + f"User: {p.user}\n" + f"Library: {p.library_name}\n" + f"Player: {p.player}\n" + f"Show: {p.show_name}\n" + f"Episode: {p.season_number}x{p.episode_number}\n" + f"Title: {p.episode_name}\n" + f"Secured Stream: {STREAM_SECURED}", + DEFAULT_PRIORITY + ) + else: + sendNotifications(NOTIFICATONS_TITLE, + f"User: {p.user}\n" + f"Library: {p.library_name}\n" + f"Player: {p.player}\n" + f"Title: {p.title}\n" + f"Secured Stream: {STREAM_SECURED}", + DEFAULT_PRIORITY + ) + #User changing the quality of transcode + elif p.action == "change": + if p.user not in EXEMPTED_USERS: + sendNotifications(NOTIFICATONS_TITLE, + f"User: {p.user}\nPlayer: {p.player}\nTranscode: {p.quality_profile}", + DEFAULT_PRIORITY) + + # Recently added to plex library + elif p.action == "created": + + if p.library_name in PLEX_TV_LIBRARIES: + + sendNotifications(NOTIFICATONS_TITLE + " - Added to Plex", + f"Library: {p.library_name}\n" + f"Show: {p.show_name}\n" + f"Episode: {p.season_number}x{p.episode_number}\n" + f"Title: {p.episode_name}", + DEFAULT_PRIORITY + ) + else: + sendNotifications(NOTIFICATONS_TITLE + " - Added to Plex", + f"Library: {p.library_name}\n" + f"Title: {p.title}", + DEFAULT_PRIORITY + )