def do_work(camera_ip, start_datetime_str, end_datetime_str, use_utc_time,
            content_type):
    logger = Logger.get_logger()
    try:
        logger.info('Processing cam {}: downloading {}'.format(
            camera_ip, content_type))
        logger.info('{} time is used'.format(
            "UTC" if use_utc_time else "Camera's local"))

        auth_type = CameraSdk.get_auth_type(camera_ip, user_name,
                                            user_password)
        if auth_type == AuthType.UNAUTHORISED:
            raise RuntimeError('Unauthorised! Check login and password')

        auth_handler = CameraSdk.get_auth(auth_type, user_name, user_password)

        if use_utc_time:
            local_time_offset = timedelta()
        else:
            local_time_offset = CameraSdk.get_time_offset(
                auth_handler, camera_ip)

        utc_time_interval = TimeInterval.from_string(
            start_datetime_str, end_datetime_str, local_time_offset).to_utc()

        download_media(auth_handler, camera_ip, utc_time_interval,
                       content_type)

    except requests.exceptions.ConnectionError as e:
        logger.error('Connection error: {}'.format(e))

    except Exception as e:
        logger.exception(e)
def get_tracks_info(auth_handler, cam_ip, utc_time_interval, content_type):
    if content_type == ContentType.VIDEO:
        return CameraSdk.get_video_tracks_info(
            auth_handler, cam_ip, utc_time_interval,
            MAX_NUMBER_OF_FILES_IN_ONE_REQUEST)
    else:
        return CameraSdk.get_photo_tracks_info(
            auth_handler, cam_ip, utc_time_interval,
            MAX_NUMBER_OF_FILES_IN_ONE_REQUEST)
def init(cam_ip):
    path_to_log_file = base_path_to_log_file + log_file_name_pattern.format(
        cam_ip)

    create_directory_for(path_to_log_file)
    create_directory_for(get_path_to_video_archive(cam_ip))

    Logger.init_logger(write_logs, path_to_log_file, MAX_BYTES_LOG_FILE_SIZE,
                       MAX_LOG_FILES_COUNT)

    CameraSdk.init(DEFAULT_TIMEOUT_SECONDS)
예제 #4
0
def get_all_tracks(auth_handler, cam_ip, utc_time_interval):
    tracks = []
    while True:
        answer = get_video_tracks_info(auth_handler, cam_ip, utc_time_interval)
        local_time_offset = utc_time_interval.local_time_offset
        if answer:
            new_tracks = CameraSdk.create_tracks_from_info(
                answer, local_time_offset)
            tracks += new_tracks
            if len(new_tracks) < MAX_VIDEOS_NUMBER_IN_ONE_REQUEST:
                break

            last_track = tracks[-1]
            utc_time_interval.start_time = last_track.get_time_interval(
            ).end_time
        else:
            tracks = []
            break

    return tracks
def wait_until_camera_rebooted(cam_ip):
    CameraSdk.wait_until_camera_rebooted(
        cam_ip, CAMERA_REBOOT_TIME_SECONDS,
        DELAY_BEFORE_CHECKING_AVAILABILITY_SECONDS)
def reboot_camera(auth_handler, cam_ip):
    CameraSdk.reboot_camera(auth_handler, cam_ip)
def download_file(auth_handler, cam_ip, url_to_download, file_name):
    return CameraSdk.download_file(auth_handler, cam_ip, url_to_download,
                                   file_name)
    def test_decode_timezone_plus(self):
        raw_timezone = 'CST-5:00:00'
        expected_time_offset = timedelta(hours=5)

        actual_time_offset = CameraSdk.parse_timezone(raw_timezone)
        self.assertEqual(expected_time_offset, actual_time_offset)
    def test_decode_timezone_plus_minutes_and_seconds(self):
        raw_timezone = 'CST-5:45:20'
        expected_time_offset = timedelta(hours=5, minutes=45, seconds=20)

        actual_time_offset = CameraSdk.parse_timezone(raw_timezone)
        self.assertEqual(expected_time_offset, actual_time_offset)
    def test_decode_timezone_minutes_and_seconds(self):
        raw_timezone = 'CST+7:30:10'
        expected_time_offset = timedelta(hours=-7, minutes=-30, seconds=-10)

        actual_time_offset = CameraSdk.parse_timezone(raw_timezone)
        self.assertEqual(expected_time_offset, actual_time_offset)
예제 #11
0
 def get_video_tracks_info(result):
     if not result:
         error_message = CameraSdk.get_error_message_from(result)
         Logger.get_logger().error(
             'Error occurred during getting track list')
         Logger.get_logger().error(error_message)
 def download_file_after(result):
     if not result:
         error_message = CameraSdk.get_error_message_from(result)
         Logger.get_logger().error(error_message)
예제 #13
0
def get_video_tracks_info(auth_handler, cam_ip, utc_time_interval):
    return CameraSdk.get_video_tracks_info(auth_handler, cam_ip,
                                           utc_time_interval,
                                           MAX_VIDEOS_NUMBER_IN_ONE_REQUEST)