Skip to content

Commit

Permalink
#13 - add flag to get video time from its metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
hohonuuli committed Jun 11, 2024
1 parent 6a99e2d commit 3acada8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
13 changes: 9 additions & 4 deletions bin/etc/python/vars_register_media.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def sha512_from_uri(uri: str) -> str:
p.unlink() # Delete the file
return checksum

def main(camera_id: str, deployment_id: str, uri: str):
def main(camera_id: str, deployment_id: str, uri: str, extracttime: bool=False) -> None:
vam_url = os.environ["VAMPIRE_SQUID_URL"]
vam_secret = os.environ["VAMPIRESQUID_CLIENT_SECRET"]
vampire_squid = VampireSquid(vam_url)
Expand All @@ -49,8 +49,12 @@ def main(camera_id: str, deployment_id: str, uri: str):
print(f"Reading video metadata from {uri}")
video_metadata = ffprobe.ffprobe(uri).video_metadata()

start_time_utc = timeutil.datetime_from_name(uri)
time_str_full = start_time_utc.isoformat()
if extracttime:
start_time_utc = video_metadata.created
else:
start_time_utc = timeutil.datetime_from_name(uri)

time_str_full = start_time_utc.isoformat()
time_str_compact = start_time_utc.strftime("%Y%m%dT%H%M%S.%fZ")

mime_type = media_type(uri)
Expand Down Expand Up @@ -102,5 +106,6 @@ def main(camera_id: str, deployment_id: str, uri: str):
type=str)
parser.add_argument("uri", help="The URL to the media file e.g. http://my.servername.org/media/D1234_20190201T120000Z.mp4",
type=str)
parser.add_argument('-e', '--extracttime', action='store_true', help="Extract the creation time from the video metadata. Default is to parse the filename" )
args = parser.parse_args()
main(args.camera_id, args.deployment_id, args.uri)
main(args.camera_id, args.deployment_id, args.uri, args.extracttime)
10 changes: 7 additions & 3 deletions bin/etc/python/vars_register_medias_on_web.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@ def readDirListing(url: str) -> List[str]:
cwd, listing = htmllistparse.fetch_listing(url, timeout=30)
return map(lambda x: f'{url}{x.name}', listing)

def main(camera_id: str, deployment_id: str, url: str):
def main(camera_id: str, deployment_id: str, url: str, extracttime: bool=False) -> None:
urls = readDirListing(url)
for uri in urls:
print(f"Processing {uri}")
vars_register_media.main(camera_id, deployment_id, uri)
try:
vars_register_media.main(camera_id, deployment_id, uri, extracttime)
except Exception as e:
print("An exception occured: {e}")

if __name__ == "__main__":
parser = argparse.ArgumentParser()
Expand All @@ -25,5 +28,6 @@ def main(camera_id: str, deployment_id: str, url: str):
type=str)
parser.add_argument("url", help="The URL to the video directory e.g. http://my.servername.org/media/D1234_EX1234",
type=str)
parser.add_argument('-e', '--extracttime', action='store_true', help="Extract the creation time from the video metadata. Default is to parse the filename" )
args = parser.parse_args()
main(args.camera_id, args.deployment_id, args.url)
main(args.camera_id, args.deployment_id, args.url, args.extracttime)
3 changes: 3 additions & 0 deletions bin/media_metadata.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

ffprobe -v quiet -print_format json -show_format -show_streams "$1"

0 comments on commit 3acada8

Please sign in to comment.