Commit Graph

43 Commits

Author SHA1 Message Date
Sebastian Goscik
471ecb0662 Major Restructure
- Each task is now its own class
- Added a database to track backed up events and their destinations
- Added task to check for and backup missed events
2022-12-03 21:48:44 +00:00
Sebastian Goscik
f4a0c2bdcd Merge pull request #32 from ircmaxell/fix_disconnect_handling
Skip DISCONNECT events
2022-03-26 16:20:51 +00:00
Anthony Ferrara
f2c9ee5c76 Skip unwanted event types
e.g DISCONNECT events never have video associated with them, skip
processing if we encounter events of types we are not interested in.

Co-authored-by: Sebastian Goscik <sebastian.goscik@live.co.uk>
2022-03-26 16:15:36 +00:00
Sebastian Goscik
381f90f497 Add the ability to change the way the clip files are structured 2022-03-26 00:05:23 +00:00
Sebastian Goscik
8bebeceaa6 Linter fixes 2022-03-18 21:44:32 +00:00
Sebastian Goscik
e2eb7858da Added support for doorbell ring events 2022-03-18 21:44:32 +00:00
Sebastian Goscik
453fed6c57 Added ability to choose which event types to backup
Co-authored-by: J3n50m4t <j3n50m4t@j3n50m4t.com>
2022-03-18 21:42:32 +00:00
Sebastian Goscik
ae323e68aa Actually assign new timestamps with proper timezones 2022-03-18 18:32:30 +00:00
Sebastian Goscik
0a4a2401be Now uses timezone of the NVR for all timestamps 2022-03-10 22:35:14 +00:00
Sebastian Goscik
92bb362f2b Changed quotes in delete coomand to " 2022-03-10 19:32:30 +00:00
Sebastian Goscik
5bd4a35d5d Change ' quotes to " in rclone command
' does not work as expected in windows
2022-03-07 22:38:12 +00:00
Sebastian Goscik
04694712d8 Added feature to check duration of downloaded clips if ffprobe is present 2022-03-06 18:18:59 +00:00
Sebastian Goscik
e3ed8ef303 Added delay before downloading clips
Unifi protect does not return full video clips if the clip is requested too soon.
There are two issues at play here:
  - Protect will only cut a clip on an keyframe which happen every 5s
  - Protect's pipeline needs a finite amount of time to make a clip available

Known Issues: It still seems to sometimes miss a single frame
2022-03-06 18:03:27 +00:00
Sebastian Goscik
43dd561d81 Rename RCloneException to more general SubprocessException 2022-03-06 17:59:00 +00:00
Sebastian Goscik
2b46b5bd4a Added --version
Implements #15
2022-03-05 14:50:54 +00:00
Sebastian Goscik
9e164de686 Demote websocket retry logging
Previously `-v` showed a lot of spam meesaged for each time the check
was done, this is not particularly useful.
2022-02-24 23:54:29 +00:00
Sascha Bischoff
c9634ba10a Periodically check for websocket disconnect and re-init
Both network issues and restarts of Unifi Protect can cause the
websocket to disconnect. Once this happens, no more events are
recieved, and hence no events are stored via rclone.

We add a task which checks that the websocket is connected every
minute. If the websocket is not connected, the connection is totally
reset. For a simple network issue, is should be sufficient to just
call pyunifiprotect's update(), but this doesn't work when protect has
been restarted. Given that this is a tool that should always be
running, we opt for the most extreme option of totally resetting the
connection, and re-establishing it from scratch.
2022-02-24 18:54:24 +00:00
Sebastian Goscik
3e53d43f95 Add timeout to known download exceptions 2022-02-22 23:36:57 +00:00
Sebastian Goscik
90e50fd982 Fix: Properly handle unknown IDs
Today after adding a new camera for testing, it became
clear that the previous assumption that pyunifiprotect
would update its bootstrap when new cameras were
added was incorrect.
2022-02-22 23:36:30 +00:00
Sascha Bischoff
9f6ec7628c Add option to supply extra arguments to rclone
Add in the capability to pass extra arguments through to rclone. These
are passed verbatim, and are set to '' by default. They can be passed
either with --rclone-args or by setting the environment variable
RCLONE_ARGS.

