# Path: config/hass/custom_components/aarlo/pyaarlo/constant.py
# LIBRARY_PATH = '/hmsweb/users/library'
# 
# PRELOAD_DAYS = 30
# 
# Path: config/hass/custom_components/aarlo/pyaarlo/util.py
# def arlotime_strftime(timestamp, date_format='%Y-%m-%dT%H:%M:%S'):
#     return arlotime_to_datetime(timestamp).strftime(date_format)
# 
# def arlotime_to_datetime(timestamp):
#     return datetime.fromtimestamp(int(timestamp / 1000))
# 
# def http_get(url, filename=None):
#     # make request
#     ret = _http_get(url)
#     if ret is None:
#         return False
# 
#     if filename is None:
#         return ret.content
# 
#     with open(filename, 'wb') as data:
#         data.write(ret.content)
#     return True
# 
# def http_stream(url, chunk=4096):
#     """Generate stream for a given record video.
# 
#     :param url: url of stream to read
#     :param chunk: chunk bytes to read per time
#     :returns generator object
#     """
#     ret = requests.get(url, stream=True)
#     ret.raise_for_status()
#     for data in ret.iter_content(chunk):
#         yield data


import threading
from datetime import datetime, timedelta
from .constant import LIBRARY_PATH, PRELOAD_DAYS
from .util import (arlotime_strftime, arlotime_to_datetime, http_get,
                   http_stream)
        self._videos = []
        self._video_keys = []

    def __repr__(self):
        return "<{0}:{1}>".format(self.__class__.__name__, self._arlo.cfg.name)

    # grab recordings from last day, add to existing library if not there
    def update(self):
        self._arlo.debug('updating image library')

        # grab today's images
        date_to = datetime.today().strftime('%Y%m%d')
        data = self._arlo.be.post(LIBRARY_PATH, {'dateFrom':date_to, 'dateTo':date_to})

        # get current videos
        with self._lock:
            keys = self._video_keys

        # add in new images
        videos = []
        for video in data:

            # skip not video
            if not video.get('contentType', '').startswith('video/'):
                continue

            camera = self._arlo.lookup_camera_by_id(video.get('deviceId'))
            if not camera:
                continue


# Path: config/hass/custom_components/aarlo/pyaarlo/constant.py
# LIBRARY_PATH = '/hmsweb/users/library'
# 
# PRELOAD_DAYS = 30
# 
# Path: config/hass/custom_components/aarlo/pyaarlo/util.py
# def arlotime_strftime(timestamp, date_format='%Y-%m-%dT%H:%M:%S'):
#     return arlotime_to_datetime(timestamp).strftime(date_format)
# 
# def arlotime_to_datetime(timestamp):
#     return datetime.fromtimestamp(int(timestamp / 1000))
# 
# def http_get(url, filename=None):
#     # make request
#     ret = _http_get(url)
#     if ret is None:
#         return False
# 
#     if filename is None:
#         return ret.content
# 
#     with open(filename, 'wb') as data:
#         data.write(ret.content)
#     return True
# 
# def http_stream(url, chunk=4096):
#     """Generate stream for a given record video.
# 
#     :param url: url of stream to read
#     :param chunk: chunk bytes to read per time
#     :returns generator object
#     """
#     ret = requests.get(url, stream=True)
#     ret.raise_for_status()
#     for data in ret.iter_content(chunk):
#         yield data


# Path: config/hass/custom_components/aarlo/pyaarlo/media.py
import threading
from datetime import datetime, timedelta
from .constant import LIBRARY_PATH, PRELOAD_DAYS
from .util import (arlotime_strftime, arlotime_to_datetime, http_get,
                   http_stream)

        self._videos = []
        self._video_keys = []

    def __repr__(self):
        return "<{0}:{1}>".format(self.__class__.__name__, self._arlo.cfg.name)

    # grab recordings from last day, add to existing library if not there
    def update(self):
        self._arlo.debug('updating image library')

        # grab today's images
        date_to = datetime.today().strftime('%Y%m%d')
        data = self._arlo.be.post(LIBRARY_PATH, {'dateFrom':date_to, 'dateTo':date_to})

        # get current videos
        with self._lock:
            keys = self._video_keys

        # add in new images
        videos = []
        for video in data:

            # skip not video
            if not video.get('contentType', '').startswith('video/'):
                continue

            camera = self._arlo.lookup_camera_by_id(video.get('deviceId'))
            if not camera:
                continue


            key = '{0}:{1}'.format(video.get('deviceId'), arlotime_strftime(video.get('localCreatedDate')))