Files
OctoPrint/src/octoprint/server/api/timelapse.py
T
Gina Häußge f580acaf70 Added post roll to timelapse
You can now define an amount of seconds that should be added to the rendered timelapse (so, since the current fps setting is 25 frames per seconds, 25 * the configured amount of post roll seconds images will need to be captured).

Timed timelapses add this to the actual run time of the timelapse capturing process (so if you configure 1s post roll, a timed timelapse will run 25s longer than the print)

Z-triggered timelapses just create one last capture from the webcam and use this image again and again (so 25 times for a post roll of 1s).

Implements #384
2014-03-05 20:52:25 +01:00

97 lines
2.5 KiB
Python

# coding=utf-8
__author__ = "Gina Häußge <osd@foosel.net>"
__license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html'
import os
from flask import request, jsonify, url_for
from werkzeug.utils import secure_filename
import octoprint.timelapse
import octoprint.util as util
from octoprint.settings import settings, valid_boolean_trues
from octoprint.server import restricted_access, admin_permission
from octoprint.server.util import redirectToTornado
from octoprint.server.api import api
#~~ timelapse handling
@api.route("/timelapse", methods=["GET"])
def getTimelapseData():
timelapse = octoprint.timelapse.current
config = {"type": "off"}
if timelapse is not None and isinstance(timelapse, octoprint.timelapse.ZTimelapse):
config["type"] = "zchange"
config["postRoll"] = timelapse.postRoll()
elif timelapse is not None and isinstance(timelapse, octoprint.timelapse.TimedTimelapse):
config["type"] = "timed"
config["postRoll"] = timelapse.postRoll()
config.update({
"interval": timelapse.interval()
})
files = octoprint.timelapse.getFinishedTimelapses()
for file in files:
file["url"] = url_for("index") + "downloads/timelapse/" + file["name"]
return jsonify({
"config": config,
"files": files
})
@api.route("/timelapse/<filename>", methods=["GET"])
def downloadTimelapse(filename):
return redirectToTornado(request, url_for("index") + "downloads/timelapse/" + filename)
@api.route("/timelapse/<filename>", methods=["DELETE"])
@restricted_access
def deleteTimelapse(filename):
if util.isAllowedFile(filename, {"mpg"}):
secure = os.path.join(settings().getBaseFolder("timelapse"), secure_filename(filename))
if os.path.exists(secure):
os.remove(secure)
return getTimelapseData()
@api.route("/timelapse", methods=["POST"])
@restricted_access
def setTimelapseConfig():
if "type" in request.values:
config = {
"type": request.values["type"],
"postRoll": 0,
"options": {}
}
if "postRoll" in request.values:
try:
config["postRoll"] = int(request.values["postRoll"])
except ValueError:
pass
if "interval" in request.values:
interval = 10
try:
interval = int(request.values["interval"])
except ValueError:
pass
config["options"] = {
"interval": interval
}
if admin_permission.can() and "save" in request.values and request.values["save"] in valid_boolean_trues:
octoprint.timelapse.configureTimelapse(config, True)
else:
octoprint.timelapse.configureTimelapse(config)
return getTimelapseData()