mirror of
				https://github.com/blakeblackshear/frigate.git
				synced 2025-10-27 10:52:11 +01:00 
			
		
		
		
	cleanup empty directories
This commit is contained in:
		
							parent
							
								
									f5c4bfa7b4
								
							
						
					
					
						commit
						feb42181de
					
				@ -166,14 +166,16 @@ class EventProcessor(threading.Thread):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            # if save clips is not enabled for this camera, just continue
 | 
					            # if save clips is not enabled for this camera, just continue
 | 
				
			||||||
            if not save_clips_config.enabled:
 | 
					            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
 | 
					                continue
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            # if specific objects are listed for this camera, only save clips for them
 | 
					            # if specific objects are listed for this camera, only save clips for them
 | 
				
			||||||
            # TODO: default to all tracked objects rather than checking for None
 | 
					            # TODO: default to all tracked objects rather than checking for None
 | 
				
			||||||
            if save_clips_config.objects:
 | 
					            if save_clips_config.objects:
 | 
				
			||||||
                if not event_data['label'] in 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
 | 
					                    continue
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if event_type == 'start':
 | 
					            if event_type == 'start':
 | 
				
			||||||
 | 
				
			|||||||
@ -17,6 +17,18 @@ logger = logging.getLogger(__name__)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
SECONDS_IN_DAY = 60 * 60 * 24
 | 
					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):
 | 
					class RecordingMaintainer(threading.Thread):
 | 
				
			||||||
    def __init__(self, config: FrigateConfig, stop_event):
 | 
					    def __init__(self, config: FrigateConfig, stop_event):
 | 
				
			||||||
        threading.Thread.__init__(self)
 | 
					        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
 | 
					            # only expire events every 10 minutes, but check for new files every 10 seconds
 | 
				
			||||||
            time.sleep(10)
 | 
					            time.sleep(10)
 | 
				
			||||||
            counter = counter + 1
 | 
					            counter = counter + 1
 | 
				
			||||||
            if counter < 60:
 | 
					            if counter > 60:
 | 
				
			||||||
                self.expire_files()
 | 
					                self.expire_files()
 | 
				
			||||||
            counter = 0
 | 
					                remove_empty_directories(self.record_dir)
 | 
				
			||||||
 | 
					                counter = 0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            self.move_files()
 | 
					            self.move_files()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user