#!/home/rouggy/Scripts/ArrDeleteFiles/.venv/bin/python3 import requests import os import logging import glob logging.basicConfig(filename='/home/rouggy/Scripts/ArrDeleteFiles/Sonarr/Sonarr.log', level=logging.DEBUG) PATH_LIST = ["Movies", "Series", "4K-Movies", "4K-Series", "Cartoons", "Kids", "Concerts"] BasePath = "" SourcePath = "" SourceFolder = "" def sendNotifications(title, message, priority): resp = requests.post('https://gotify.rouggy.com/message?token=AKMj5SsZblmpAJ_', json={ "message": message, "priority": priority, "title": title }) try: # Sonarr EventType = os.environ.get('sonarr_eventtype') logging.debug(f"Event Type: {EventType}") SourcePath = os.environ.get('sonarr_episodefile_sourcepath') logging.debug(f"Source Path: {SourcePath}") SourceFolder = os.environ.get('sonarr_episodefile_sourcefolder') logging.debug(f"Source Folder: {SourceFolder}") # Get the folder name of the file to check if movie/serie is inside a folder or not BasePath = os.path.basename(SourceFolder) logging.debug(f"Base Path: {BasePath}") except: logging.warning("Could not get environment variables") if BasePath not in PATH_LIST: try: os.remove(SourcePath) logging.debug(f"Removing file {SourcePath}") for file in glob.glob(SourceFolder + "/*"): os.remove(file) logging.debug(f"Removing file {file} from {SourceFolder}") os.rmdir(SourceFolder) logging.debug(f"Deleting folder {SourceFolder}") except: pass else: try: os.remove(SourcePath) except: pass sendNotifications("Delete Serie", f"Source Path:{SourcePath}", 10)