def make_link(index, link, label, path):
    menu_items = []
    queries = {'mode': MODES.DELETE_LINK, 'index': index, 'path': path}
    menu_items.append(
        ('Delete Link', 'RunPlugin(%s)' % (kodi.get_plugin_url(queries))), )
    queries = {'mode': MODES.EDIT_LINK, 'index': index, 'path': path}
    menu_items.append(
        ('Edit Link', 'RunPlugin(%s)' % (kodi.get_plugin_url(queries))), )
    kodi.create_item({
        'mode': MODES.PLAY_LINK,
        'link': link
    },
                     label,
                     is_folder=False,
                     is_playable=True,
                     menu_items=menu_items)
def make_directory(path, dir_name):
    menu_items = []
    queries = {'mode': MODES.DELETE_DIR, 'path': path, 'dir_name': dir_name}
    menu_items.append(('Delete Directory', 'RunPlugin(%s)' %
                       (kodi.get_plugin_url(queries))), )
    queries = {'mode': MODES.RENAME_DIR, 'path': path, 'dir_name': dir_name}
    menu_items.append(('Rename Directory', 'RunPlugin(%s)' %
                       (kodi.get_plugin_url(queries))), )
    path = os.path.join(path, dir_name)
    kodi.create_item({
        'mode': MODES.OPEN_DIR,
        'path': path
    },
                     dir_name,
                     is_folder=True,
                     menu_items=menu_items)
def open_dir(path):
    kodi.create_item({
        'mode': MODES.CREATE_DIR,
        'path': path
    },
                     'Create Directory ',
                     is_folder=False,
                     is_playable=False)
    kodi.create_item({
        'mode': MODES.ADD_LINK,
        'path': path
    },
                     'Add Link',
                     is_folder=False,
                     is_playable=False)
    kodi.create_item({'mode': MODES.SETTINGS},
                     'SMR Settings',
                     is_folder=False,
                     is_playable=False)
    path, dirs, files = get_directory(path)
    for dir_name in sorted(dirs):
        make_directory(path, dir_name)

    if LINK_FILE in files:
        link_file = os.path.join(path, LINK_FILE)
        with open(link_file) as f:
            for i, line in enumerate(f):
                item = line.split('|')
                link = item[0].strip()
                if not link:
                    continue
                try:
                    label = item[1]
                except:
                    label = item[0]
                make_link(i, link, label, path)

    kodi.set_content('files')
    kodi.end_of_directory(cache_to_disc=False)