For example. the expectation is that the end user can use these for
setting a bandwidth limit so that rclone uploading doesn't saturate
their internet bandwidth.
2022-02-22 15:25:27 +00:00
Sebastian Goscik
5e1803c06c corrected retry logging 2022-02-21 23:12:42 +00:00
Sebastian Goscik
b2d041ff09 Add missing f for fstrings in warning 2022-02-21 11:12:19 +00:00
Sebastian Goscik
61e54c3b5f Add known download exception 2022-02-21 11:12:19 +00:00
Sebastian Goscik
84cb32fabf Added debug logging of config settings 2022-02-21 11:12:19 +00:00
Sebastian Goscik
773b90ba4f Log camera ID -> name mapping at start
Makes it easier to figure out what the camera IDs are for ignoring them
2022-02-21 11:12:19 +00:00
Sebastian Goscik
0dd9e8e91b Add feature to ignore cameras
Implements #1
2022-02-21 11:12:19 +00:00
Sebastian Goscik
e491965e04 Lookup camera names in pyunifiprotect instead of a local map
Pyunifiprotect should keep the known cameras upto date, unlike the map
we were keeping before which was never updated after start.
2022-02-21 11:12:19 +00:00
Sebastian Goscik
0b1ccca4b2 linter fixes 2022-02-20 23:43:27 +00:00
Sebastian Goscik
3e1868b21f Added a retry delay 2022-02-20 21:33:21 +00:00
Sebastian Goscik
166e4b282b Added down/upload retries
Also improved logging of exception that occur to ensure unexpected exceptions are never passed silently
2022-02-20 21:21:30 +00:00
Sebastian Goscik
a22fa64587 Created custom exception class for rclone errors
Previously it used RuntimeExceptions which could also be raised from other source.
This also meant some exceptions could be passed silently which is no longer the case
2022-02-20 21:00:19 +00:00
Sebastian Goscik
b948c4ceb5 Fix typing and docstrings 2022-02-19 22:03:51 +00:00
Sebastian Goscik
6a0f89ff49 Remove unnecessary attributes
Especially the login credentials
2022-02-19 21:45:03 +00:00
Sebastian Goscik
c7f35cb17e Reduce logging indent to two spaces 2022-02-19 21:44:27 +00:00
Sebastian Goscik
00f1b675b7 Refactor upload into its own method 2022-02-19 21:43:33 +00:00
Sebastian Goscik
d69090ba72 Overhauled logging
- Better logging format
- More information logged
- Ability to show rclone logging
2022-02-19 19:36:31 +00:00
Sebastian Goscik
30557c1d40 Improved download logging
Added much more detail about the captured event
2022-02-19 12:43:53 +00:00
Sebastian Goscik
524a30d0a7 Import order tidy up 2022-02-19 12:03:51 +00:00
Sebastian Goscik
c481810c1e Improved cmd debug logging 2022-02-19 12:03:51 +00:00
Sebastian Goscik
e63c36d100 Removed need for temp files
Download and upload now occur purely from memory
2022-02-19 12:03:51 +00:00
Sebastian Goscik
eebac2386a Fix purge self reference + delete empty directories
The rclone pruge method needed access to self but wasnt called in such a way that it had it.
Previously it would leave empty directories once files were purged. This is no longer the case
by chaining a call to `rclone rmdirs`
2022-02-19 12:02:25 +00:00
Sebastian Goscik
cd96b80097 Initial implementation
- CLI + env var settings
- Backup via rclone
- Configurable retention
- Run purge nightly
- 4 levels of logging
2022-02-19 11:53:22 +00:00
Sebastian Goscik
fe57f626c0 Initial commit 2022-02-18 01:24:02 +00:00