header={ "chef": "BeatRig", "recipe_version": "1.26", "title": "Convert To FLAC", "description": "Convert almost any file to FLAC", "spice": "BQ==:G+Hy36kJcnQQYYavb/JV2Il6eCYr6h4hRJHCF9rRbhX5BcazL6cuTgUMdz0xA50VWA5PmmV0Q7aWkiUtNFtbk991l+t0e8IBXMReMIT1GNjnZZDv7n2YRAo0xcSQbY0ixjG6LLH4wGKnspKAoA/v69iLn6N2IH0XzIZwTGdHSo4=", "flavour": "9LKrvS0JIBDzcokX8YjD8qL1Z/vmUPRQGB5ZgnAl+V1T/TsZShcAlLzWiamWC0JHVWirVcM/DBRXRm/RwCXqdlzGofNiDsUnboG+dQqJPsNLTp2VLFI6ryO/wgGMb26Sc/TXqPeG9a0gkdsr/wEOCGAc4vTbM4Np6ix58YnEL1s=", "time": 1677074290, "magnetron_version": "1.0.218", "tags": "audio", "core_version": "0.5.1", "palette": "Clean Slate", "dependencies": "ffprobe,ffmpeg", "type": "default", "os": "windows,macOS", "functions": "main", "uuid": "67a5626be28f42e9822814d348a5c8db", "instructions": "Drop file(s) here" }; // ============================================================================= // GLOBALS // ============================================================================= var duration = 0; // ============================================================================= // MAIN // ============================================================================= function main() { // ----------------------------- // CHECK IF FFMPEG AND FFPROBE ARE AVAILABLE if(getAllowedApps("ffmpeg") == '' ) abort("FFMPEG is not available"); if(getAllowedApps("ffprobe") == '' ) abort("FFMPEG is not available"); // ----------------------------- // START PROGRESS setProgress(101); // ----------------------------- // GET ALL FILES FROM THE APP var files = getFiles(); // ----------------------------- if( files.length == 0) abort("Add some files first!"); // ----------------------------- // CLEAN UP THE FILE LIST for (i=0;i 0) { files[i]["file_icon"] = "CheckSquare"; files[i]["file_icon_color"] = "FFFF0000"; files[i]["file_status"] = "Conversion failed!"; // REMOVE FILE IF FAILED if(fileExists(outfile)) deleteFile(outfile); } else { files[i]["file_icon"] = "CheckSquare"; files[i]["file_icon_color"] = "FF008800"; files[i]["file_status"] = "Done"; } setFiles(files); } // ALL DONE setFiles(files); setProgress(100); setMainMessage(" "); } // ============================================================================= // CMD CALLBACK // ============================================================================= function cmd_callback(cmd_name, cmd_output) { // FOR AUDIO GET THE DURATION if(cmd_name == "ffmpeg" && cmd_output.length > 0 && duration > 0.) { var progress = searchRegEx(cmd_output , "(?:time=)(.*?)(?:\ bitrate=)", "i", 1); progress = progress[progress.length-1].split(':'); progress = (parseFloat(progress[0]) * 60. * 60.) + (parseFloat(progress[1])*60.) + parseFloat(progress[2]); Math.round( parseFloat(progress)/ duration * 100. ); setProgress( progress ); } } // ============================================================================= // OPEN DIALOG // ============================================================================= function openDialog(startfolder) { var form = { // PATH "path_label" : { "type" : "text", "label" : "source folder", "just" : "l", "bounds" : { "x": 20, "w" : 160, }, }, "path_toggle": { "type": "togglebox", "bounds" : { "y": -1, "x": 180, "w" : 25, }, "label" : "", "toggle" : true }, "custompath_label" : { "type" : "text", "label" : "folder", "just" : "l", "bounds" : { "x": 20, "w" : 160, }, "visible": false, }, "custompath" : { "type" : "fileselect", "path" : startfolder, "editable" : false, "dir" : true, "saving" : true, "label" : "empty", "bounds" : { "y": -1, "x": 180, "w" : 340, }, "visible": false, }, // MODE "bitrate_label" : { "type" : "text", "label" : "bitrate", "just" : "l", "bounds" : { "y": 220, "x": 20, "w" : 160, }, }, "bitrate" : { "type" : "combobox", "default" : "source", "items" : "source,32,24,20,16,12,8", "label" : "", "bounds" : { "y": 220, "x" : 180, "w" : 340 }, "visible" : true, }, // SAMPLE RATE "samplerate" : { "type" : "combobox", "default" : "source", "items" : "source,192kHz,176.4kHz,96kHz,88.2kHz,48kHz,44.1kHz,32kHz,22.05kHz", "label" : " ", "bounds" : {"y": 260, "x" : 180, "w" : 340 }, }, "samplerate_label" : { "type" : "text", "label" : "samplerate", "just" : "l", "bounds" : { "y": 260, "x" : 20, "w" : 120 }, }, // COMPRESSION "compression_label" : { "type" : "text", "label" : "compression", "just" : "l", "bounds" : { "x" : 20, "w" : 120 }, }, "compression" : { "type" : "combobox", "default" : "5", "items" : "0,1,2,3,4,5,6,7,8,9,10,11,12", "label" : " ", "bounds" : {"y": -1, "x" : 180, "w" : 340 }, }, // BUTTONS "spacer1" : { "type" : "text", "label" : " ", "just" : "r", "bounds" : { "x": 120, "w" : 200, "h" : 100 }, }, "cancel" : { "type" : "button", "label" : "cancel", "bounds" : { "x": 310, "w" : 100 }, "returns" : 0 }, "go" : { "type" : "button", "label" : "go", "bounds" : { "y": -1, "x": 420, "w" : 100, }, "returns" : 1 } }; return dialog(header.title, "", "", form); } // ============================================================================= function dialog_callback(props) { if (props["name"] == "path_toggle") var r = dialog({ "custompath" : { "visible" : !props["toggle"] }, "custompath_label" : { "visible" : !props["toggle"] } }); }