#!/usr/bin/python3

import sys
import os

import launchutils


def _get_arg_value(key_str):
    return launchutils.get_arg_value(key_str)

modules_path = launchutils.get_modules_path()
sys.path.insert(0, modules_path)

import processutils
processutils.update_sys_path(modules_path)

try:
    import mltxmlheadless
    launchutils.set_app_runtime_type(modules_path)
    
    session_id = _get_arg_value("session_id")
    parent_folder = _get_arg_value("parent_folder")
    xml_file_path = _get_arg_value("xml_file_path")
    video_file_name = _get_arg_value("video_file_name")
    range_in = _get_arg_value("range_in")
    range_out = _get_arg_value("range_out")
    profile_desc_under_score = _get_arg_value("profile_desc")
    profile_desc = profile_desc_under_score.replace("_", " ") # We need to put underscores in profile names to get them here in one piece.
                                                              # Now we take underscores out to get correct MLT profile names.
except Exception as err:
    print ("Failed to import mltxmlheadless")
    print ("ERROR:", err)
    print ("Installation was assumed to be at:", modules_path)
    sys.exit(1)

mltxmlheadless.main(modules_path, session_id, parent_folder, xml_file_path, video_file_name, range_in, range_out, profile_desc)




