Retrieve or create a folder inside the library with the specified name.

def _get_folder(gi, folder_name, library, libitems):
    """Retrieve or create a folder inside the library with the specified name.
    """
    for item in libitems:
        if item["type"] == "folder" and item["name"] == "/%s" % folder_name:
            return item
    return gi.libraries.create_folder(library.id, folder_name)[0]