Update gotify.py

This commit is contained in:
Gregory Salaun 2023-12-18 19:58:32 +07:00
parent fe0cf7b520
commit a4736c9204

264
gotify.py
View File

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