This repository has been archived on 2023-12-18. You can view files and clone it, but cannot push or open issues or pull requests.
ArrDeleteFiles/Radarr/delete_files.py
2022-06-05 11:32:56 +07:00

55 lines
1.6 KiB
Python

#!/home/rouggy/Scripts/ArrDeleteFiles/.venv/bin/python3
import requests
import os
import logging
logging.basicConfig(filename='/home/rouggy/Scripts/ArrDeleteFiles/Radarr.log', encoding='utf-8', level=logging.DEBUG)
PATH_LIST = ["Movies", "Series", "4K-Movies", "4K-Series", "Cartoons"]
BasePath = ""
SourcePath = ""
MovieFolder = ""
def sendNotifications(title, message, priority):
resp = requests.post('https://gotify.rouggy.com/message?token=AKMj5SsZblmpAJ_', json={
"message": message,
"priority": priority,
"title": title
})
try:
# Radarr
EventType = os.environ.get('radarr_eventtype')
logging.debug(f"Event Type: {EventType}")
SourcePath = os.environ.get('radarr_moviefile_sourcepath')
logging.debug(f"Source Path: {SourcePath}")
SourceFolder = os.environ.get('radarr_moviefile_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
MovieFolder = os.path.dirname(SourcePath)
logging.debug(f"Movie Folder: {MovieFolder}")
BasePath = os.path.basename(MovieFolder)
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 folder {SourcePath}")
os.rmdir(MovieFolder)
logging.debug(f"Deleting folder {MovieFolder}")
except:
pass
else:
try:
os.remove(SourcePath)
except:
pass
sendNotifications("Delete Movie", f"Source Path:{SourcePath}", 10)