'Convert millisecond-based subtitles to SRT'

@staticmethod
def _fix_subtitles(subtitles):

    def _msectotimecode(msec):
        u'    Helper    utility    to    convert    milliseconds    to    timecode    '
        components = []
        for divider in [1000, 60, 60, 100]:
            components.append((msec % divider))
            msec //= divider
        return u'{3:02}:{2:02}:{1:02},{0:03}'.format(*components)
    def _fix_subtitle(subtitle):
        for line in subtitle.splitlines():
            m = re.match(u'^\\s*([0-9]+);\\s*([0-9]+)\\s+([0-9]+)\\s*$', line)
            if m:
                (yield m.group(1))
                (start, stop) = (_msectotimecode(int(t)) for t in m.groups()[1:])
                (yield u'{0}    -->    {1}'.format(start, stop))
            else:
                (yield line)
    return u'\r\n'.join(_fix_subtitle(subtitles))
