def load(self, days=PRELOAD_DAYS):

        self._arlo.debug('loading image library')

        # set begining and end
        now = datetime.today()
        date_from = (now - timedelta(days=days)).strftime('%Y%m%d')
        date_to = now.strftime('%Y%m%d')

        # save videos for cameras we know about
        data = self._arlo._be.post(LIBRARY_URL, {
            'dateFrom': date_from,
            'dateTo': date_to
        })
        videos = []
        keys = []
        for video in data:
            camera = self._arlo.lookup_camera_by_id(video.get('deviceId'))
            if camera is not None:
                key = '{0}:{1}'.format(
                    video.get('deviceId'),
                    arlotime_strftime(video.get('localCreatedDate')))
                self._arlo.debug('adding {0}'.format(key))
                videos.append(ArloVideo(video, camera, self._arlo))
                keys.append(key)

        # set update count, load() never runs callbacks
        with self._lock:
            self._count += 1
            self._videos = videos
            self._video_keys = keys
            self._arlo.debug('ml:load-count=' + str(self._count))
Exemple #2
0
    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_URL, {
            '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')))
            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()
Exemple #3
0
 def created_at_pretty(self, date_format=None):
     if date_format:
         return arlotime_strftime(self.created_at, date_format=date_format)
     return arlotime_strftime(self.created_at)
Exemple #4
0
 def name(self):
     return "{0}:{1}".format(self._camera.device_id,
                             arlotime_strftime(self.created_at))