This commit is contained in:
Gregory Salaun 2022-12-24 16:48:33 +07:00
parent 44626d8e50
commit 95ca38921d

View File

@ -14,6 +14,20 @@ BasePath = ""
SourcePath = "" SourcePath = ""
SourceFolder = "" SourceFolder = ""
def checkSeasonFolder(SourceFolder):
count = 0
for file in glob.glob(SourceFolder + "/*"):
if file.endswith(".mkv"):
logging.info(f"Found mkv file {file} in the folder: {SourceFolder}")
count += 1
if count > 1:
logging.info("Identified a Season folder")
return True
else:
logging.info("This is not a Season folder")
return False
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,
@ -42,12 +56,14 @@ if BasePath not in PATH_LIST:
os.remove(SourcePath) os.remove(SourcePath)
logging.debug(f"Removing file {SourcePath}") logging.debug(f"Removing file {SourcePath}")
for file in glob.glob(SourceFolder + "/*"): for file in glob.glob(SourceFolder + "/*"):
os.remove(file) if not file.endswith(".mkv"):
logging.debug(f"Removing file {file} from {SourceFolder}") os.remove(file)
os.rmdir(SourceFolder) logging.debug(f"Removing file {file} from {SourceFolder}")
logging.debug(f"Deleting folder {SourceFolder}") if not checkSeasonFolder(SourceFolder):
os.rmdir(SourceFolder)
logging.debug(f"Deleting folder {SourceFolder}")
except: except:
pass logging.warning("Error while trying to delete the files")
else: else:
try: try:
os.remove(SourcePath) os.remove(SourcePath)