# Path: operators/textparser/tools/find_even_split.py
# def find_even_split(line):
#     max_line_length = 31
#     output = make_lines(line, max_line_length)
#     max_lines = len(output)
#     space = max_line_length - 1
#     while len(make_lines(line, space)) == max_lines:
#         space -= 1
#     lines = make_lines(line, space + 1)
#     return '\n'.join(make_lines(line, space + 1))
# 
# Path: operators/textparser/tools/seconds_to_srt_timecode.py
# def seconds_to_srt_timecode(sec_time):
#     """
#     Converts time (in seconds) into a timecode with the format
#     23:59:59,999
#     """
#     hours = int(sec_time / 3600)
#     minutes = int((sec_time % 3600) / 60)
#     seconds = int((((sec_time % 3600) / 60) - minutes) * 60)
#     milliseconds = int((sec_time - int(sec_time)) * 1000)
# 
#     hours = "%02d" % hours
#     minutes = "%02d" % minutes
#     seconds = "%02d" % seconds
#     milliseconds = "%03d" % milliseconds
# 
#     return ''.join([hours, ':', minutes, ':', seconds, ',',
#                     milliseconds])


from .tools.find_even_split import find_even_split
from .tools.seconds_to_srt_timecode import seconds_to_srt_timecode

def text_to_srt(text, fps, reflow_long_lines=False):
    """
    Creates an SRT string out of plain text, with 1 second for each
    segment
    """
    text = text.strip()
    lines = text.split('\n')

    output = []
    sec_time = 0
    for i in range(len(lines)):
        seg = str(i + 1) + '\n'

        start = seconds_to_srt_timecode(i + 0.00000001)
        sec_time = i + 1.00000001

# Path: operators/textparser/tools/find_even_split.py
# def find_even_split(line):
#     max_line_length = 31
#     output = make_lines(line, max_line_length)
#     max_lines = len(output)
#     space = max_line_length - 1
#     while len(make_lines(line, space)) == max_lines:
#         space -= 1
#     lines = make_lines(line, space + 1)
#     return '\n'.join(make_lines(line, space + 1))
# 
# Path: operators/textparser/tools/seconds_to_srt_timecode.py
# def seconds_to_srt_timecode(sec_time):
#     """
#     Converts time (in seconds) into a timecode with the format
#     23:59:59,999
#     """
#     hours = int(sec_time / 3600)
#     minutes = int((sec_time % 3600) / 60)
#     seconds = int((((sec_time % 3600) / 60) - minutes) * 60)
#     milliseconds = int((sec_time - int(sec_time)) * 1000)
# 
#     hours = "%02d" % hours
#     minutes = "%02d" % minutes
#     seconds = "%02d" % seconds
#     milliseconds = "%03d" % milliseconds
# 
#     return ''.join([hours, ':', minutes, ':', seconds, ',',
#                     milliseconds])


# Path: operators/textparser/parser.py
from .tools.find_even_split import find_even_split
from .tools.seconds_to_srt_timecode import seconds_to_srt_timecode


def text_to_srt(text, fps, reflow_long_lines=False):
    """
    Creates an SRT string out of plain text, with 1 second for each
    segment
    """
    text = text.strip()
    lines = text.split('\n')

    output = []
    sec_time = 0
    for i in range(len(lines)):
        seg = str(i + 1) + '\n'

        start = seconds_to_srt_timecode(i + 0.00000001)
        sec_time = i + 1.00000001

        end = seconds_to_srt_timecode(sec_time)