cleanup empty directories

This commit is contained in:
Blake Blackshear 2020-11-30 21:08:47 -06:00
parent f5c4bfa7b4
commit feb42181de
3 changed files with 21 additions and 6 deletions

View File

@ -116,11 +116,11 @@ class FrigateApp():
def start_event_processor(self):
self.event_processor = EventProcessor(self.config, self.camera_metrics, self.event_queue, self.event_processed_queue, self.stop_event)
self.event_processor.start()
def start_event_cleanup(self):
self.event_cleanup = EventCleanup(self.config, self.stop_event)
self.event_cleanup.start()
def start_recording_maintainer(self):
self.recording_maintainer = RecordingMaintainer(self.config, self.stop_event)
self.recording_maintainer.start()

View File

@ -166,14 +166,16 @@ class EventProcessor(threading.Thread):
# if save clips is not enabled for this camera, just continue
if not save_clips_config.enabled:
self.event_processed_queue.put((event_data['id'], camera))
if event_type == 'end':
self.event_processed_queue.put((event_data['id'], camera))
continue
# if specific objects are listed for this camera, only save clips for them
# TODO: default to all tracked objects rather than checking for None
if save_clips_config.objects:
if not event_data['label'] in save_clips_config.objects:
self.event_processed_queue.put((event_data['id'], camera))
if event_type == 'end':
self.event_processed_queue.put((event_data['id'], camera))
continue
if event_type == 'start':

View File

@ -17,6 +17,18 @@ logger = logging.getLogger(__name__)
SECONDS_IN_DAY = 60 * 60 * 24
def remove_empty_directories(directory):
# list all directories recursively and sort them by path,
# longest first
paths = sorted(
[x[0] for x in os.walk('/media/frigate/recordings/')],
key=lambda p: len(str(p)),
reverse=True,
)
for path in paths:
if len(os.listdir(path)) == 0:
os.rmdir(path)
class RecordingMaintainer(threading.Thread):
def __init__(self, config: FrigateConfig, stop_event):
threading.Thread.__init__(self)
@ -103,9 +115,10 @@ class RecordingMaintainer(threading.Thread):
# only expire events every 10 minutes, but check for new files every 10 seconds
time.sleep(10)
counter = counter + 1
if counter < 60:
if counter > 60:
self.expire_files()
counter = 0
remove_empty_directories(self.record_dir)
counter = 0
self.move_files()