diff --git a/pyarlo/__init__.py b/pyarlo/__init__.py index edc71ca..9b48712 100644 --- a/pyarlo/__init__.py +++ b/pyarlo/__init__.py @@ -2,12 +2,13 @@ """Base Python Class file for Netgear Arlo camera module.""" import logging import requests +import base64 from pyarlo.base_station import ArloBaseStation from pyarlo.camera import ArloCamera from pyarlo.media import ArloMediaLibrary from pyarlo.const import ( - BILLING_ENDPOINT, DEVICES_ENDPOINT, + API_URL, BILLING_ENDPOINT, DEVICES_ENDPOINT, FRIENDS_ENDPOINT, LOGIN_ENDPOINT, PROFILE_ENDPOINT, PRELOAD_DAYS, RESET_ENDPOINT) @@ -69,10 +70,11 @@ def _authenticate(self): method='POST', extra_params={ 'email': self.__username, - 'password': self.__password - }) + 'password': base64.b64encode(self.__password.encode()).decode()}, + extra_headers={ + 'Referer': API_URL}) - if isinstance(data, dict) and data.get('success'): + if isinstance(data, dict) and data.get('meta') and data['meta']['code'] == 200: data = data.get('data') self.authenticated = data.get('authenticated') self.country_code = data.get('countryCode') @@ -85,7 +87,9 @@ def _authenticate(self): def cleanup_headers(self): """Reset the headers and params.""" - headers = {'Content-Type': 'application/json'} + headers = { + 'Content-Type': 'application/json', + 'Auth-Version': '2'} headers['Authorization'] = self.__token self.__headers = headers self.__params = {} diff --git a/pyarlo/const.py b/pyarlo/const.py index 2bba1b9..5f5c535 100644 --- a/pyarlo/const.py +++ b/pyarlo/const.py @@ -1,23 +1,23 @@ """Constants used by Python Arlo.""" # API Endpoints -API_URL = "https://arlo.netgear.com/hmsweb" +API_URL = "https://my.arlo.com" -DEVICE_SUPPORT_ENDPOINT = API_URL + "/devicesupport/v2" -SUBSCRIBE_ENDPOINT = API_URL + "/client/subscribe" -UNSUBSCRIBE_ENDPOINT = API_URL + "/client/unsubscribe" -BILLING_ENDPOINT = API_URL + "/users/serviceLevel/v2" -DEVICES_ENDPOINT = API_URL + "/users/devices" -FRIENDS_ENDPOINT = API_URL + "/users/friends" -LIBRARY_ENDPOINT = API_URL + "/users/library" -LOGIN_ENDPOINT = API_URL + "/login/v2" -LOGOUT_ENDPOINT = API_URL + "/logout" -NOTIFY_ENDPOINT = API_URL + "/users/devices/notify/{0}" -PROFILE_ENDPOINT = API_URL + "/users/profile" +DEVICE_SUPPORT_ENDPOINT = API_URL + "/hmsweb/devicesupport/v2" +SUBSCRIBE_ENDPOINT = API_URL + "/hmsweb/client/subscribe" +UNSUBSCRIBE_ENDPOINT = API_URL + "/hmsweb/client/unsubscribe" +BILLING_ENDPOINT = API_URL + "/hmsweb/users/serviceLevel/v2" +DEVICES_ENDPOINT = API_URL + "/hmsweb/users/devices" +FRIENDS_ENDPOINT = API_URL + "/hmsweb/users/friends" +LIBRARY_ENDPOINT = API_URL + "/hmsweb/users/library" +LOGIN_ENDPOINT = "https://ocapi-app.arlo.com/api/auth" +LOGOUT_ENDPOINT = API_URL + "/hmsweb/logout" +NOTIFY_ENDPOINT = API_URL + "/hmsweb/users/devices/notify/{0}" +PROFILE_ENDPOINT = API_URL + "/hmsweb/users/profile" RESET_ENDPOINT = LIBRARY_ENDPOINT + "/reset" RESET_CAM_ENDPOINT = RESET_ENDPOINT + "/?uniqueId={0}" -STREAM_ENDPOINT = API_URL + "/users/devices/startStream" -SNAPSHOTS_ENDPOINT = API_URL + "/users/devices/fullFrameSnapshot" +STREAM_ENDPOINT = API_URL + "/hmsweb/users/devices/startStream" +SNAPSHOTS_ENDPOINT = API_URL + "/hmsweb/users/devices/fullFrameSnapshot" # number of days to preload video PRELOAD_DAYS = 30 diff --git a/pyarlo/media.py b/pyarlo/media.py index 8c8fad0..369c3e9 100644 --- a/pyarlo/media.py +++ b/pyarlo/media.py @@ -62,11 +62,14 @@ def load(self, days=PRELOAD_DAYS, only_cameras=None, for video in data: # pylint: disable=cell-var-from-loop - srccam = \ - list(filter( - lambda cam: cam.device_id == video.get('deviceId'), - all_cameras) - )[0] + try: + srccam = \ + list(filter( + lambda cam: cam.device_id == video.get('deviceId'), + all_cameras) + )[0] + except IndexError: + continue # make sure only_cameras is a list if only_cameras and \ @@ -187,6 +190,13 @@ def video_url(self): return self._attrs.get('presignedContentUrl') return None + @property + def motion_type(self): + """Returns the type of motion that triggered the camera. Requires subscription.""" + if self._attrs is not None: + return self._attrs.get("objCategory") + return None + def download_thumbnail(self, filename=None): """Download JPEG thumbnail. diff --git a/setup.py b/setup.py index 5e4df53..8dea378 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,7 @@ def readme(): setup( name='pyarlo', packages=['pyarlo'], - version='0.2.3', + version='0.2.4', description='Python Arlo is a library written in Python 2.7/3x ' + 'that exposes the Netgear Arlo cameras as Python objects.', long_description=readme(), diff --git a/tests/fixtures/pyarlo_authentication.json b/tests/fixtures/pyarlo_authentication.json index c8de888..562aed2 100644 --- a/tests/fixtures/pyarlo_authentication.json +++ b/tests/fixtures/pyarlo_authentication.json @@ -9,4 +9,5 @@ "token": "999999999999", "userId": "999-123456", "validEmail": true}, - "success": true} + "meta": {"code":200} +}