Skip to content

Commit

Permalink
Endpoint for last clip (#9710)
Browse files Browse the repository at this point in the history
* Added endpoint for last clip

* Update frigate/http.py

Co-authored-by: Nicolas Mowen <nickmowen213@gmail.com>

* Update docs/docs/integrations/api.md

Co-authored-by: Nicolas Mowen <nickmowen213@gmail.com>

* Update frigate/http.py

Co-authored-by: Nicolas Mowen <nickmowen213@gmail.com>

* Update frigate/http.py

Co-authored-by: Nicolas Mowen <nickmowen213@gmail.com>

* Formatted with ruff

---------

Co-authored-by: Vader <info@vanse.de>
Co-authored-by: Nicolas Mowen <nickmowen213@gmail.com>
  • Loading branch information
3 people authored Mar 2, 2024
1 parent 5028a96 commit 64f142a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/docs/integrations/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,10 @@ Returns a thumbnail for the event id optimized for notifications. Works while th

Returns the thumbnail from the latest event for the given camera and label combo. Using `any` as the label will return the latest thumbnail regardless of type.

### `GET /api/<camera_name>/<label>/clip.mp4`

Returns the clip from the latest event for the given camera and label combo. Using `any` as the label will return the latest clip regardless of type.

### `GET /api/events/<id>/clip.mp4`

Returns the clip for the event id. Works after the event has ended.
Expand Down
19 changes: 19 additions & 0 deletions frigate/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,25 @@ def label_thumbnail(camera_name, label):
return response


@bp.route("/<camera_name>/<label>/clip.mp4")
def label_clip(camera_name, label):
label = unquote(label)
event_query = Event.select(fn.MAX(Event.id)).where(
Event.camera == camera_name, Event.has_clip == True
)
if label != "any":
event_query = event_query.where(Event.label == label)

try:
event = event_query.get()

return event_clip(event)
except DoesNotExist:
return make_response(
jsonify({"success": False, "message": "Event not found"}), 404
)


@bp.route("/events/<id>/snapshot.jpg")
def event_snapshot(id):
download = request.args.get("download", type=bool)
Expand Down

0 comments on commit 64f142a

Please sign in to comment.