This commit is contained in:
Gregory Salaun 2022-11-21 11:05:25 +07:00
parent 19eafe2318
commit a477c3a167

View File

@ -3,6 +3,7 @@
import requests import requests
import os import os
import logging import logging
import glob
logging.basicConfig(filename='/home/rouggy/Scripts/ArrDeleteFiles/Radarr.log', encoding='utf-8', level=logging.DEBUG) logging.basicConfig(filename='/home/rouggy/Scripts/ArrDeleteFiles/Radarr.log', encoding='utf-8', level=logging.DEBUG)
@ -11,7 +12,7 @@ PATH_LIST = ["Movies", "Series", "4K-Movies", "4K-Series", "Cartoons"]
BasePath = "" BasePath = ""
SourcePath = "" SourcePath = ""
MovieFolder = "" SourceFolder = ""
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={
@ -29,11 +30,8 @@ try:
SourceFolder = os.environ.get('radarr_moviefile_sourcefolder') SourceFolder = os.environ.get('radarr_moviefile_sourcefolder')
logging.debug(f"Source Folder: {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 # Get the folder name of the file to check if movie/serie is inside a folder or not
MovieFolder = os.path.dirname(SourcePath) BasePath = os.path.basename(SourceFolder)
logging.debug(f"Movie Folder: {MovieFolder}")
BasePath = os.path.basename(MovieFolder)
logging.debug(f"Base Path: {BasePath}") logging.debug(f"Base Path: {BasePath}")
except: except:
logging.warning("Could not get environment variables") logging.warning("Could not get environment variables")
@ -41,9 +39,12 @@ except:
if BasePath not in PATH_LIST: if BasePath not in PATH_LIST:
try: try:
os.remove(SourcePath) os.remove(SourcePath)
logging.debug(f"Removing folder {SourcePath}") logging.debug(f"Removing file {SourcePath}")
os.rmdir(MovieFolder) for file in glob.glob(SourceFolder + "/*"):
logging.debug(f"Deleting folder {MovieFolder}") os.remove(file)
logging.debug(f"Removing file {file} from {SourceFolder}")
os.rmdir(SourceFolder)
logging.debug(f"Deleting folder {SourceFolder}")
except: except:
pass pass
else: else: