(self, result, camera, path, delay, debug)
Parse downloaded videos.
Parse downloaded videos.
Parse downloaded videos .
def _parse_downloaded_items(self, result, camera, path, delay, debug):
        """Parse downloaded videos."""
        for item in result:
            try:
                created_at = item["created_at"]
                camera_name = item["device_name"]
                is_deleted = item["deleted"]
                address = item["media"]
            except KeyError:
                _LOGGER.info("Missing clip information, skipping...")
                continue

            if camera_name not in camera and "all" not in camera:
                _LOGGER.debug("Skipping videos for %s.", camera_name)
                continue

            if is_deleted:
                _LOGGER.debug("%s: %s is marked as deleted.", camera_name, address)
                continue

            clip_address = f"{self.urls.base_url}{address}"
            filename = f"{camera_name}-{created_at}"
            filename = f"{slugify(filename)}.mp4"
            filename = os.path.join(path, filename)

            if not debug:
                if os.path.isfile(filename):
                    _LOGGER.info("%s already exists, skipping...", filename)
                    continue

                response = api.http_get(
                    self,
                    url=clip_address,
                    stream=True,
                    json=False,
                    timeout=TIMEOUT_MEDIA,
                )
                with open(filename, "wb") as vidfile:
                    copyfileobj(response.raw, vidfile)

                _LOGGER.info("Downloaded video to %s", filename)
            else:
                print(
                    (
                        f"Camera: {camera_name}, Timestamp: {created_at}, "
                        "Address: {address}, Filename: {filename}"
                    )
                )
            if delay > 0:
                time.sleep(delay)
def _parse_downloaded_items ( self , result , camera , path , delay , debug ) : for item in result : try : created_at = item [ "created_at" ] camera_name = item [ "device_name" ] is_deleted = item [ "deleted" ] address = item [ "media" ] except KeyError : _LOGGER . info ( "Missing clip information, skipping..." ) continue if camera_name not in camera and "all" not in camera : _LOGGER . debug ( "Skipping videos for %s." , camera_name ) continue if is_deleted : _LOGGER . debug ( "%s: %s is marked as deleted." , camera_name , address ) continue clip_address = f"{self.urls.base_url}{address}" filename = f"{camera_name}-{created_at}" filename = f"{slugify(filename)}.mp4" filename = os . path . join ( path , filename ) if not debug : if os . path . isfile ( filename ) : _LOGGER . info ( "%s already exists, skipping..." , filename ) continue response = api . http_get ( self , url = clip_address , stream = True , json = False , timeout = TIMEOUT_MEDIA , ) with open ( filename , "wb" ) as vidfile : copyfileobj ( response . raw , vidfile ) _LOGGER . info ( "Downloaded video to %s" , filename ) else : print ( ( f"Camera: {camera_name}, Timestamp: {created_at}, " "Address: {address}, Filename: {filename}" ) ) if delay > 0 : time . sleep ( delay )