Allow postprocessing binary/script post download#180
Allow postprocessing binary/script post download#180WietseWind wants to merge 1 commit intoep1cman:mainfrom
Conversation
ep1cman
left a comment
There was a problem hiding this comment.
Thanks for the PR, I like this feature as it opens up a lot of possibilities. Only minor adjustments needed
| The binary / executable script receives a first argument with the storage location for the downloaded video. You can easily mount a script from a local filesystem to the container: | ||
|
|
||
| ```bash | ||
| rm -r /tmp/unifi ; docker rmi ghcr.io/ep1cman/unifi-protect-backup ; poetry build && docker buildx build . -t ghcr.io/ep1cman/unifi-protect-backup ; |
There was a problem hiding this comment.
rebuilding the container seems excessive for the readme
| self.logger.error(f"Unexpected exception occurred, abandoning event {event.id}:", exc_info=e) | ||
|
|
||
| async def _upload_video(self, video: bytes, destination: pathlib.Path, rclone_args: str): | ||
| async def _upload_video(self, video: bytes, destination: pathlib.Path, rclone_args: str, postprocess_binary: str): |
There was a problem hiding this comment.
why is this passed into here and never used?
| video (bytes): The data to be written to the file | ||
| destination (pathlib.Path): Where rclone should write the file | ||
| rclone_args (str): Optional extra arguments to pass to `rclone` | ||
| postprocess_binary (str): Optional extra path to postprocessing binary |
|
|
||
| try: | ||
| await self._upload_video(video, destination, self._rclone_args) | ||
| await self._upload_video(video, destination, self._rclone_args, self._postprocess_binary) |
There was a problem hiding this comment.
why is this passed into here and never used?
|
|
||
| # Postprocess | ||
| if self._postprocess_binary: | ||
| returncode_postprocess, stdout_postprocess, stderr_postprocess = await run_command(f'"{self._postprocess_binary}" "{destination}"') |
There was a problem hiding this comment.
I feel that the exit codes here should have some signficance to how the script proceeds.
Maybe:
0 = OK
1 = Error, raise exception
2 = Error, but ok to proceed with upload
|
Upon a second review of this PR I have some more questions:
I feel like this should be implemented differently, as a optional step that runs as a separate task that gets inserted between the download and upload. it could even be used to dictate if an event should be backed up or not e.g only back up clips that have wildlife in them |
Another PR (next to #179)
This change allows for providing a postprocess binary/script, to execute custom logic post downloading a video.
In my specific case, after downloading motion detection, I want to run a script to detect if there are animals in the video (wildlife). If not: discard. If animals: upload to Youtube (wildlife channel).
Added readme, etc. etc. & relatively verbose logging of stdout and stderr if the postprocessing binary path is specified.
P.S. reason for me adding this:
https://github.com/WietseWind/Unifi-Wildlife-Detection