Skip to content

Commit 2b3e142

Browse files
committed
Updated project structure and some file names.
Restored `requirements.txt` Updated `setup.py` to include new repository url and contact details. Moved the rtsp code from `record` to `stream`. Updated project structure to make it more readable and developer friendly - moved mixins to the `mixins` package, moved handlers to the `handlers` package. Moved files not belonging to anything in particular to the `util` package. Updated `camera` class to also defer login call. Deleted unused files like `config_handler`.
1 parent 4c4dd7d commit 2b3e142

27 files changed

+117
-95
lines changed

README.md

Lines changed: 3 additions & 3 deletions
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

examples/basic_usage.py

Lines changed: 11 additions & 0 deletions
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()

reolinkapi/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from .api_handler import APIHandler
1+
from reolinkapi.handlers.api_handler import APIHandler
22
from .camera import Camera
33

44
__version__ = "0.1.2"

reolinkapi/camera.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,38 @@
1-
from .api_handler import APIHandler
1+
from reolinkapi.handlers.api_handler import APIHandler
22

33

44
class Camera(APIHandler):
55

6-
def __init__(self, ip: str, username: str = "admin", password: str = "", https: bool = False):
6+
def __init__(self, ip: str,
7+
username: str = "admin",
8+
password: str = "",
9+
https: bool = False,
10+
defer_login: bool = False,
11+
**kwargs):
712
"""
813
Initialise the Camera object by passing the ip address.
914
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"}
1017
:param ip:
1118
:param username:
1219
: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
1325
"""
1426
# For when you need to connect to a camera behind a proxy, pass
1527
# a proxy argument: proxy={"http": "socks5://127.0.0.1:8000"}
16-
APIHandler.__init__(self, ip, username, password, https=https)
28+
APIHandler.__init__(self, ip, username, password, https=https, **kwargs)
1729

1830
# Normal call without proxy:
1931
# APIHandler.__init__(self, ip, username, password)
2032

2133
self.ip = ip
2234
self.username = username
2335
self.password = password
24-
super().login()
36+
37+
if not defer_login:
38+
super().login()

reolinkapi/config_handler.py

Lines changed: 0 additions & 17 deletions
This file was deleted.

reolinkapi/handlers/__init__.py

Whitespace-only changes.

reolinkapi/api_handler.py renamed to reolinkapi/handlers/api_handler.py

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
import requests
22
from typing import Dict, List, Optional, Union
3-
from reolinkapi.alarm import AlarmAPIMixin
4-
from reolinkapi.device import DeviceAPIMixin
5-
from reolinkapi.display import DisplayAPIMixin
6-
from reolinkapi.download import DownloadAPIMixin
7-
from reolinkapi.image import ImageAPIMixin
8-
from reolinkapi.motion import MotionAPIMixin
9-
from reolinkapi.network import NetworkAPIMixin
10-
from reolinkapi.ptz import PtzAPIMixin
11-
from reolinkapi.recording import RecordingAPIMixin
12-
from reolinkapi.resthandle import Request
13-
from reolinkapi.system import SystemAPIMixin
14-
from reolinkapi.user import UserAPIMixin
15-
from reolinkapi.zoom import ZoomAPIMixin
3+
from reolinkapi.mixins.alarm import AlarmAPIMixin
4+
from reolinkapi.mixins.device import DeviceAPIMixin
5+
from reolinkapi.mixins.display import DisplayAPIMixin
6+
from reolinkapi.mixins.download import DownloadAPIMixin
7+
from reolinkapi.mixins.image import ImageAPIMixin
8+
from reolinkapi.mixins.motion import MotionAPIMixin
9+
from reolinkapi.mixins.network import NetworkAPIMixin
10+
from reolinkapi.mixins.ptz import PtzAPIMixin
11+
from reolinkapi.mixins.record import RecordAPIMixin
12+
from reolinkapi.handlers.rest_handler import Request
13+
from reolinkapi.mixins.stream import StreamAPIMixin
14+
from reolinkapi.mixins.system import SystemAPIMixin
15+
from reolinkapi.mixins.user import UserAPIMixin
16+
from reolinkapi.mixins.zoom import ZoomAPIMixin
1617

1718

1819
class APIHandler(AlarmAPIMixin,
@@ -23,10 +24,11 @@ class APIHandler(AlarmAPIMixin,
2324
MotionAPIMixin,
2425
NetworkAPIMixin,
2526
PtzAPIMixin,
26-
RecordingAPIMixin,
27+
RecordAPIMixin,
2728
SystemAPIMixin,
2829
UserAPIMixin,
29-
ZoomAPIMixin):
30+
ZoomAPIMixin,
31+
StreamAPIMixin):
3032
"""
3133
The APIHandler class is the backend part of the API, the actual API calls
3234
are implemented in Mixins.
@@ -42,6 +44,7 @@ def __init__(self, ip: str, username: str, password: str, https: bool = False, *
4244
:param ip:
4345
:param username:
4446
:param password:
47+
:param https: connect over https
4548
:param proxy: Add a proxy dict for requests to consume.
4649
eg: {"http":"socks5://[username]:[password]@[host]:[port], "https": ...}
4750
More information on proxies in requests: https://stackoverflow.com/a/15661226/9313679
File renamed without changes.

reolinkapi/mixins/__init__.py

Whitespace-only changes.
File renamed without changes.

0 commit comments

Comments
 (0)