#!/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 proxyheadless
    launchutils.set_app_runtime_type(modules_path)
    
    session_id = _get_arg_value("session_id")
    parent_folder = _get_arg_value("parent_folder")
    media_file_id = _get_arg_value("media_file_id")
    proxy_w = _get_arg_value("proxy_w")
    proxy_h = _get_arg_value("proxy_h")
    enc_index = _get_arg_value("enc_index")
    proxy_file_path = _get_arg_value("proxy_file_path")
    proxy_rate = _get_arg_value("proxy_rate")
    media_file_path = _get_arg_value("media_file_path")
    lookup_path =  _get_arg_value("lookup_path")
    profile_desc_under_score = _get_arg_value("proxy_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.
    is_transcode =  _get_arg_value("is_transcode")
    print("is_transcode", is_transcode)
except Exception as err:
    print ("Failed to import proxyheadless")
    print ("ERROR:", err)
    print ("Installation was assumed to be at:", modules_path)
    sys.exit(1)

proxyheadless.main( modules_path, parent_folder,session_id, media_file_id, 
                    proxy_w, proxy_h, enc_index, proxy_file_path, 
                    proxy_rate, media_file_path, profile_desc, 
                    lookup_path, is_transcode)




