diff --git a/daemon/kodi_scan b/daemon/kodi_scan index b23c3dd426e33a22cb16e711e69ce4eddc0cd51c..a18fec88155d6fd611050c1adb4d055e311e05f2 100755 --- a/daemon/kodi_scan +++ b/daemon/kodi_scan @@ -40,11 +40,26 @@ def scan(library=None): scan("audio") +def notify(): + """Send a notification about a finished download.""" + message = f"{TR_TORRENT_NAME} has finished downloading." + data = json.dumps({"message": message}).encode() + request = urllib.request.Request( + "https://notify.shore.co.il/send", + data=data, + method="POST", + headers={"Content-Type": "application/json"}, + ) + # pylint: disable-next=consider-using-with + urllib.request.urlopen(request) # nosec + + TR_DOWNLOADS_DIR = pathlib.Path("/var/lib/transmission/Downloads") TR_MOVIES_DIR = TR_DOWNLOADS_DIR / "Movies" TR_TV_SHOWS_DIR = TR_DOWNLOADS_DIR / "TV Shows" TR_MUSIC_DIR = TR_DOWNLOADS_DIR / "Music" TR_TORRENT_DIR = os.getenv("TR_TORRENT_DIR") +TR_TORRENT_NAME = os.getenv("TR_TORRENT_NAME") if __name__ == "__main__": if TR_TORRENT_DIR is None: @@ -60,3 +75,4 @@ if __name__ == "__main__": scan("audio") else: scan() + notify()