Skip to content

Commit e1cb9bd

Browse files
authoredDec 19, 2020
Merge pull request #37 from barretobrock/develop
Refactor package to be imported as a single package
2 parents 0221215 + 0fdd0df commit e1cb9bd

35 files changed

+601
-361
lines changed
 

‎.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
secrets.cfg
12
# Byte-compiled / optimized / DLL files
23
__pycache__/
34
*.py[cod]

‎Camera.py

-24
This file was deleted.

‎ConfigHandler.py

-17
This file was deleted.

‎README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
<p align="center">
44
<img alt="Reolink Approval" src="https://img.shields.io/badge/reolink-approved-blue?style=flat-square">
5-
<img alt="GitHub" src="https://img.shields.io/github/license/ReolinkCameraApi/reolink-python-api?style=flat-square">
6-
<img alt="GitHub tag (latest SemVer)" src="https://img.shields.io/github/v/tag/ReolinkCameraApi/reolink-python-api?style=flat-square">
7-
<img alt="PyPI" src="https://img.shields.io/pypi/v/reolink-api?style=flat-square">
5+
<img alt="GitHub" src="https://img.shields.io/github/license/ReolinkCameraAPI/reolinkapipy?style=flat-square">
6+
<img alt="GitHub tag (latest SemVer)" src="https://img.shields.io/github/v/tag/ReolinkCameraAPI/reolinkapipy?style=flat-square">
7+
<img alt="PyPI" src="https://img.shields.io/pypi/v/reolinkapi?style=flat-square">
88
<img alt="Discord" src="https://img.shields.io/discord/773257004911034389?style=flat-square">
99
</p>
1010

‎api/__init__.py

-4
This file was deleted.

‎api/recording.py

-111
This file was deleted.

‎examples/basic_usage.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import reolinkapi
2+
3+
if __name__ == "__main__":
4+
cam = reolinkapi.Camera("192.168.0.102", defer_login=True)
5+
6+
# must first login since I defer have deferred the login process
7+
cam.login()
8+
9+
dst = cam.get_dst()
10+
ok = cam.add_user("foo", "bar", "admin")
11+
alarm = cam.get_alarm_motion()

‎examples/download_motions.py

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

‎examples/streaming_video.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import cv2
2-
3-
from Camera import Camera
2+
from reolinkapi import Camera
43

54

65
def non_blocking():

‎reolinkapi/__init__.py

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from reolinkapi.handlers.api_handler import APIHandler
2+
from .camera import Camera
3+
4+
__version__ = "0.1.2"

‎reolinkapi/camera.py

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from reolinkapi.handlers.api_handler import APIHandler
2+
3+
4+
class Camera(APIHandler):
5+
6+
def __init__(self, ip: str,
7+
username: str = "admin",
8+
password: str = "",
9+
https: bool = False,
10+
defer_login: bool = False,
11+
**kwargs):
12+
"""
13+
Initialise the Camera object by passing the ip address.
14+
The default details {"username":"admin", "password":""} will be used if nothing passed
15+
For deferring the login to the camera, just pass defer_login = True.
16+
For connecting to the camera behind a proxy pass a proxy argument: proxy={"http": "socks5://127.0.0.1:8000"}
17+
:param ip:
18+
:param username:
19+
:param password:
20+
:param https: connect to the camera over https
21+
:param defer_login: defer the login process
22+
:param proxy: Add a proxy dict for requests to consume.
23+
eg: {"http":"socks5://[username]:[password]@[host]:[port], "https": ...}
24+
More information on proxies in requests: https://stackoverflow.com/a/15661226/9313679
25+
"""
26+
# For when you need to connect to a camera behind a proxy, pass
27+
# a proxy argument: proxy={"http": "socks5://127.0.0.1:8000"}
28+
APIHandler.__init__(self, ip, username, password, https=https, **kwargs)
29+
30+
# Normal call without proxy:
31+
# APIHandler.__init__(self, ip, username, password)
32+
33+
self.ip = ip
34+
self.username = username
35+
self.password = password
36+
37+
if not defer_login:
38+
super().login()

‎reolinkapi/handlers/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)
Please sign in to comment.