Skip to content

Commit

Permalink
supports finer event types in new firmare (11 may 2021)
Browse files Browse the repository at this point in the history
  • Loading branch information
acolomba committed May 15, 2021
1 parent 074745f commit ab9fb6a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
26 changes: 22 additions & 4 deletions blackvuesync.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,28 @@ def calc_cutoff_date(keep):
Recording = namedtuple("Recording", "filename base_filename group_name datetime type direction extension")

# dashcam recording filename regular expression
# references:
# https://www.blackvue.com.sg/uploads/8/4/4/2/8442586/manual_dr750s-2ch_en_web_ver.1.00_12.pdf
# https://blackvue.com/major-update-improved-blackvue-app-ui-dark-mode-live-event-upload-and-more/
# N: Normal
# E: Event
# P: Parking motion detection
# M: Manual
# I: Parking impact
# O: Overspeed
# A: Hard acceleration
# T: Hard cornering
# B: Hard braking
# R: Geofence-enter
# X: Geofence-exit
# G: Geofence-pass
#
# L or S: upload flag, Substream or Live
filename_re = re.compile(r"""(?P<base_filename>(?P<year>\d\d\d\d)(?P<month>\d\d)(?P<day>\d\d)
_(?P<hour>\d\d)(?P<minute>\d\d)(?P<second>\d\d))
_(?P<type>[NEPM])
_(?P<type>[NEPMIOATBRXG])
(?P<direction>[FR])
(?P<upload>[LS]?)
\.(?P<extension>mp4)""", re.VERBOSE)


Expand Down Expand Up @@ -323,12 +341,12 @@ def sort_recordings(recordings, recording_priority):
"""sorts recordings in place according to the given priority"""

def datetime_sort_key(recording):
"""sorts by datetime, then recording type, then front/rear direction"""
"""sorts by datetime, then front/rear direction, then recording type"""
return recording.datetime, "FR".find(recording.direction)

def manual_event_sort_key(recording):
"""sorts by recording type, then datetime, then front/rear direction"""
return "MENP".find(recording.type), recording.datetime, "FR".find(recording.direction)
"""sorts by recording type (manual and events first), then datetime, then front/rear direction"""
return "MEIBOATRXGNP".find(recording.type), recording.datetime, "FR".find(recording.direction)

if recording_priority == "date":
# least recent first
Expand Down
13 changes: 11 additions & 2 deletions test/blackvue_emu/blackvue_emu.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
# dashcam filename pattern
filename_re = re.compile(r"""(?P<base_filename>(?P<year>\d\d\d\d)(?P<month>\d\d)(?P<day>\d\d)
_(?P<hour>\d\d)(?P<minute>\d\d)(?P<second>\d\d))
_(?P<type>[NEPM])
_(?P<type>[NEPMIOATBRXG])
(?P<direction>[FR]?)
(?P<upload>[LS]?)
\.(?P<extension>(3gf|gps|mp4|thm))""", re.VERBOSE)


Expand Down Expand Up @@ -48,10 +49,18 @@ def generate_recording_filenames(day_range=3):

for date in [today - datetime.timedelta(day) for day in range(0, day_range)]:
for hour in [9, 18]:
for minutes in range(10, 25):
for minutes in range(10, 25, 3):
for direction in ["F", "R"]:
yield "%04d%02d%02d_%02d%02d%02d_N%s.mp4" % (date.year, date.month, date.day, hour, minutes, 0,
direction)
for minutes in range(11, 25, 3):
for direction in ["F", "R"]:
yield "%04d%02d%02d_%02d%02d%02d_E%s.mp4" % (date.year, date.month, date.day, hour, minutes, 0,
direction)
for minutes in range(13, 25, 3):
for direction in ["F", "R"]:
yield "%04d%02d%02d_%02d%02d%02d_A%sL.mp4" % (date.year, date.month, date.day, hour, minutes, 0,
direction)


@app.route("/blackvue_vod.cgi", methods=['GET'])
Expand Down

0 comments on commit ab9fb6a

Please sign in to comment.