Skip to content

Commit 9b66cd4

Browse files
committed
add example of download playback videos
1 parent c16189a commit 9b66cd4

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
"""Downloads a video from camera from start to end time."""
2+
import os
3+
from configparser import RawConfigParser
4+
from datetime import datetime as dt, timedelta
5+
from reolinkapi import Camera
6+
import requests
7+
import pandas as pd
8+
9+
def read_config(props_path: str) -> dict:
10+
"""Reads in a properties file into variables.
11+
12+
NB! this config file is kept out of commits with .gitignore. The structure of this file is such:
13+
# secrets.cfg
14+
[camera]
15+
ip={ip_address}
16+
username={username}
17+
password={password}
18+
"""
19+
config = RawConfigParser()
20+
assert os.path.exists(props_path), f"Path does not exist: {props_path}"
21+
config.read(props_path)
22+
return config
23+
24+
25+
# Read in your ip, username, & password
26+
# (NB! you'll likely have to create this file. See tests/test_camera.py for details on structure)
27+
config = read_config('camera.cfg')
28+
29+
ip = config.get('camera', 'ip')
30+
un = config.get('camera', 'username')
31+
pw = config.get('camera', 'password')
32+
33+
# Connect to camera
34+
cam = Camera(ip, un, pw)
35+
36+
start = dt.now() - timedelta(minutes=10)
37+
end = dt.now() - timedelta(minutes=9)
38+
channel = 0
39+
40+
files = cam.get_playback_files(start=start, end=end, channel= channel)
41+
print(files)
42+
dl_dir = os.path.join(os.path.expanduser('~'), 'Downloads')
43+
for fname in files:
44+
print(fname)
45+
# Download the mp4
46+
cam.get_file(fname, output_path=os.path.join(dl_dir, fname))

0 commit comments

Comments
 (0)