2024-12-15 14:31:30 +01:00
|
|
|
import os
|
|
|
|
import time
|
2024-12-28 21:21:52 +01:00
|
|
|
import subprocess
|
2024-12-15 14:31:30 +01:00
|
|
|
|
|
|
|
def get_folder_size(folder_path):
|
|
|
|
total_size = 0
|
|
|
|
for dirpath, dirnames, filenames in os.walk(folder_path):
|
|
|
|
for filename in filenames:
|
|
|
|
filepath = os.path.join(dirpath, filename)
|
|
|
|
if os.path.exists(filepath):
|
|
|
|
total_size += os.path.getsize(filepath)
|
|
|
|
return total_size
|
|
|
|
|
|
|
|
def delete_files(folder_path, extensions):
|
2024-12-28 21:21:52 +01:00
|
|
|
os.system('sudo pkill -f revivetube.py')
|
|
|
|
process = subprocess.Popen(['sudo', 'nohup', 'python3', 'revivetube.py'])
|
2024-12-15 14:31:30 +01:00
|
|
|
for dirpath, dirnames, filenames in os.walk(folder_path):
|
|
|
|
for filename in filenames:
|
|
|
|
if any(filename.lower().endswith(ext) for ext in extensions):
|
|
|
|
filepath = os.path.join(dirpath, filename)
|
|
|
|
try:
|
|
|
|
os.remove(filepath)
|
2024-12-28 21:21:52 +01:00
|
|
|
except:
|
|
|
|
print("ERROR")
|
2024-12-15 14:31:30 +01:00
|
|
|
|
|
|
|
def monitor_folder(folder_path, size_limit_gb, check_interval):
|
2024-12-28 21:21:52 +01:00
|
|
|
size_limit_bytes = size_limit_gb * 1024 * 1024 * 1024
|
2024-12-15 14:31:30 +01:00
|
|
|
while True:
|
|
|
|
folder_size = get_folder_size(folder_path)
|
|
|
|
if folder_size > size_limit_bytes:
|
|
|
|
delete_files(folder_path, [".flv", ".mp4"])
|
|
|
|
time.sleep(check_interval)
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
folder_to_monitor = "./sigma/videos/"
|
2024-12-28 21:21:52 +01:00
|
|
|
size_limit = 7
|
2024-12-15 14:31:30 +01:00
|
|
|
interval = 5
|
|
|
|
|
2024-12-28 21:21:52 +01:00
|
|
|
monitor_folder(folder_to_monitor, size_limit, interval)
|