# Path: operators/tools/get_open_channel.py
# def get_open_channel(scene):
#     """Get a channel with nothing in it"""
#     channels = []
#     try:
#         for strip in scene.sequence_editor.sequences_all:
#             channels.append(strip.channel)
#         if len(channels) > 0:
#             return max(channels) + 1
#         else:
#             return 1
#     except AttributeError:
#         return 1
# 
# Path: operators/tools/get_font.py
# def get_font(font_path):
# 
# 	if os.path.isfile(font_path):
# 		return bpy.data.fonts.load(font_path, check_existing=True)
# 	else:
# 		return None


import bpy
from .get_open_channel import get_open_channel
from .get_font import get_font
        scene.sequence_editor_create()

    wm = context.window_manager
    wm.progress_begin(0, 100.0)

    added_strips = []

    for i in range(len(subs)):
        start_time = subs[i].start.to_millis() / 1000
        strip_start = round(start_time * fps, 0)

        end_time = subs[i].end.to_millis() / 1000
        strip_end = round(end_time * fps, 0)
        sub_name = str(open_channel) + '_' + str(i + 1)
        try:
            if '[locked start]' in subs[i].name:
                sub_name = '[locked start]' + sub_name
            if '[locked end]' in subs[i].name:
                sub_name += '[locked end]'
        except AttributeError:
            pass

        text_strip = scene.sequence_editor.sequences.new_effect(
            name=sub_name,
            type='TEXT',
            channel=open_channel,
            frame_start=strip_start,
            frame_end=strip_end
            )


# Path: operators/tools/get_open_channel.py
# def get_open_channel(scene):
#     """Get a channel with nothing in it"""
#     channels = []
#     try:
#         for strip in scene.sequence_editor.sequences_all:
#             channels.append(strip.channel)
#         if len(channels) > 0:
#             return max(channels) + 1
#         else:
#             return 1
#     except AttributeError:
#         return 1
# 
# Path: operators/tools/get_font.py
# def get_font(font_path):
# 
# 	if os.path.isfile(font_path):
# 		return bpy.data.fonts.load(font_path, check_existing=True)
# 	else:
# 		return None


# Path: operators/tools/subtitles_to_sequencer.py
import bpy
from .get_open_channel import get_open_channel
from .get_font import get_font

        scene.sequence_editor_create()

    wm = context.window_manager
    wm.progress_begin(0, 100.0)

    added_strips = []

    for i in range(len(subs)):
        start_time = subs[i].start.to_millis() / 1000
        strip_start = round(start_time * fps, 0)

        end_time = subs[i].end.to_millis() / 1000
        strip_end = round(end_time * fps, 0)
        sub_name = str(open_channel) + '_' + str(i + 1)
        try:
            if '[locked start]' in subs[i].name:
                sub_name = '[locked start]' + sub_name
            if '[locked end]' in subs[i].name:
                sub_name += '[locked end]'
        except AttributeError:
            pass

        text_strip = scene.sequence_editor.sequences.new_effect(
            name=sub_name,
            type='TEXT',
            channel=open_channel,
            frame_start=strip_start,
            frame_end=strip_end
            )


        text_strip.font = get_font(scene.subtitle_font)