-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Minor cleanups and some new example programs. #67
Open
phbcanada
wants to merge
12
commits into
ReolinkCameraAPI:master
Choose a base branch
from
phbcanada:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
f003a0d
Update setup.py
phbcanada eb8add1
Update streaming_video.py
phbcanada ee7dde6
Update stream.py
phbcanada da83de9
Add check for login failure.
phbcanada ea70bc7
New api method "set_network_ftp"
phbcanada f2a01d5
Two new example programs
phbcanada e61718a
Update api_handler.py
phbcanada 1f62a24
Add support for newer API version on some cameras.
phbcanada f755409
Merge branch 'master' of github.com:phbcanada/reolinkapipy
phbcanada 247a19c
Add some support for V2 API. Misc fixes and additions.
phbcanada e3c913c
Correct call is actually GetMdAlarm
phbcanada 0e7b321
Fixes to set_recording_encoding
phbcanada File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import reolinkapi | ||
import json | ||
|
||
if __name__ == "__main__": | ||
hostname = "watchdog1" | ||
|
||
try: | ||
cam = reolinkapi.Camera(hostname, username="userid", password="passwd") | ||
except: | ||
print(f"Failed to open camera {hostname}") | ||
exit(1) | ||
|
||
if not cam.is_logged_in(): | ||
print(f"Login failed for {hostname}") | ||
exit(1) | ||
|
||
|
||
print( json.dumps( cam.get_information(), indent=4 ) ) | ||
print( json.dumps( cam.get_network_general(), indent=4 ) ) | ||
print( json.dumps( cam.get_network_ddns(), indent=4 ) ) | ||
print( json.dumps( cam.get_network_ntp(), indent=4 ) ) | ||
print( json.dumps( cam.get_network_email(), indent=4 ) ) | ||
print( json.dumps( cam.get_network_ftp(), indent=4 ) ) | ||
print( json.dumps( cam.get_network_push(), indent=4 ) ) | ||
print( json.dumps( cam.get_network_status(), indent=4 ) ) | ||
print( json.dumps( cam.get_recording_encoding(), indent=4 ) ) | ||
print( json.dumps( cam.get_recording_advanced(), indent=4 ) ) | ||
print( json.dumps( cam.get_general_system(), indent=4 ) ) | ||
print( json.dumps( cam.get_performance(), indent=4 ) ) | ||
print( json.dumps( cam.get_dst(), indent=4 ) ) | ||
print( json.dumps( cam.get_online_user(), indent=4 ) ) | ||
print( json.dumps( cam.get_users(), indent=4 ) ) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/opt/homebrew/bin/python3 | ||
|
||
import reolinkapi | ||
import os | ||
import json | ||
from sys import argv | ||
|
||
def ftp_cam(which): | ||
hostname = 'watchdog%d' % which | ||
cam_name = 'Watchdog%d' % which | ||
|
||
try: | ||
cam = reolinkapi.Camera(hostname, username="userid", password="passwd") | ||
except: | ||
print(f"Failed to open camera {cam_name}") | ||
return 1 | ||
|
||
if not cam.is_logged_in(): | ||
print(f"Login failed for {cam_name}") | ||
return 2 | ||
|
||
try: | ||
print(f"Setting FTP params for {cam_name}") | ||
response = cam.set_network_ftp("hocus", "pocus", "directory", "192.168.1.2", 0) | ||
print( json.dumps( response, indent=4 ) ) | ||
print( json.dumps( cam.get_network_ftp(), indent=4 ) ) | ||
if response[0]["value"]["rspCode"] == 200: | ||
print("Success!") | ||
except Exception as e: | ||
print(f"{argv[0]} for {cam_name} failed.") | ||
print(e) | ||
return 3 | ||
|
||
return 0 | ||
|
||
|
||
if __name__ == "__main__": | ||
if len(argv) != 2: | ||
print("Usage: %s <cam#>]" % argv[0]) | ||
exit(1) | ||
|
||
exit( ftp_cam(int(argv[1])) ) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/opt/homebrew/bin/python3 | ||
|
||
import reolinkapi | ||
import os | ||
from sys import argv | ||
|
||
def snap_cam(which, dirname): | ||
hostname = 'watchdog%d' % which | ||
cam_name = 'Watchdog%d' % which | ||
|
||
try: | ||
cam = reolinkapi.Camera(hostname, username="rtsp", password="darknet") | ||
except: | ||
print(f"Failed to open camera {cam_name}") | ||
return 1 | ||
|
||
if not cam.is_logged_in(): | ||
print(f"Login failed for {cam_name}") | ||
return 2 | ||
|
||
image_file = '%s/%s.jpg' % (dirname, hostname) | ||
if os.path.exists(image_file): | ||
os.unlink(image_file) | ||
|
||
print("Snapping", cam_name) | ||
image = cam.get_snap() | ||
image.save(image_file) | ||
return 0 | ||
|
||
|
||
if __name__ == "__main__": | ||
dirname = '.' | ||
if len(argv) == 3: | ||
dirname = argv[2] | ||
elif len(argv) != 2: | ||
print("Usage: %s <cam#> [output-directory]" % argv[0]) | ||
exit(1) | ||
|
||
exit( snap_cam(int(argv[1]), dirname) ) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -1,4 +1,6 @@ | ||||
import requests | ||||
from urllib3.exceptions import InsecureRequestWarning | ||||
|
||||
from typing import Dict, List, Optional, Union | ||||
from reolinkapi.mixins.alarm import AlarmAPIMixin | ||||
from reolinkapi.mixins.device import DeviceAPIMixin | ||||
|
@@ -53,6 +55,8 @@ def __init__(self, ip: str, username: str, password: str, https: bool = False, * | |||
self.url = f"{scheme}://{ip}/cgi-bin/api.cgi" | ||||
self.ip = ip | ||||
self.token = None | ||||
self.ability = None | ||||
self.scheduleVersion = 0 | ||||
self.username = username | ||||
self.password = password | ||||
Request.proxies = kwargs.get("proxy") # Defaults to None if key isn't found | ||||
|
@@ -64,28 +68,47 @@ def login(self) -> bool: | |||
:return: bool | ||||
""" | ||||
try: | ||||
# Suppress only the single warning from urllib3 needed. | ||||
requests.packages.urllib3.disable_warnings(category=InsecureRequestWarning) | ||||
|
||||
body = [{"cmd": "Login", "action": 0, | ||||
"param": {"User": {"userName": self.username, "password": self.password}}}] | ||||
param = {"cmd": "Login", "token": "null"} | ||||
response = Request.post(self.url, data=body, params=param) | ||||
if response is not None: | ||||
# print("LOGIN GOT: ", response.text) | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
data = response.json()[0] | ||||
code = data["code"] | ||||
if int(code) == 0: | ||||
self.token = data["value"]["Token"]["name"] | ||||
print("Login success") | ||||
return True | ||||
print(self.token) | ||||
return False | ||||
# print("Login success") | ||||
else: | ||||
# print(self.token) | ||||
Comment on lines
+84
to
+86
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove the comments or restore the print of "Login success?" |
||||
print("ERROR: LOGIN RESPONSE: ", response.text) | ||||
return False | ||||
else: | ||||
# TODO: Verify this change w/ owner. Delete old code if acceptable. | ||||
# A this point, response is NoneType. There won't be a status code property. | ||||
# print("Failed to login\nStatus Code:", response.status_code) | ||||
print("Failed to login\nResponse was null.") | ||||
return False | ||||
except Exception as e: | ||||
print("Error Login\n", e) | ||||
raise | ||||
print(f"ERROR Login Failed, exception: {e}") | ||||
return False | ||||
|
||||
try: | ||||
ability = self.get_ability() | ||||
self.ability = ability[0]["value"]["Ability"] | ||||
self.scheduleVersion = self.ability["scheduleVersion"]["ver"] | ||||
print("API VERSION: ", self.scheduleVersion) | ||||
except Exception as e: | ||||
self.logout() | ||||
return False | ||||
|
||||
return True | ||||
|
||||
def is_logged_in(self) -> bool: | ||||
return self.token is not None | ||||
|
||||
def logout(self) -> bool: | ||||
""" | ||||
|
@@ -98,7 +121,7 @@ def logout(self) -> bool: | |||
# print(ret) | ||||
return True | ||||
except Exception as e: | ||||
print("Error Logout\n", e) | ||||
print(f"ERROR Logout Failed, exception: {e}") | ||||
return False | ||||
|
||||
def _execute_command(self, command: str, data: List[Dict], multi: bool = False) -> \ | ||||
|
@@ -137,5 +160,5 @@ def _execute_command(self, command: str, data: List[Dict], multi: bool = False) | |||
response = Request.post(self.url, data=data, params=params) | ||||
return response.json() | ||||
except Exception as e: | ||||
print(f"Command {command} failed: {e}") | ||||
print(f"ERROR Command {command} failed, exception: {e}") | ||||
raise |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe make this optional?
or what about just leaving this to the client to set this as an env variable
PYTHONWARNINGS="ignore:Unverified HTTPS request"