# Path: operators/pylrc/tools/timecode.py
# def is_timecode(timecode):
#     """Checks if a string is a proper lrc timecode"""
# 
#     timecode = timecode.replace('<', '[').replace('>', ']')
#     try:
#         x = datetime.strptime(timecode, '[%M:%S.%f]')
#         return True
# 
#     except ValueError:
#         return False
# 
# def timecode_to_srt(timecode):
#     """convert timecode of format [MM:SS.ff] to an srt format timecode"""
#     secs = timecode_to_seconds(timecode)
# 
#     hours = "00"
#     minutes = "%02d" % int(secs / 60)
#     seconds = "%02d" % int(secs % 60)
#     millis = "%03d" % (round(secs - int(secs), 2) * 1000)
# 
#     return ''.join([hours, ':', minutes, ':', seconds, ',', millis])
# 
# Path: operators/pylrc/tools/find_even_split.py
# def find_even_split(line):
#     """
#     Given a string, splits it into two (almost) evenly spaced lines
#     """
#     word_list = line.split(' ')
#     differences = []
#     for i in range(len(word_list)):
#         group1 = ' '.join(word_list[0:i + 1])
#         group2 = ' '.join(word_list[i + 1::])
#         differences.append(abs(len(group1) - len(group2)))
#     index = differences.index(min(differences))
#     for i in range(len(word_list)):
#         if i == index:
#             group1 = ' '.join(word_list[0:i+1])
#             group2 = ' '.join(word_list[i+1::])
# 
#     return ''.join([group1, '\n', group2]).rstrip()


from .tools.timecode import is_timecode, timecode_to_srt
from .tools.find_even_split import find_even_split
        Checks if the subs is an enhanced lrc
        """
        for sub in self:
            word = '<' + sub.text.split('<')[-1]
            if is_timecode(word[0:10]):
                return True
        return False

    def to_SRT(self):
        """Returns an SRT string of the LRC data"""

        if not self[-1].text.rstrip() == "":
            timecode = self[-1].lrc_timecode
            end_line = LyricLine(timecode, "")
            end_line.shift(seconds=5)
            self.append(end_line)

        if self.is_enhanced_lrc():
            return self.to_ESRT()

        output = []
        srt = ""
        for i in range(len(self) - 1):
            if not self[i].text == '':
                srt = str(i + 1) + '\n'
                start_timecode = self[i].srt_time
                end_timecode = self[i + 1].srt_time

                srt = srt + start_timecode + ' --> ' + end_timecode + '\n'
                if len(self[i].text) > 31:

# Path: operators/pylrc/tools/timecode.py
# def is_timecode(timecode):
#     """Checks if a string is a proper lrc timecode"""
# 
#     timecode = timecode.replace('<', '[').replace('>', ']')
#     try:
#         x = datetime.strptime(timecode, '[%M:%S.%f]')
#         return True
# 
#     except ValueError:
#         return False
# 
# def timecode_to_srt(timecode):
#     """convert timecode of format [MM:SS.ff] to an srt format timecode"""
#     secs = timecode_to_seconds(timecode)
# 
#     hours = "00"
#     minutes = "%02d" % int(secs / 60)
#     seconds = "%02d" % int(secs % 60)
#     millis = "%03d" % (round(secs - int(secs), 2) * 1000)
# 
#     return ''.join([hours, ':', minutes, ':', seconds, ',', millis])
# 
# Path: operators/pylrc/tools/find_even_split.py
# def find_even_split(line):
#     """
#     Given a string, splits it into two (almost) evenly spaced lines
#     """
#     word_list = line.split(' ')
#     differences = []
#     for i in range(len(word_list)):
#         group1 = ' '.join(word_list[0:i + 1])
#         group2 = ' '.join(word_list[i + 1::])
#         differences.append(abs(len(group1) - len(group2)))
#     index = differences.index(min(differences))
#     for i in range(len(word_list)):
#         if i == index:
#             group1 = ' '.join(word_list[0:i+1])
#             group2 = ' '.join(word_list[i+1::])
# 
#     return ''.join([group1, '\n', group2]).rstrip()


# Path: operators/pylrc/lyrics.py
from .tools.timecode import is_timecode, timecode_to_srt
from .tools.find_even_split import find_even_split

        Checks if the subs is an enhanced lrc
        """
        for sub in self:
            word = '<' + sub.text.split('<')[-1]
            if is_timecode(word[0:10]):
                return True
        return False

    def to_SRT(self):
        """Returns an SRT string of the LRC data"""

        if not self[-1].text.rstrip() == "":
            timecode = self[-1].lrc_timecode
            end_line = LyricLine(timecode, "")
            end_line.shift(seconds=5)
            self.append(end_line)

        if self.is_enhanced_lrc():
            return self.to_ESRT()

        output = []
        srt = ""
        for i in range(len(self) - 1):
            if not self[i].text == '':
                srt = str(i + 1) + '\n'
                start_timecode = self[i].srt_time
                end_timecode = self[i + 1].srt_time

                srt = srt + start_timecode + ' --> ' + end_timecode + '\n'
                if len(self[i].text) > 31:

                    srt = srt + find_even_split(self[i].text) + '\n'