From d89300ecb72787b44b94b4ec92af8598149193bf Mon Sep 17 00:00:00 2001 From: Lawrence Curtis Date: Sun, 15 Sep 2024 22:49:42 +0100 Subject: [PATCH] run through linter --- ...lby Vision - Fix crop and compatibility.js | 184 ++++++++++-------- 1 file changed, 98 insertions(+), 86 deletions(-) diff --git a/Scripts/Flow/Video/Video - Dolby Vision - Fix crop and compatibility.js b/Scripts/Flow/Video/Video - Dolby Vision - Fix crop and compatibility.js index f475b91..1f564df 100644 --- a/Scripts/Flow/Video/Video - Dolby Vision - Fix crop and compatibility.js +++ b/Scripts/Flow/Video/Video - Dolby Vision - Fix crop and compatibility.js @@ -16,47 +16,49 @@ function Script(RemoveHDRTenPlus) { const videoStreams = Variables.vi.VideoInfo.VideoStreams; if (!(videoStreams?.length > 0 && videoStreams[0].DolbyVision)) { - Logger.ELog('No Dolby Vision detected') + Logger.ELog("No Dolby Vision detected"); return 2; } - if (!(videoStreams[0].Codec == 'hevc')) { - Logger.ELog('Video format MUST be HEVC, AV1 is not currently supported by dovi_tool'); + if (!(videoStreams[0].Codec == "hevc")) { + Logger.ELog( + "Video format MUST be HEVC, AV1 is not currently supported by dovi_tool" + ); return 2; } - Flow.AdditionalInfoRecorder('DoVi', 'Initializing', 1); + Flow.AdditionalInfoRecorder("DoVi", "Initializing", 1); - let dovi_tool = ToolPath('dovi_tool'); - if (!dovi_tool) - return -1; + let dovi_tool = ToolPath("dovi_tool"); + if (!dovi_tool) return -1; - let mkvmerge = ToolPath('mkvmerge'); - if (!mkvmerge) - return -1; + let mkvmerge = ToolPath("mkvmerge"); + if (!mkvmerge) return -1; - let mkvinfo = ToolPath('mkvinfo'); - if (!mkvinfo) - return -1; + let mkvinfo = ToolPath("mkvinfo"); + if (!mkvinfo) return -1; - let ffmpeg = ToolPath('ffmpeg'); - if (!ffmpeg) - return -1; + let ffmpeg = ToolPath("ffmpeg"); + if (!ffmpeg) return -1; let working = Flow.WorkingFile; let original = Variables.file.Orig.FullName; - Flow.AdditionalInfoRecorder('DoVi', 'Extracting HEVC bitstream', 1); + Flow.AdditionalInfoRecorder("DoVi", "Extracting HEVC bitstream", 1); var executeArgs = new ExecuteArgs(); executeArgs.command = ffmpeg; executeArgs.argumentList = [ - '-i', original, - '-c:v', 'copy', - '-bsf:v', 'hevc_mp4toannexb', - '-f', 'hevc', - Flow.TempPath + '/original.hevc' + "-i", + original, + "-c:v", + "copy", + "-bsf:v", + "hevc_mp4toannexb", + "-f", + "hevc", + Flow.TempPath + "/original.hevc", ]; executeArgs.add_Error((line) => { @@ -69,32 +71,36 @@ function Script(RemoveHDRTenPlus) { let process = Flow.Execute(executeArgs); if (process.exitCode !== 0) { - Logger.ELog('Failed to extract HEVC: ' + process.output); + Logger.ELog("Failed to extract HEVC: " + process.output); return -1; } Flow.PartPercentageUpdate(0); - Flow.AdditionalInfoRecorder('DoVi', 'Extracting RPU', 1); + Flow.AdditionalInfoRecorder("DoVi", "Extracting RPU", 1); // Creating RPU 8.1 file var executeArgs = new ExecuteArgs(); executeArgs.command = dovi_tool; executeArgs.argumentList = [ - '--crop', - '--mode', '2', - 'extract-rpu', - '-o', `${Flow.TempPath}/original.rpu`, - `${Flow.TempPath}/original.hevc` + "--crop", + "--mode", + "2", + "extract-rpu", + "-o", + `${Flow.TempPath}/original.rpu`, + `${Flow.TempPath}/original.hevc`, ]; if (RemoveHDRTenPlus) { - executeArgs.argumentList = ['--drop-hdr10plus'].concat(executeArgs.argumentList); + executeArgs.argumentList = ["--drop-hdr10plus"].concat( + executeArgs.argumentList + ); } if (!Flow.IsWindows) { let args = executeArgs.argumentList.join(" "); - executeArgs.argumentList = ['-qefc', dovi_tool + " " + args, '/dev/null']; - executeArgs.command = 'script'; + executeArgs.argumentList = ["-qefc", dovi_tool + " " + args, "/dev/null"]; + executeArgs.command = "script"; } executeArgs.add_Output((line) => { @@ -102,73 +108,77 @@ function Script(RemoveHDRTenPlus) { if (matches) { Flow.PartPercentageUpdate(matches[1]); } else { - Flow.AdditionalInfoRecorder('DoVi', line.replace(/\[2K/, ''), 1); + Flow.AdditionalInfoRecorder("DoVi", line.replace(/\[2K/, ""), 1); } }); process = Flow.Execute(executeArgs); if (process.exitCode !== 0) { - Logger.ELog('Failed to dovi_tool extract: ' + process.output); + Logger.ELog("Failed to dovi_tool extract: " + process.output); return -1; } // Remove temp files - System.IO.File.Delete(Flow.TempPath + '/original.hevc') + System.IO.File.Delete(Flow.TempPath + "/original.hevc"); Flow.PartPercentageUpdate(0); - Flow.AdditionalInfoRecorder('DoVi', 'Extracting converted video', 1); + Flow.AdditionalInfoRecorder("DoVi", "Extracting converted video", 1); var executeArgs = new ExecuteArgs(); executeArgs.command = ffmpeg; executeArgs.argumentList = [ - '-i', working, - '-c:v', 'copy', - Flow.TempPath + '/converted_video.hevc' + "-i", + working, + "-c:v", + "copy", + Flow.TempPath + "/converted_video.hevc", ]; executeArgs.add_Error((line) => { let matches = line.match(/time=([\.:0-9]+)/i); if (matches) { - ffPercent(duration, matches[1]) + ffPercent(duration, matches[1]); } }); Flow.Execute(executeArgs); if (process.exitCode !== 0) { - Logger.ELog('Failed to extract working video: ' + process.exitCode); + Logger.ELog("Failed to extract working video: " + process.exitCode); return -1; } Flow.PartPercentageUpdate(0); - Flow.AdditionalInfoRecorder('DoVi', 'Replacing RPU', 1); + Flow.AdditionalInfoRecorder("DoVi", "Replacing RPU", 1); // Inject original RPU and remove crop var executeArgs = new ExecuteArgs(); - executeArgs.command = dovi_tool + executeArgs.command = dovi_tool; executeArgs.argumentList = [ - '--crop', - '--mode', - '2', - 'inject-rpu', - '--rpu-in', - Flow.TempPath + '/original.rpu', - '--input', - Flow.TempPath + '/converted_video.hevc', - '--output', - Flow.TempPath + '/fixed.hevc' - ] + "--crop", + "--mode", + "2", + "inject-rpu", + "--rpu-in", + Flow.TempPath + "/original.rpu", + "--input", + Flow.TempPath + "/converted_video.hevc", + "--output", + Flow.TempPath + "/fixed.hevc", + ]; if (RemoveHDRTenPlus) { - executeArgs.argumentList = ['--drop-hdr10plus'].concat(executeArgs.argumentList); + executeArgs.argumentList = ["--drop-hdr10plus"].concat( + executeArgs.argumentList + ); } if (!Flow.IsWindows) { let args = executeArgs.argumentList.join(" "); - executeArgs.argumentList = ['-qefc', dovi_tool + " " + args, '/dev/null']; - executeArgs.command = 'script'; + executeArgs.argumentList = ["-qefc", dovi_tool + " " + args, "/dev/null"]; + executeArgs.command = "script"; } executeArgs.add_Output((line) => { @@ -177,26 +187,24 @@ function Script(RemoveHDRTenPlus) { Flow.PartPercentageUpdate(matches[1]); } else { Flow.PartPercentageUpdate(0); - Flow.AdditionalInfoRecorder('DoVi', line.replace(/\[2K/, ''), 1); + Flow.AdditionalInfoRecorder("DoVi", line.replace(/\[2K/, ""), 1); } }); process = Flow.Execute(executeArgs); if (process.exitCode !== 0) { - Logger.ELog('Failed to dovi_tool: ' + process.exitCode); + Logger.ELog("Failed to dovi_tool: " + process.exitCode); return -1; } - System.IO.File.Delete(Flow.TempPath + '/converted_video.hevc'); - System.IO.File.Delete(Flow.TempPath + '/original.rpu'); + System.IO.File.Delete(Flow.TempPath + "/converted_video.hevc"); + System.IO.File.Delete(Flow.TempPath + "/original.rpu"); // Check framerate of video process = Flow.Execute({ command: mkvinfo, - argumentList: [ - working - ] + argumentList: [working], }); const regexp = /([\.0-9]+) frames\/fields/i; @@ -205,16 +213,22 @@ function Script(RemoveHDRTenPlus) { executeArgs.command = mkvmerge; executeArgs.argumentList = [ - '-o', Flow.TempPath + '/converted.mkv', - Flow.TempPath + '/fixed.hevc', - '-D', working, - '--track-order', '1:0' + "-o", + Flow.TempPath + "/converted.mkv", + Flow.TempPath + "/fixed.hevc", + "-D", + working, + "--track-order", + "1:0", ]; if (matches) { executeArgs.argumentList = [ - '--default-duration', `0:${matches[1]}fps`, - '--fix-bitstream-timing-information', '0'].concat(executeArgs.argumentList); + "--default-duration", + `0:${matches[1]}fps`, + "--fix-bitstream-timing-information", + "0", + ].concat(executeArgs.argumentList); } executeArgs.add_Output((line) => { @@ -225,16 +239,16 @@ function Script(RemoveHDRTenPlus) { }); Flow.PartPercentageUpdate(0); - Flow.AdditionalInfoRecorder('DoVi', 'Finishing', 1); + Flow.AdditionalInfoRecorder("DoVi", "Finishing", 1); process = Flow.Execute(executeArgs); if (process.exitCode !== 0) { - Logger.ELog('Failed to mux: ' + process.exitCode); + Logger.ELog("Failed to mux: " + process.exitCode); return -1; } - System.IO.File.Delete(Flow.TempPath + '/fixed.hevc'); - Flow.SetWorkingFile(Flow.TempPath + '/converted.mkv'); + System.IO.File.Delete(Flow.TempPath + "/fixed.hevc"); + Flow.SetWorkingFile(Flow.TempPath + "/converted.mkv"); return 1; } @@ -242,29 +256,27 @@ function Script(RemoveHDRTenPlus) { function ToolPath(tool) { if (Flow.IsDocker) { let process = Flow.Execute({ - command: 'which', - argumentList: [ - tool - ] + command: "which", + argumentList: [tool], }); - if (process.exitCode == 0) - return process.output.replace(/\n/, ""); + if (process.exitCode == 0) return process.output.replace(/\n/, ""); - Logger.ELog(`Please install both the MKVToolNix and dovi_tool DockerMods`) + Logger.ELog(`Please install both the MKVToolNix and dovi_tool DockerMods`); return null; } let toolPath = Flow.GetToolPath(tool); - if ((toolPath)) - return toolPath; + if (toolPath) return toolPath; - Logger.ELog(`${tool} cannot be found! Please create a Variable called "${tool}" that points too the correct location, please see ffmpeg as an example`); + Logger.ELog( + `${tool} cannot be found! Please create a Variable called "${tool}" that points too the correct location, please see ffmpeg as an example` + ); } function humanTimeToSeconds(text) { - const parts = text.split(':').map(p => parseFloat(p)); + const parts = text.split(":").map((p) => parseFloat(p)); let time = 0; time += parts.pop(); //s @@ -276,4 +288,4 @@ function humanTimeToSeconds(text) { function ffPercent(duration, text) { Flow.PartPercentageUpdate((100 / duration) * humanTimeToSeconds(text)); -} \ No newline at end of file +}