mirror of
				https://github.com/blakeblackshear/frigate.git
				synced 2025-10-27 10:52:11 +01:00 
			
		
		
		
	new http endpoints
This commit is contained in:
		
							parent
							
								
									251c7fa982
								
							
						
					
					
						commit
						50e898a684
					
				@ -167,6 +167,12 @@ class DetectorConfig():
 | 
				
			|||||||
    def device(self):
 | 
					    def device(self):
 | 
				
			||||||
        return self._device
 | 
					        return self._device
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
 | 
					    def to_dict(self):
 | 
				
			||||||
 | 
					        return {
 | 
				
			||||||
 | 
					            'type': self.type,
 | 
				
			||||||
 | 
					            'device': self.device
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class MqttConfig():
 | 
					class MqttConfig():
 | 
				
			||||||
    def __init__(self, config):
 | 
					    def __init__(self, config):
 | 
				
			||||||
@ -201,6 +207,15 @@ class MqttConfig():
 | 
				
			|||||||
    def password(self):
 | 
					    def password(self):
 | 
				
			||||||
        return self._password
 | 
					        return self._password
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def to_dict(self):
 | 
				
			||||||
 | 
					        return {
 | 
				
			||||||
 | 
					            'host': self.host,
 | 
				
			||||||
 | 
					            'port': self.port,
 | 
				
			||||||
 | 
					            'topic_prefix': self.topic_prefix,
 | 
				
			||||||
 | 
					            'client_id': self.client_id,
 | 
				
			||||||
 | 
					            'user': self.user
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class SaveClipsConfig():
 | 
					class SaveClipsConfig():
 | 
				
			||||||
    def __init__(self, config):
 | 
					    def __init__(self, config):
 | 
				
			||||||
        self._max_seconds = config['max_seconds']
 | 
					        self._max_seconds = config['max_seconds']
 | 
				
			||||||
@ -219,6 +234,13 @@ class SaveClipsConfig():
 | 
				
			|||||||
    def cache_dir(self):
 | 
					    def cache_dir(self):
 | 
				
			||||||
        return self._cache_dir
 | 
					        return self._cache_dir
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
 | 
					    def to_dict(self):
 | 
				
			||||||
 | 
					        return {
 | 
				
			||||||
 | 
					            'max_seconds': self.max_seconds,
 | 
				
			||||||
 | 
					            'clips_dir': self.clips_dir,
 | 
				
			||||||
 | 
					            'cache_dir': self.cache_dir
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class FfmpegConfig():
 | 
					class FfmpegConfig():
 | 
				
			||||||
    def __init__(self, global_config, config):
 | 
					    def __init__(self, global_config, config):
 | 
				
			||||||
        self._input = config.get('input')
 | 
					        self._input = config.get('input')
 | 
				
			||||||
@ -270,6 +292,14 @@ class FilterConfig():
 | 
				
			|||||||
    def min_score(self):
 | 
					    def min_score(self):
 | 
				
			||||||
        return self._min_score
 | 
					        return self._min_score
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
 | 
					    def to_dict(self):
 | 
				
			||||||
 | 
					        return {
 | 
				
			||||||
 | 
					            'min_area': self.min_area,
 | 
				
			||||||
 | 
					            'max_area': self.max_area,
 | 
				
			||||||
 | 
					            'threshold': self.threshold,
 | 
				
			||||||
 | 
					            'min_score': self.min_score
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class ObjectConfig():
 | 
					class ObjectConfig():
 | 
				
			||||||
    def __init__(self, global_config, config):
 | 
					    def __init__(self, global_config, config):
 | 
				
			||||||
        self._track = config.get('track', global_config['track'])
 | 
					        self._track = config.get('track', global_config['track'])
 | 
				
			||||||
@ -286,6 +316,12 @@ class ObjectConfig():
 | 
				
			|||||||
    def filters(self) -> Dict[str, FilterConfig]:
 | 
					    def filters(self) -> Dict[str, FilterConfig]:
 | 
				
			||||||
        return self._filters
 | 
					        return self._filters
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def to_dict(self):
 | 
				
			||||||
 | 
					        return {
 | 
				
			||||||
 | 
					            'track': self.track,
 | 
				
			||||||
 | 
					            'filters': { k: f.to_dict() for k, f in self.filters.items() }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class CameraSnapshotsConfig():
 | 
					class CameraSnapshotsConfig():
 | 
				
			||||||
    def __init__(self, config):
 | 
					    def __init__(self, config):
 | 
				
			||||||
        self._show_timestamp = config['show_timestamp']
 | 
					        self._show_timestamp = config['show_timestamp']
 | 
				
			||||||
@ -314,6 +350,15 @@ class CameraSnapshotsConfig():
 | 
				
			|||||||
    def height(self):
 | 
					    def height(self):
 | 
				
			||||||
        return self._height
 | 
					        return self._height
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
 | 
					    def to_dict(self):
 | 
				
			||||||
 | 
					        return {
 | 
				
			||||||
 | 
					            'show_timestamp': self.show_timestamp,
 | 
				
			||||||
 | 
					            'draw_zones': self.draw_zones,
 | 
				
			||||||
 | 
					            'draw_bounding_boxes': self.draw_bounding_boxes,
 | 
				
			||||||
 | 
					            'crop_to_region': self.crop_to_region,
 | 
				
			||||||
 | 
					            'height': self.height
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class CameraSaveClipsConfig():
 | 
					class CameraSaveClipsConfig():
 | 
				
			||||||
    def __init__(self, config):
 | 
					    def __init__(self, config):
 | 
				
			||||||
        self._enabled = config['enabled']
 | 
					        self._enabled = config['enabled']
 | 
				
			||||||
@ -332,6 +377,13 @@ class CameraSaveClipsConfig():
 | 
				
			|||||||
    def objects(self):
 | 
					    def objects(self):
 | 
				
			||||||
        return self._objects
 | 
					        return self._objects
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
 | 
					    def to_dict(self):
 | 
				
			||||||
 | 
					        return {
 | 
				
			||||||
 | 
					            'enabled': self.enabled,
 | 
				
			||||||
 | 
					            'pre_capture': self.pre_capture,
 | 
				
			||||||
 | 
					            'objects': self.objects
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class ZoneConfig():
 | 
					class ZoneConfig():
 | 
				
			||||||
    def __init__(self, name, config):
 | 
					    def __init__(self, name, config):
 | 
				
			||||||
        self._coordinates = config['coordinates']
 | 
					        self._coordinates = config['coordinates']
 | 
				
			||||||
@ -372,6 +424,11 @@ class ZoneConfig():
 | 
				
			|||||||
    def filters(self):
 | 
					    def filters(self):
 | 
				
			||||||
        return self._filters
 | 
					        return self._filters
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
 | 
					    def to_dict(self):
 | 
				
			||||||
 | 
					        return {
 | 
				
			||||||
 | 
					            'filters': {k: f.to_dict() for k, f in self.filters.items()}
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class CameraConfig():
 | 
					class CameraConfig():
 | 
				
			||||||
    def __init__(self, name, config, cache_dir, global_ffmpeg, global_objects):
 | 
					    def __init__(self, name, config, cache_dir, global_ffmpeg, global_objects):
 | 
				
			||||||
        self._name = name
 | 
					        self._name = name
 | 
				
			||||||
@ -483,10 +540,6 @@ class CameraConfig():
 | 
				
			|||||||
    def best_image_timeout(self):
 | 
					    def best_image_timeout(self):
 | 
				
			||||||
        return self._best_image_timeout
 | 
					        return self._best_image_timeout
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    @property
 | 
					 | 
				
			||||||
    def mqtt(self):
 | 
					 | 
				
			||||||
        return self._mqtt
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
    @property
 | 
					    @property
 | 
				
			||||||
    def zones(self)-> Dict[str, ZoneConfig]:
 | 
					    def zones(self)-> Dict[str, ZoneConfig]:
 | 
				
			||||||
        return self._zones
 | 
					        return self._zones
 | 
				
			||||||
@ -515,6 +568,22 @@ class CameraConfig():
 | 
				
			|||||||
    def ffmpeg_cmd(self):
 | 
					    def ffmpeg_cmd(self):
 | 
				
			||||||
        return self._ffmpeg_cmd
 | 
					        return self._ffmpeg_cmd
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def to_dict(self):
 | 
				
			||||||
 | 
					        return {
 | 
				
			||||||
 | 
					            'name': self.name,
 | 
				
			||||||
 | 
					            'height': self.height,
 | 
				
			||||||
 | 
					            'width': self.width,
 | 
				
			||||||
 | 
					            'fps': self.fps,
 | 
				
			||||||
 | 
					            'best_image_timeout': self.best_image_timeout,
 | 
				
			||||||
 | 
					            'zones': {k: z.to_dict() for k, z in self.zones.items()},
 | 
				
			||||||
 | 
					            'save_clips': self.save_clips.to_dict(),
 | 
				
			||||||
 | 
					            'snapshots': self.snapshots.to_dict(),
 | 
				
			||||||
 | 
					            'objects': self.objects.to_dict(),
 | 
				
			||||||
 | 
					            'frame_shape': self.frame_shape,
 | 
				
			||||||
 | 
					            'ffmpeg_cmd': " ".join(self.ffmpeg_cmd),
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class FrigateConfig():
 | 
					class FrigateConfig():
 | 
				
			||||||
    def __init__(self, config_file=None, config=None):
 | 
					    def __init__(self, config_file=None, config=None):
 | 
				
			||||||
        if config is None and config_file is None:
 | 
					        if config is None and config_file is None:
 | 
				
			||||||
@ -564,6 +633,14 @@ class FrigateConfig():
 | 
				
			|||||||
        
 | 
					        
 | 
				
			||||||
        return config
 | 
					        return config
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
 | 
					    def to_dict(self):
 | 
				
			||||||
 | 
					        return {
 | 
				
			||||||
 | 
					            'detectors': {k: d.to_dict() for k, d in self.detectors.items()},
 | 
				
			||||||
 | 
					            'mqtt': self.mqtt.to_dict(),
 | 
				
			||||||
 | 
					            'save_clips': self.save_clips.to_dict(),
 | 
				
			||||||
 | 
					            'cameras': {k: c.to_dict() for k, c in self.cameras.items()}
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
    @property
 | 
					    @property
 | 
				
			||||||
    def detectors(self) -> Dict[str, DetectorConfig]:
 | 
					    def detectors(self) -> Dict[str, DetectorConfig]:
 | 
				
			||||||
        return self._detectors
 | 
					        return self._detectors
 | 
				
			||||||
 | 
				
			|||||||
@ -8,7 +8,7 @@ import cv2
 | 
				
			|||||||
import numpy as np
 | 
					import numpy as np
 | 
				
			||||||
from flask import (Blueprint, Flask, Response, current_app, jsonify,
 | 
					from flask import (Blueprint, Flask, Response, current_app, jsonify,
 | 
				
			||||||
                   make_response, request)
 | 
					                   make_response, request)
 | 
				
			||||||
from peewee import SqliteDatabase, operator
 | 
					from peewee import SqliteDatabase, operator, fn
 | 
				
			||||||
from playhouse.shortcuts import model_to_dict
 | 
					from playhouse.shortcuts import model_to_dict
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from frigate.models import Event
 | 
					from frigate.models import Event
 | 
				
			||||||
@ -42,6 +42,25 @@ def create_app(frigate_config, database: SqliteDatabase, camera_metrics, detecto
 | 
				
			|||||||
def is_healthy():
 | 
					def is_healthy():
 | 
				
			||||||
    return "Frigate is running. Alive and healthy!"
 | 
					    return "Frigate is running. Alive and healthy!"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@bp.route('/events/summary')
 | 
				
			||||||
 | 
					def events_summary():
 | 
				
			||||||
 | 
					    groups = (
 | 
				
			||||||
 | 
					        Event
 | 
				
			||||||
 | 
					            .select(
 | 
				
			||||||
 | 
					                Event.camera, 
 | 
				
			||||||
 | 
					                Event.label, 
 | 
				
			||||||
 | 
					                fn.strftime('%Y-%m-%d', fn.datetime(Event.start_time, 'unixepoch')).alias('day'), 
 | 
				
			||||||
 | 
					                fn.COUNT(Event.id).alias('count')
 | 
				
			||||||
 | 
					            )
 | 
				
			||||||
 | 
					            .group_by(
 | 
				
			||||||
 | 
					                Event.camera, 
 | 
				
			||||||
 | 
					                Event.label, 
 | 
				
			||||||
 | 
					                fn.strftime('%Y-%m-%d', fn.datetime(Event.start_time, 'unixepoch'))
 | 
				
			||||||
 | 
					            )
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return jsonify([e for e in groups.dicts()])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@bp.route('/events')
 | 
					@bp.route('/events')
 | 
				
			||||||
def events():
 | 
					def events():
 | 
				
			||||||
    limit = request.args.get('limit', 100)
 | 
					    limit = request.args.get('limit', 100)
 | 
				
			||||||
@ -78,7 +97,11 @@ def events():
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    return jsonify([model_to_dict(e) for e in events])
 | 
					    return jsonify([model_to_dict(e) for e in events])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@bp.route('/debug/stats')
 | 
					@bp.route('/config')
 | 
				
			||||||
 | 
					def config():
 | 
				
			||||||
 | 
					    return jsonify(current_app.frigate_config.to_dict())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@bp.route('/stats')
 | 
				
			||||||
def stats():
 | 
					def stats():
 | 
				
			||||||
    camera_metrics = current_app.camera_metrics
 | 
					    camera_metrics = current_app.camera_metrics
 | 
				
			||||||
    stats = {}
 | 
					    stats = {}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user