| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 | /*    FFmpeg Factory ArOZ JavaScript Gateway Interface Converter    This script will launch ffmpeg and convert a given file into the desired format*///Require libraryrequirelib("filelib");//Globaal variablesvar targetFilepath = filepath;var conversionCommand = command;//Helper function to get the filepath.Dir of the realpathfunction dir(filepath){	filepath = filepath.split("/");	filepath.pop();	return filepath.join("/");}//Return the filename of the path without extensionfunction base(filepath){    filepath = filepath.split("\\").join("/");    filepath = filepath.split("/");    filename = filepath.pop();    filename = filename.split(".")    filename.pop();    return filename.join(".");}//Package required. Get the real path of the fileif (filelib.fileExists(targetFilepath)){    var srcReal = decodeVirtualPath(targetFilepath);    srcReal = srcReal.split("\\").join("/");    //Parse the command for the conversion    var actualCommand = decodeURIComponent(command);    actualCommand = actualCommand.replace('{filepath}',srcReal);    actualCommand = actualCommand.replace('{filename}',dir(srcReal) + "/" + base(srcReal))    //Register this task in on-going task list    newDBTableIfNotExists("FFmpeg Factory")    var ts = Math.round((new Date()).getTime() / 1000);    var taskKey = USERNAME + "/" + ts;    writeDBItem("FFmpeg Factory",taskKey,targetFilepath)    //Pass the command into ffmpeg pkg    var results = execpkg("ffmpeg",actualCommand);    //Deregister this task from on-going task list    deleteDBItem("FFmpeg Factory",taskKey,targetFilepath);    sendJSONResp(JSON.stringify({        status: "ok",        execresults: results    }));   }else{    //File not exists. Return an error json    sendJSONResp(JSON.stringify({        error: "File not exists: " + targetFilepath    }));}
 |