mirror of
				https://github.com/blakeblackshear/frigate.git
				synced 2025-10-27 10:52:11 +01:00 
			
		
		
		
	add download option on clips and snapshots
This commit is contained in:
		
							parent
							
								
									1181620f33
								
							
						
					
					
						commit
						2fbfbf614b
					
				@ -187,6 +187,7 @@ def event_thumbnail(id):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
@bp.route("/events/<id>/snapshot.jpg")
 | 
					@bp.route("/events/<id>/snapshot.jpg")
 | 
				
			||||||
def event_snapshot(id):
 | 
					def event_snapshot(id):
 | 
				
			||||||
 | 
					    download = request.args.get("download", type=bool)
 | 
				
			||||||
    jpg_bytes = None
 | 
					    jpg_bytes = None
 | 
				
			||||||
    try:
 | 
					    try:
 | 
				
			||||||
        event = Event.get(Event.id == id)
 | 
					        event = Event.get(Event.id == id)
 | 
				
			||||||
@ -222,11 +223,17 @@ def event_snapshot(id):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    response = make_response(jpg_bytes)
 | 
					    response = make_response(jpg_bytes)
 | 
				
			||||||
    response.headers["Content-Type"] = "image/jpg"
 | 
					    response.headers["Content-Type"] = "image/jpg"
 | 
				
			||||||
 | 
					    if download:
 | 
				
			||||||
 | 
					        response.headers[
 | 
				
			||||||
 | 
					            "Content-Disposition"
 | 
				
			||||||
 | 
					        ] = f"attachment; filename=snapshot-{id}.jpg"
 | 
				
			||||||
    return response
 | 
					    return response
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@bp.route("/events/<id>/clip.mp4")
 | 
					@bp.route("/events/<id>/clip.mp4")
 | 
				
			||||||
def event_clip(id):
 | 
					def event_clip(id):
 | 
				
			||||||
 | 
					    download = request.args.get("download", type=bool)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    event: Event = Event.get(Event.id == id)
 | 
					    event: Event = Event.get(Event.id == id)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if event is None:
 | 
					    if event is None:
 | 
				
			||||||
@ -246,7 +253,7 @@ def event_clip(id):
 | 
				
			|||||||
    return send_file(
 | 
					    return send_file(
 | 
				
			||||||
        clip_path,
 | 
					        clip_path,
 | 
				
			||||||
        mimetype="video/mp4",
 | 
					        mimetype="video/mp4",
 | 
				
			||||||
        as_attachment=True,
 | 
					        as_attachment=download,
 | 
				
			||||||
        attachment_filename=f"{event.camera}_{start_ts}-{end_ts}.mp4",
 | 
					        attachment_filename=f"{event.camera}_{start_ts}-{end_ts}.mp4",
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -548,6 +555,8 @@ def recordings(camera_name):
 | 
				
			|||||||
@bp.route("/<camera>/start/<int:start_ts>/end/<int:end_ts>/clip.mp4")
 | 
					@bp.route("/<camera>/start/<int:start_ts>/end/<int:end_ts>/clip.mp4")
 | 
				
			||||||
@bp.route("/<camera>/start/<float:start_ts>/end/<float:end_ts>/clip.mp4")
 | 
					@bp.route("/<camera>/start/<float:start_ts>/end/<float:end_ts>/clip.mp4")
 | 
				
			||||||
def recording_clip(camera, start_ts, end_ts):
 | 
					def recording_clip(camera, start_ts, end_ts):
 | 
				
			||||||
 | 
					    download = request.args.get("download", type=bool)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    recordings = (
 | 
					    recordings = (
 | 
				
			||||||
        Recordings.select()
 | 
					        Recordings.select()
 | 
				
			||||||
        .where(
 | 
					        .where(
 | 
				
			||||||
@ -615,6 +624,7 @@ def recording_clip(camera, start_ts, end_ts):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    response = make_response(mp4_bytes)
 | 
					    response = make_response(mp4_bytes)
 | 
				
			||||||
    response.mimetype = "video/mp4"
 | 
					    response.mimetype = "video/mp4"
 | 
				
			||||||
 | 
					    if download:
 | 
				
			||||||
        response.headers[
 | 
					        response.headers[
 | 
				
			||||||
            "Content-Disposition"
 | 
					            "Content-Disposition"
 | 
				
			||||||
        ] = f"attachment; filename={camera}_{start_ts}-{end_ts}.mp4"
 | 
					        ] = f"attachment; filename={camera}_{start_ts}-{end_ts}.mp4"
 | 
				
			||||||
 | 
				
			|||||||
@ -127,10 +127,20 @@ export default function Event({ eventId }) {
 | 
				
			|||||||
            onReady={(player) => {}}
 | 
					            onReady={(player) => {}}
 | 
				
			||||||
          />
 | 
					          />
 | 
				
			||||||
          <div className="text-center">
 | 
					          <div className="text-center">
 | 
				
			||||||
            <Button className="mx-2" color="blue" href={`${apiHost}/api/events/${eventId}/clip.mp4`} download>
 | 
					            <Button
 | 
				
			||||||
 | 
					              className="mx-2"
 | 
				
			||||||
 | 
					              color="blue"
 | 
				
			||||||
 | 
					              href={`${apiHost}/api/events/${eventId}/clip.mp4?download=true`}
 | 
				
			||||||
 | 
					              download
 | 
				
			||||||
 | 
					            >
 | 
				
			||||||
              <Clip className="w-6" /> Download Clip
 | 
					              <Clip className="w-6" /> Download Clip
 | 
				
			||||||
            </Button>
 | 
					            </Button>
 | 
				
			||||||
            <Button className="mx-2" color="blue" href={`${apiHost}/clips/${data.camera}-${eventId}.jpg`} download>
 | 
					            <Button
 | 
				
			||||||
 | 
					              className="mx-2"
 | 
				
			||||||
 | 
					              color="blue"
 | 
				
			||||||
 | 
					              href={`${apiHost}/api/events/${eventId}/snapshot.jpg?download=true`}
 | 
				
			||||||
 | 
					              download
 | 
				
			||||||
 | 
					            >
 | 
				
			||||||
              <Snapshot className="w-6" /> Download Snapshot
 | 
					              <Snapshot className="w-6" /> Download Snapshot
 | 
				
			||||||
            </Button>
 | 
					            </Button>
 | 
				
			||||||
          </div>
 | 
					          </div>
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user