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 support for environment variables #409

Merged
merged 4 commits into from
Feb 11, 2024
Merged
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
38 changes: 38 additions & 0 deletions protect_archiver/cli/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,40 +18,52 @@
show_default=True,
required=True,
help="IP address or hostname of the UniFi Protect Server",
envvar="PROTECT_ADDRESS",
show_envvar=True,
)
@click.option(
"--port",
default=Config.PORT,
show_default=True,
required=False,
help="The port of the UniFi Protect Server",
envvar="PROTECT_PORT",
show_envvar=True,
)
@click.option(
"--not-unifi-os",
is_flag=True,
default=False,
show_default=True,
help="Use this for systems without UniFi OS",
envvar="PROTECT_NOT_UNIFI_OS",
show_envvar=True,
)
@click.option(
"--username",
required=True,
help="Username of user with local access.",
prompt="Username of local Protect user",
envvar="PROTECT_USERNAME",
show_envvar=True,
)
@click.option(
"--password",
required=True,
help="Password of user with local access",
prompt="Password for local Protect user",
hide_input=True,
envvar="PROTECT_PASSWORD",
show_envvar=True,
)
@click.option(
"--verify-ssl",
is_flag=True,
default=False,
show_default=True,
help="Verify Protect SSL certificate",
envvar="PROTECT_VERIFY_SSL",
show_envvar=True,
)
@click.option(
"--cameras",
Expand All @@ -61,27 +73,35 @@
"Comma-separated list of one or more camera IDs ('--cameras=\"id_1,id_2,id_3,...\"'). "
"Use '--cameras=all' to download footage of all available cameras."
),
envvar="PROTECT_CAMERAS",
show_envvar=True,
)
@click.option(
"--wait-between-downloads",
"download_wait",
default=0,
show_default=True,
help="Time to wait between file downloads, in seconds",
envvar="PROTECT_WAIT_BETWEEN_DOWNLOADS",
show_envvar=True,
)
@click.option(
"--ignore-failed-downloads",
is_flag=True,
default=False,
show_default=True,
help="Ignore failed downloads and continue with next download",
envvar="PROTECT_IGNORE_FAILED_DOWNLOADS",
show_envvar=True,
)
@click.option(
"--skip-existing-files",
is_flag=True,
default=False,
show_default=True,
help="Skip downloading files which already exist on disk",
envvar="PROTECT_SKIP_EXISTING",
show_envvar=True,
)
@click.option(
"--touch-files",
Expand All @@ -92,19 +112,25 @@
"Create local file without content for current download - "
"useful in combination with '--skip-existing-files' to skip problematic segments"
),
envvar="PROTECT_TOUCH_FILES",
show_envvar=True,
)
@click.option(
"--use-subfolders/--no-use-subfolders",
default=True,
show_default=True,
help="Save footage to folder structure with format 'YYYY/MM/DD/camera_name/'",
envvar="PROTECT_USE_SUBFOLDERS",
show_envvar=True,
)
@click.option(
"--download-request-timeout",
"download_timeout",
default=60.0,
show_default=True,
help="Time to wait before aborting download request, in seconds",
envvar="PROTECT_DOWNLOAD_TIMEOUT",
show_envvar=True,
)
@click.option(
"--start",
Expand All @@ -122,6 +148,8 @@
# TODO(danielfernau): uncomment the next line as soon as the feature is implemented
# "If omitted, the time of the first available recording for each camera will be used."
),
envvar="PROTECT_START_TIME",
show_envvar=True,
)
@click.option(
"--end",
Expand All @@ -139,6 +167,8 @@
# TODO(danielfernau): uncomment the next line as soon as the feature is implemented
# "If omitted, the time of the last available recording for each camera will be used."
),
envvar="PROTECT_END_TIME",
show_envvar=True,
)
@click.option(
"--disable-alignment",
Expand All @@ -150,6 +180,8 @@
"Disables alignment of the 1-hour segments to absolute hours. "
"If set, results in 8:45, 9:45, 10:45 instead of 8:45, 9:00, 10:00, 10:45."
),
envvar="PROTECT_DISABLE_ALIGNMENT",
show_envvar=True,
)
@click.option(
"--disable-splitting",
Expand All @@ -162,6 +194,8 @@
"USE WITH CAUTION: requesting segments longer than 1 hour via the "
"API can cause the Protect console to crash and restart unexpectedly."
),
envvar="PROTECT_DISABLE_SPLITTING",
show_envvar=True,
)
@click.option(
"--snapshot",
Expand All @@ -173,13 +207,17 @@
"Capture and download a snapshot from the specified camera(s). "
"This flag cannot be used in combination with the normal video download mode."
),
envvar="PROTECT_CREATE_SNAPSHOT",
show_envvar=True,
)
@click.option(
"--use-utc-filenames",
is_flag=True,
default=False,
show_default=True,
help="Use UTC timestamp in file names instead of local time",
envvar="PROTECT_USE_UTC",
show_envvar=True,
)
def download(
dest: str,
Expand Down
34 changes: 34 additions & 0 deletions protect_archiver/cli/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,40 +18,52 @@
show_default=True,
required=True,
help="IP address or hostname of the UniFi Protect Server",
envvar="PROTECT_ADDRESS",
show_envvar=True,
)
@click.option(
"--port",
default=Config.PORT,
show_default=True,
required=False,
help="The port of the UniFi Protect Server",
envvar="PROTECT_PORT",
show_envvar=True,
)
@click.option(
"--not-unifi-os",
is_flag=True,
default=False,
show_default=True,
help="Use this for systems without UniFi OS",
envvar="PROTECT_NOT_UNIFI_OS",
show_envvar=True,
)
@click.option(
"--username",
required=True,
help="Username of user with local access",
prompt="Username of local Protect user",
envvar="PROTECT_USERNAME",
show_envvar=True,
)
@click.option(
"--password",
required=True,
help="Password of user with local access",
prompt="Password for local Protect user",
hide_input=True,
envvar="PROTECT_PASSWORD",
show_envvar=True,
)
@click.option(
"--verify-ssl",
is_flag=True,
default=False,
show_default=True,
help="Verify Protect SSL certificate",
envvar="PROTECT_VERIFY_SSL",
show_envvar=True,
)
@click.option(
"--cameras",
Expand All @@ -61,27 +73,35 @@
"Comma-separated list of one or more camera IDs ('--cameras=\"id_1,id_2,id_3,...\"'). "
"Use '--cameras=all' to download footage of all available cameras."
),
envvar="PROTECT_CAMERAS",
show_envvar=True,
)
@click.option(
"--wait-between-downloads",
"download_wait",
default=0,
show_default=True,
help="Time to wait between file downloads, in seconds",
envvar="PROTECT_WAIT_BETWEEN_DOWNLOADS",
show_envvar=True,
)
@click.option(
"--ignore-failed-downloads",
is_flag=True,
default=False,
show_default=True,
help="Ignore failed downloads and continue with next download",
envvar="PROTECT_IGNORE_FAILED_DOWNLOADS",
show_envvar=True,
)
@click.option(
"--skip-existing-files",
is_flag=True,
default=False,
show_default=True,
help="Skip downloading files which already exist on disk",
envvar="PROTECT_SKIP_EXISTING",
show_envvar=True,
)
@click.option(
"--touch-files",
Expand All @@ -92,19 +112,25 @@
"Create local file without content for current download - "
"useful in combination with '--skip-existing-files' to skip problematic segments"
),
envvar="PROTECT_TOUCH_FILES",
show_envvar=True,
)
@click.option(
"--use-subfolders/--no-use-subfolders",
default=True,
show_default=True,
help="Save footage to folder structure with format 'YYYY/MM/DD/camera_name/'",
envvar="PROTECT_USE_SUBFOLDERS",
show_envvar=True,
)
@click.option(
"--download-request-timeout",
"download_timeout",
default=60.0,
show_default=True,
help="Time to wait before aborting download request, in seconds",
envvar="PROTECT_DOWNLOAD_TIMEOUT",
show_envvar=True,
)
@click.option(
"--start",
Expand All @@ -122,6 +148,8 @@
# TODO(danielfernau): uncomment the next line as soon as the feature is implemented
# "If omitted, the time of the first available recording for each camera will be used."
),
envvar="PROTECT_START_TIME",
show_envvar=True,
)
@click.option(
"--end",
Expand All @@ -139,20 +167,26 @@
# TODO(danielfernau): uncomment the next line as soon as the feature is implemented
# "If omitted, the time of the last available recording for each camera will be used."
),
envvar="PROTECT_END_TIME",
show_envvar=True,
)
@click.option(
"--download-motion-heatmaps",
is_flag=True,
default=False,
show_default=True,
help="Also download motion heatmaps for event recordings",
envvar="PROTECT_DOWNLOAD_MOTION_HEATMAPS",
show_envvar=True,
)
@click.option(
"--use-utc-filenames",
is_flag=True,
default=False,
show_default=True,
help="Use UTC timestamp in file names instead of local time",
envvar="PROTECT_USE_UTC",
show_envvar=True,
)
def events(
dest: str,
Expand Down
Loading
Loading