import time

def process_m3u8_file(file_path):
    with open(file_path, 'r') as file:
        lines = file.readlines()

    updated_lines = []
    count_inf = 0
    count_discontinuity = 0

    for line in lines:
        if line.startswith('#EXTINF'):
            count_inf += 1
            if count_inf <= 10 and count_inf % 2 != 0:
                continue
            elif count_inf <= 10:
                count_inf = 0
        elif line.startswith('#EXT-X-DISCONTINUITY'):
            count_discontinuity += 1
            if count_discontinuity <= 10:
                continue
            else:
                count_discontinuity = 0
        else:
            count_inf = 0
            count_discontinuity = 0

        updated_lines.append(line)

    with open(file_path, 'w') as file:
        file.writelines(updated_lines)

# Example usage
m3u8_file_path = 'result_old_2.m3u8'

while True:
    process_m3u8_file(m3u8_file_path)
    print('M3U8 file processed.')

    time.sleep(900)  # Sleep for 15 minutes


