Exemplo n.º 1
0
 private static void ProcessOutputLine(string type, string line, SplitProcessResult status)
 {
     Startup.EphemeralLog($"[spleeter] {type}: {line}", false);
     if (type == "stderr" && ErrorRegex.IsMatch(line))
     {
         status.ErrorCount++;
         status.Errors.Add(line);
     }
     else if (FileWrittenRegex.IsMatch(line))
     {
         status.FileWrittenCount++;
     }
 }
Exemplo n.º 2
0
        // V2
        public SplitProcessResult Split(string inputFile, YoutubeProcessRequest request, string outputFolder, bool isBatch = false)
        {
            var output  = new StringBuilder();
            var status  = new SplitProcessResult();
            var process = new Process
            {
                StartInfo = new ProcessStartInfo
                {
                    FileName = @"cmd.exe",
                    RedirectStandardInput  = true,
                    UseShellExecute        = false,
                    RedirectStandardOutput = true,
                    RedirectStandardError  = true,
                    CreateNoWindow         = true
                },
                EnableRaisingEvents = true
            };

            process.ErrorDataReceived += new DataReceivedEventHandler(delegate(object sender, DataReceivedEventArgs e)
            {
                if (!string.IsNullOrEmpty(e.Data))
                {
                    ProcessOutputLine("stderr", e.Data, status);
                }
            });
            process.OutputDataReceived += new DataReceivedEventHandler(delegate(object sender, DataReceivedEventArgs e)
            {
                if (!string.IsNullOrEmpty(e.Data))
                {
                    ProcessOutputLine("stdout", e.Data, status);
                }
            });
            process.Start();
            process.BeginOutputReadLine();
            process.BeginErrorReadLine();

            var    maxDurationParam = Max_Duration == "" ? "" : $"--duration {Max_Duration}";
            string formatParam;

            if (request.Options.IncludeHighFrequencies)
            {
                //formatParam = $"-p alt-config/{request.BaseFormat}/base_config_hf.json";
                formatParam = $"-p spleeter:{request.BaseFormat}-16kHz";
            }
            else
            {
                formatParam = $"-p spleeter:{request.BaseFormat}";
            }
            var inputParam      = isBatch ? inputFile : $"\"{inputFile}\"";
            var separateCommand = @$ "spleeter separate -o " "{outputFolder}" " {maxDurationParam} {formatParam} -c mp3 {inputParam}";

            using (var sw = process.StandardInput)
            {
                if (sw.BaseStream.CanWrite)
                {
                    sw.WriteLine(Anaconda_Activate_Script);
                    sw.WriteLine(separateCommand);
                    sw.WriteLine("conda deactivate");
                }
            }

            WaitOrKill(process, 15, separateCommand);

            status.ExitCode = process.ExitCode != 0 ? process.ExitCode : status.FileWrittenCount == 0 ? -1 : 0;
            return(status);
        }