refactor it to oop, add some features and make sure it is user friendly
```
import datetime
import PySimpleGUI as sg
import os
import re

def clean_subtitle_line(line):
    # Remove all HTML-like tags
    line = re.sub(r'<[^>]+>', '', line)
    # Remove other common subtitle formatting tags like {\an8} or {\pos(400,570)}
    line = re.sub(r'{\\[^\}]+}', '', line)
    return line.strip()

def get_file_extension(file_path):
    return file_path.rsplit('.', 1)[-1].lower()

def convert_to_datetime(time_str):
    if len(time_str.split(':')) == 2:
        time_str = '00:' + time_str
    # Adjust the format to handle milliseconds
    if ',' in time_str:
        time_str = time_str.split(',')[0]  # Ignores the milliseconds for simplicity
    return datetime.datetime.strptime(time_str, '%H:%M:%S')


def read_file_lines(file_path):
    with open(file_path, 'r', encoding='utf-8-sig') as file:
        return file.readlines()

def is_metadata_line(line, file_type):
    return file_type == 'vtt' and line.startswith(('WEBVTT', 'Kind:', 'Language:'))

def process_subtitle_line(line, start_time, buffer, processed_lines, aggregation_method, aggregation_value):
    start_time_str, _ = line.split(' --> ')
    start_time_str = start_time_str.strip().split('.')[0]
    current_time = convert_to_datetime(start_time_str)

    if start_time is None:
        start_time = current_time
    if should_aggregate(buffer, start_time, current_time, aggregation_method, aggregation_value):
        processed_lines.append([start_time] + buffer)
        buffer = []
        start_time = current_time
    
    return start_time, buffer

def should_aggregate(buffer, start_time, current_time, aggregation_method, aggregation_value):
    if aggregation_method == 'Lines':
        return len(buffer) >= aggregation_value
    elif aggregation_method == 'Time':
        return (current_time - start_time).total_seconds() >= aggregation_value
    return False

def format_lines(processed_lines, include_timestamp):
    formatted_lines = []
    for block in processed_lines:
        if include_timestamp:
            timestamp = format_timestamp(block[0])
            texts = ' '.join(block[1:])
            formatted_lines.append(f"[{timestamp}] {texts}")
        else:
            formatted_lines.append(' '.join(block[1:]))
    return formatted_lines

def format_timestamp(time):
    formatted_time = time.strftime('%H:%M:%S').lstrip('0').lstrip(':')
    return formatted_time if formatted_time else '00:00'

def save_lines_to_file(output_directory, original_file_path, lines):
    if not output_directory:
        output_directory = os.path.dirname(original_file_path)
    output_file_path = os.path.join(output_directory, os.path.basename(original_file_path).rsplit('.', 1)[0] + '.txt')
    with open(output_file_path, 'w', encoding='utf-8') as file:
        file.write('\n'.join(lines))
    sg.popup('Success!', f'The file has been converted and saved as {output_file_path}')
    os.startfile(output_file_path)

def process_content(content, file_type, aggregation_method, aggregation_value):
    start_time = None
    buffer = []
    processed_lines = []

    for line in content:
        line = line.strip()
        if is_metadata_line(line, file_type):
            continue
        if ' --> ' in line:
            start_time, buffer = process_subtitle_line(line, start_time, buffer, processed_lines, aggregation_method, aggregation_value)
        elif line:
            # Skip lines that are only numbers (possibly line numbers)
            if line.isdigit():
                continue
            buffer.append(clean_subtitle_line(line))

    if buffer:
        processed_lines.append([start_time] + buffer)

    return processed_lines


def handle_file_conversion(file_path, output_directory, aggregation_method, aggregation_value, include_timestamp):
    file_type = get_file_extension(file_path)
    if file_type not in ['vtt', 'srt']:
        sg.popup_error('Error', 'Unsupported file format.')
        return

    content = read_file_lines(file_path)
    processed_lines = process_content(content, file_type, aggregation_method, aggregation_value)
    formatted_lines = format_lines(processed_lines, include_timestamp)
    save_lines_to_file(output_directory, file_path, formatted_lines)

def define_layout():
    return [
        [sg.Text('Browse for subtitle file:'), sg.InputText(), sg.FileBrowse(file_types=(("Subtitle Files", "*.vtt;*.srt"),), key='FILE')],
        [sg.Text('Output folder:'), sg.InputText(), sg.FolderBrowse(key='OUTPUT_FOLDER')],
        [sg.Radio('Group by number of lines', "RADIO1", default=True, key='Lines'),
         sg.Radio('Group by time (seconds)', "RADIO1", key='Time')],
        [sg.Text('Enter value:'), sg.InputText('3', size=(5, 1), key='VALUE')],
        [sg.Radio('With timestamp', "RADIO2", default=True, key='WithTimestamp'),
         sg.Radio('Without timestamp', "RADIO2", key='WithoutTimestamp')],
        [sg.Button('Convert'), sg.Button('Exit')]
    ]

def handle_convert_event(values):
    if values['FILE'] and values['VALUE'].isdigit():
        with_timestamp = values['WithTimestamp']
        output_directory = values['OUTPUT_FOLDER'] if values['OUTPUT_FOLDER'] else os.path.dirname(values['FILE'])
        handle_file_conversion(values['FILE'], output_directory, 'Lines' if values['Lines'] else 'Time', int(values['VALUE']), with_timestamp)
    else:
        sg.popup_error('Error', 'Please select a subtitle file and enter a valid number or time in seconds.')

def main():
    sg.theme('Reddit')
    layout = define_layout()
    window = sg.Window('Subtitle to TXT Converter', layout)
    
    while True:
        event, values = window.read()
        if event in (sg.WIN_CLOSED, 'Exit'):
            break
        if event == 'Convert':
            handle_convert_event(values)
    
    window.close()

if __name__ == '__main__':
    main()
```