def select_files_in_time_range()

in awstreamer/utils/video.py [0:0]


def select_files_in_time_range(files, timestamp_from, timestamp_to):
    '''
    Selects files in the specifed time range
    '''
    # Parse time stamp
    try:
        sec_from = timestamp_to_sec(timestamp_from)
        sec_to = timestamp_to_sec(timestamp_to)
    except:
        return []

    logger.info("sec_from: %s" % sec_from)
    logger.info("sec_to: %s" % sec_to)

    selectedFiles = []
    idx_from = -1
    idx_to = -1
    for i in range(len(files)):
        timestamp = files[i][2]

        # Find start time
        if idx_from < 0 and timestamp > sec_from:
            idx_from = i - 1

        # Append files if start time has been found
        if idx_from >= 0:
            selectedFiles.append(files[i - 1])

        # Find end time
        if idx_to < 0 and timestamp >= sec_to:
            idx_to = i
            break

    logger.info("idx_from: %d" % idx_from)
    logger.info("idx_to: %d" % idx_to)

    return selectedFiles