# 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)
            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')))
            if key in keys:
                self._arlo.debug( 'skipping {0}, already present'.format( key ) )
                continue

            self._arlo.debug('adding {0}'.format(key))
            videos.append(ArloVideo(video, camera, self._arlo))
            keys.append(key)

        # note changes and run callbacks
        cbs = []
        with self._lock:
            self._count += 1
            self._videos = videos + self._videos
            self._video_keys = keys
            self._arlo.debug('ml:update-count=' + str(self._count))
            cbs = self._load_cbs_
            self._load_cbs_ = []

        # run callbacks with no locks held
        for cb in cbs:
            cb()


# 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)

            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')))
            if key in keys:
                self._arlo.debug( 'skipping {0}, already present'.format( key ) )
                continue

            self._arlo.debug('adding {0}'.format(key))
            videos.append(ArloVideo(video, camera, self._arlo))
            keys.append(key)

        # note changes and run callbacks
        cbs = []
        with self._lock:
            self._count += 1
            self._videos = videos + self._videos
            self._video_keys = keys
            self._arlo.debug('ml:update-count=' + str(self._count))
            cbs = self._load_cbs_
            self._load_cbs_ = []

        # run callbacks with no locks held
        for cb in cbs:
            cb()


    def load(self, days=PRELOAD_DAYS):