Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add timelapse support #470

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion protect_archiver/cli/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,27 @@
envvar="PROTECT_USE_UTC",
show_envvar=True,
)
@click.option(
"--timelapse",
is_flag=True,
default=Config.TIMELAPSE,
show_default=True,
required=False,
help="Export a timelapse video. Note: must use in conjunction with FPS",
envvar="PROTECT_TIMELAPSE",
show_envvar=True,
)
@click.option(
"--fps",
default=Config.FPS,
show_default=True,
required=False,
help="Frames Per Second for the exported video (options are 4, 8, 20, or 40). " \
"Note: must be used in conjunction with TIMELAPSE option",
envvar="PROTECT_FPS",
show_envvar=True,
)

def download(
dest: str,
address: str,
Expand All @@ -240,6 +261,9 @@ def download(
disable_splitting: bool,
create_snapshot: bool,
use_utc_filenames: bool,
timelapse: bool,
fps: str,

) -> None:
# check the provided command line arguments
# TODO(danielfernau): remove exit codes 1 (path invalid) and 6 (start/end/snapshot) from docs: no longer valid
Expand All @@ -266,6 +290,8 @@ def download(
touch_files=touch_files,
download_timeout=download_timeout,
use_utc_filenames=use_utc_filenames,
timelapse=timelapse,
fps=fps,
)

try:
Expand All @@ -288,7 +314,7 @@ def download(
)

Downloader.download_footage(
client, start, end, camera, disable_alignment, disable_splitting
client, start, end, camera, disable_alignment, disable_splitting, timelapse, fps
)
else:
click.echo(
Expand Down
4 changes: 4 additions & 0 deletions protect_archiver/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ def __init__(
# aka read_timeout - time to wait until a socket read response happens
download_timeout: float = Config.DOWNLOAD_TIMEOUT,
use_utc_filenames: bool = Config.USE_UTC_FILENAMES,
timelapse: bool = Config.TIMELAPSE,
fps: str = Config.FPS,
) -> None:
self.protocol = protocol
self.address = address
Expand All @@ -46,6 +48,8 @@ def __init__(
self.skip_existing_files = skip_existing_files
self.touch_files = touch_files
self.use_utc_filenames = use_utc_filenames
self.timelapse = timelapse
self.fps = fps

self.destination_path = path.abspath(destination_path)

Expand Down
2 changes: 2 additions & 0 deletions protect_archiver/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ def __init__(self) -> None:
)
MAX_RETRIES: int = 3
USE_UTC_FILENAMES: bool = False
TIMELAPSE: bool = False
FPS: str = None
4 changes: 3 additions & 1 deletion protect_archiver/downloader/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ def download_footage(
camera: Any,
disable_alignment: bool = Config.DISABLE_ALIGNMENT,
disable_splitting: bool = Config.DISABLE_SPLITTING,
timelapse: bool = Config.TIMELAPSE,
fps: str = Config.FPS
) -> Any:
return download_footage(client, start, end, camera, disable_alignment, disable_splitting)
return download_footage(client, start, end, camera, disable_alignment, disable_splitting, timelapse, fps)

@staticmethod
def download_snapshot(client: Any, start: datetime, camera: Any) -> Any:
Expand Down
6 changes: 5 additions & 1 deletion protect_archiver/downloader/download_footage.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ def download_footage(
camera: Camera,
disable_alignment: bool = False,
disable_splitting: bool = False,
timelapse: bool = False,
fps: str = None,
) -> None:
# make camera name safe for use in file name
camera_name_fs_safe = make_camera_name_fs_safe(camera)
Expand Down Expand Up @@ -72,7 +74,9 @@ def download_footage(
open(filename, "a").close()

# build video export query
video_export_query = f"/video/export?camera={camera.id}&start={js_timestamp_range_start}&end={js_timestamp_range_end}"
video_export_query = f"/video/export?camera={camera.id}&start={js_timestamp_range_start}&end={js_timestamp_range_end}"
if timelapse:
video_export_query = video_export_query + f"&type=timelapse&fps={fps}"

# download the file
download_file(client, video_export_query, filename)