-
Notifications
You must be signed in to change notification settings - Fork 34
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
Add Support For Base Station Media Downloads with RATLS #87
Conversation
6012e13
to
8f0734b
Compare
OOOHHHH, Exciting!! I will give this a try. |
Yes, I currently only have files back to January 1st and I believe the default period is 30 days. When I run it now, the URLError seems to repeat endlessly now. I had to ctrl-C to stop. I will set the period shorter to see what happens. And yes, I do have 4K videos on my base station. I will add the extra code to media.py and let you know the result. |
@Jeff-Rand I've pushed another update to better support both 2k and 4k video from the base station. |
I set the |
Confirmed that |
I presume those errors are from trying to list the contents of the library. You might check
|
FYI, the reason you see it |
Also, are you on the same local network as your base station? |
Adding the two print statements I get: |
Yes |
I think I just spotted the issue... Update line 51 of ratls: diff --git a/pyaarlo/ratls.py b/pyaarlo/ratls.py
index ab3a584..84112a4 100644
--- a/pyaarlo/ratls.py
+++ b/pyaarlo/ratls.py
@@ -48,7 +48,7 @@ class ArloRatls(object):
return self._base_connection_details
def get(self, path, raw=False):
- request = Request(f"{self.url}/{path}")
+ request = Request(f"{self.url}{path}")
request.get_method = lambda: 'GET'
for (k, v) in self._ratls_req_headers().items(): |
I removed the slash and the result is the same. |
I added a line to output the request. This is what I got: |
Consider: diff --git a/pyaarlo/ratls.py b/pyaarlo/ratls.py
index 84112a4..ab03083 100644
--- a/pyaarlo/ratls.py
+++ b/pyaarlo/ratls.py
@@ -60,7 +60,7 @@ class ArloRatls(object):
return response
return json.loads(response.read())
except Exception as e:
- self._arlo.warning("request-error={}".format(type(e).__name__))
+ self._arlo.warning("request-error={}:{}".format(type(e).__name__, e.reason))
return None
def _ratls_req_headers(self): I'm struggling to imagine how those URLs would cause |
The error message is now |
What version of python are you running? I think something may have changed with Python 3.10's SSL Contexts... pydicom/pynetdicom#709 |
Ahhh.... I'm running Python 3.10.2 Let me try an older version. |
I need to confirm, but I would bet the base station doesn't support TLS1.2. I can try explicitly allowing it TLS1.1 |
I tried it on another system I have running Python 3.9.7. No errors, yay! |
Another silly question, what is the default path that the video files are saved to? How do I change the path? Sorry for all the questions, this is all still new to me. |
It's the original Try this diff with python 3.10: diff --git a/pyaarlo/ratls.py b/pyaarlo/ratls.py
index 84112a4..7414abb 100644
--- a/pyaarlo/ratls.py
+++ b/pyaarlo/ratls.py
@@ -91,6 +91,7 @@ class ArloRatls(object):
device_certs_path = self._security.device_certs_path(self._unique_id)
self._sslcontext = ssl.create_default_context(cafile=os.path.join(certs_path, "ica.crt"), purpose=ssl.Purpose.CLIENT_AUTH) #, purp
self._sslcontext.load_cert_chain(os.path.join(device_certs_path, "peer.crt"), self._security.private_key_path)
+ self._sslcontext.options &= ~ssl.OP_NO_TLSv1_1
self._base_client = build_opener(HTTPSHandler(context=self._sslcontext))
def _check_device_certs(self): |
I'm getting the same error message after adding the |
I finally figured out the If I enumerate my cameras with this code: I get this: I am only getting videos from the last camera named "Front yard" |
Looks like it only supports TLS 1.0 and SSLv3. Try this option: |
This would iterate over the cameras attached to your base station and give you only results for each camera. I haven't found any evidence from decompiling and examining the Android app that the API supports pagination diff --git a/pyaarlo/media.py b/pyaarlo/media.py
index afa9212..5e3701d 100644
--- a/pyaarlo/media.py
+++ b/pyaarlo/media.py
@@ -311,10 +311,12 @@ class ArloBaseStationMediaLibrary(ArloMediaLibrary):
# Fetch each page individually, since the base station still only return results for one date at a time
for date in range(int(date_from), int(date_to) + 1):
- # This URL is mysterious -- it won't return multiple days of videos
- data = self._base.ratls.get(f"{RATLS_LIBRARY_PATH}/{date}/{date}")
- if data and "data" in data:
- list += data["data"]
+ for camera in self._arlo.cameras:
+ if camera.parent_id == self._base.device_id:
+ # This URL is mysterious -- it won't return multiple days of videos
+ data = self._base.ratls.get(f"{RATLS_LIBRARY_PATH}/{date}/{date}/{camera.device_id}")
+ if data and "data" in data:
+ list += data["data"] |
Using |
I'll have to upgrade and try to fix it with Python 3.10 myself. Will push a fix once I find one. |
@Jeff-Rand the latest change properly supports Python 3.10 (also tested with Python 3.9) I don't think it was the deprecation of TLS 1.1, but changes related to hostname verification. |
I'm still getting errors on Python 3.10. The error has changed to Also, on Python 3.9 I'm still only getting videos from one camera. I'm starting to get an understanding of the code and should be able to figure out the issue soon. I will let you know what I find. |
I had a strange issue with my base station today and I was getting that error until I power cycled it and tried again after a few minutes. |
I rebooted my base station and tried again with Python 3.10. I'm still getting the not found HTTPError. I did however fix the problem with getting videos from only one of my three cameras. I made the following changes and it is getting them all now. In media.py I changed lines 192 and 261 from this: And line 389 from this: Thanks so much for doing all this work! I am very happy now. |
@Jeff-Rand cool -- added support for all 3 video content types. |
Firstly, thanks everybody for doing/helping with this. Sorry for the delay but I'll take a look at all this this weekend. |
@phene The latest update works great in Python 3.9. I'm now getting the You can ignore the part about it not working in Python 3.10. Apparently, the issue with connectivity has something to do with my machine. I just upgraded my other machine to Python 3.10 and it works just fine. |
Adds the following classes: ArloRatls - Triggers base station port opening, token issuance, and client TLS against the base station. ArloBaseStationMediaLibrary - Subclass of ArloMediaLibrary which can iterate over the base station library and trigger downloads of videos SecurityUtils - A near-exact copy of @jesserockz's library for creating certificates and managing certificates signed for each device.
Rebased against master |
Code looks good to me. I'll merge over today. @phene Thanks for doing this. You still ok with the merge? |
Go for it! |
Done. And apologies for the delay, I finally for a day off my real job! |
Follow-up to #86 and based on work done here by @jesserockz
This adds some new classes:
Example usage: