private void ProcessStmtFile(string path) { XmlDocument _xml = new XmlDocument(); if (File.Exists(path)) { _xml.Load(path); //Receive Files //Download Files XmlNodeList _lstFiles = _xml.SelectNodes("/rules/files/file"); foreach (XmlNode node in _lstFiles) { string action = XMLHelper.GetAttributeValue(node, "action"); if (action == "receive") { } if (action == "upload") { } } //Execute Statement XmlNodeList _lstCmds = _xml.SelectNodes("/rules/commands/command"); foreach (XmlNode node in _lstCmds) { string text = XMLHelper.GetAttributeValue(node, "text"); if (!String.IsNullOrEmpty(text)) { //TODO: Analize the result of the execution ShellHelper.Execute(text); } } } }
public static YoutubeAudioResponse DownloadAudio(string vid) { var fileName = GetAudioFilename(vid); var result = new YoutubeAudioResponse(); if (File.Exists(fileName)) { result.AudioFileFullPath = fileName; return(result); } var userPassParams = string.IsNullOrWhiteSpace(Youtube_User) ? "" : @$ "-u " "{Youtube_User}" " -p " "{Youtube_Pass}" ""; var cmd = @$ "youtube-dl -f bestaudio --no-playlist {userPassParams} -o " "{fileName}" " --no-check-certificate " "https://youtu.be/{vid}" ""; var shellResult = ShellHelper.Execute(cmd); if (shellResult.ExitCode != 0) { throw new Exception($"youtube-dl audio exited with code {shellResult.ExitCode}.\n{shellResult.Output}"); } if (!File.Exists(fileName)) { throw new Exception($"Video filename {fileName} not found after youtube-dl"); } result.AudioFileFullPath = fileName; return(result); }
public static YoutubeVideoResponse DownloadVideo(string vid, bool includeSubtitles) { var result = new YoutubeVideoResponse(); var fileName = GetVideoFilename(vid); if (File.Exists(fileName)) { result.VideoFileFullPath = fileName; return(result); } var userPassParams = string.IsNullOrWhiteSpace(Youtube_User) ? "" : @$ "-u " "{Youtube_User}" " -p " "{Youtube_Pass}" " "; var embedSubs = includeSubtitles ? "--write-sub --embed-subs " : ""; var cmd = @$ "youtube-dl -f " "bestvideo[height<=720][ext=mp4]" " --max-filesize 100M {userPassParams}-o " "{fileName}" " {embedSubs}--no-check-certificate " "https://youtu.be/{vid}" ""; var shellResult = ShellHelper.Execute(cmd); if (shellResult.ExitCode != 0) { throw new Exception($"youtube-dl video exited with code {shellResult.ExitCode}.\n{shellResult.Output}"); } if (!File.Exists(fileName)) { throw new Exception($"Audio filename {fileName} not found after youtube-dl"); } result.VideoFileFullPath = fileName; return(result); }
public SplitProcessResult Split(string inputFile, string outputFolder, string format, bool includeHighFreq, bool isBatch = false) { if (format == "karaoke" || format == "vocals") { format = "2stems"; } string cmd; string formatParam; if (includeHighFreq) { formatParam = $"-p alt-config/{format}/base_config_hf.json"; } else { formatParam = $"-p spleeter:{format}"; } var maxDurationParam = Max_Duration == "" ? "" : $"--duration {Max_Duration}"; var inputParam = "-i " + (isBatch ? inputFile : $"\"{inputFile}\""); cmd = $"python -m spleeter separate {inputParam} -o \"{outputFolder}\" {maxDurationParam} {formatParam} -c mp3"; var result = ShellHelper.Execute(cmd); return(new SplitProcessResult() { ErrorCount = 0, ExitCode = result.ExitCode, Output = result.Output }); }
private void App_PhaseEvent(object sender, PhaseEventArgs e) { if (!File.Exists(_scriptHook)) { return; } var ret = ShellHelper.Execute(_scriptHook, true, new Dictionary <string, string>(e.Environments) { { "CV4PVE_AUTOSNAP_DEBUG", _debug ? "1" :"0" }, { "CV4PVE_AUTOSNAP_DRY_RUN", _dryRun ? "1" :"0" }, }, _out, _dryRun, _debug); if (ret.ExitCode != 0) { _out.WriteLine($"Script return code: {ret.ExitCode}"); } if (!string.IsNullOrWhiteSpace(ret.StandardOutput)) { _out.Write(ret.StandardOutput); } }
private void MakeOutput(string originalAudioFile, string outputFilePath, string splitOutputFolder, YoutubeProcessRequest request) { if (File.Exists(outputFilePath)) { File.Delete(outputFilePath); } Directory.CreateDirectory(Path.GetDirectoryName(outputFilePath)); var stemFiles = Directory.GetFiles(splitOutputFolder, "*.mp3", SearchOption.AllDirectories) .Select(sf => new StemFileInfo { FileName = Path.GetFileName(sf), FileNameWithoutExtension = Path.GetFileNameWithoutExtension(sf), FilePath = sf }) .ToList(); if (request.Extension == ".mp4") { // Video var video = YoutubeHelper.DownloadVideo(request.Vid, true); string audioFilepath; if (request.SubFormats != null && request.SubFormats.Count == 1) { // Single audio file for the video audioFilepath = stemFiles.FirstOrDefault(sf => sf.FileNameWithoutExtension == request.SubFormats[0])?.FilePath; } else { // Multiple audio files for the video audioFilepath = outputFilePath.Replace(".mp4", ".mp3"); MergeMp3(audioFilepath, stemFiles.Where(sf => request.SubFormats.Contains(sf.FileNameWithoutExtension))); } if (audioFilepath != null) { var cmd = $"ffmpeg -y -i \"{video.VideoFileFullPath}\" -i \"{audioFilepath}\" -c:v copy -c:s mov_text -map 0:v:0 -map 1:a:0 -map 0:s:0? \"{outputFilePath}\""; var shellResult = ShellHelper.Execute(cmd); if (shellResult.ExitCode != 0) { throw new Exception(shellResult.Output); } } } else if (request.Extension == ".mp3") { // Return a single stem mp3 or merge multiple mp3s MakeMp3(outputFilePath, request, stemFiles); } else if (request.Extension == ".zip") { // ZIP multiple MP3s MakeZip(originalAudioFile, outputFilePath, request, stemFiles); } }
public static YoutubeVideoInfo GetVideoInfo(string vid) { if (_videoInfoCache.TryGetValue(vid, out YoutubeVideoInfo cachedInfo)) { return(cachedInfo); } var cmd = @$ "youtube-dl -s --get-filename --get-duration --no-check-certificate " "https://youtu.be/{vid}" ""; var shellResult = ShellHelper.Execute(cmd); if (shellResult.ExitCode != 0) { throw new Exception($"youtube-dl -s exited with code {shellResult.ExitCode}.\n{shellResult.Output}"); } var dataArray = shellResult.Output.ToString().Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries); if (dataArray.Length < 2) { throw new Exception($"youtube-dl -s returned unformatted data {shellResult.ExitCode}.\n{shellResult.Output}"); } var info = new YoutubeVideoInfo() { Filename = dataArray[0].Trim(), Duration = dataArray[1] }; if (info.Filename.Contains('.')) { info.Filename = ShellHelper.SanitizeFilename(info.Filename.Substring(0, info.Filename.LastIndexOf('.'))); } var dur = info.Duration.Split(':'); if (dur.Length == 1) { info.DurationSeconds = int.Parse(dur[0]); } else if (dur.Length == 2) { info.DurationSeconds = int.Parse(dur[0]) * 60 + int.Parse(dur[1]); } else if (dur.Length == 3) { info.DurationSeconds = int.Parse(dur[0]) * 3600 + int.Parse(dur[1]) * 60 + int.Parse(dur[2]); } _videoInfoCache[vid] = info; return(info); }
private void MergeMp3(string outputFilePath, IEnumerable <StemFileInfo> stemFilesToMerge) { if (File.Exists(outputFilePath)) { _logger.LogInformation("Merged mp3 cache hit"); return; } var inputParams = stemFilesToMerge .Select(sf => $"-i \"{sf.FilePath}\"") .ToList(); var mergeCmd = $"ffmpeg -y {string.Join(' ', inputParams)} -filter_complex \"[0:0][1:0] amix=inputs={inputParams.Count}:duration=longest\" \"{outputFilePath}\""; var shellResult = ShellHelper.Execute(mergeCmd); if (shellResult.ExitCode != 0) { throw new Exception(shellResult.Output); } }
public static string DownloadAudioMp3(string vid) { var filePathTemplate = $"{Output_Root}/yt/{vid}.%(ext)s"; var cmd = $@"youtube-dl -f bestaudio --max-filesize 100M --extract-audio --audio-format mp3 --audio-quality 0 --no-check-certificate -o ""{filePathTemplate}"" ""https://youtu.be/{vid}"""; var shellResult = ShellHelper.Execute(cmd); if (shellResult.ExitCode != 0) { throw new Exception($"youtube-dl audio exited with code {shellResult.ExitCode}.\n{shellResult.Output}"); } var outputFilePath = $"{Output_Root}/yt/{vid}.mp3"; if (!File.Exists(outputFilePath)) { throw new Exception($"Audio filename {outputFilePath} not found after youtube-dl"); } return(outputFilePath); }
private void App_PhaseEvent(object sender, PhaseEventArgs e) { if (!File.Exists(_scriptHook)) { return; } var ret = ShellHelper.Execute(_scriptHook, true, new Dictionary <string, string> { { "CV4PVE_AUTOSNAP_PHASE", e.Phase }, { "CV4PVE_AUTOSNAP_VMID", e.VM?.Id + "" }, { "CV4PVE_AUTOSNAP_VMNAME", e.VM?.Name }, { "CV4PVE_AUTOSNAP_VMTYPE", e.VM?.Type + "" }, { "CV4PVE_AUTOSNAP_LABEL", e.Label }, { "CV4PVE_AUTOSNAP_KEEP", e.Keep + "" }, { "CV4PVE_AUTOSNAP_SNAP_NAME", e.SnapName }, { "CV4PVE_AUTOSNAP_VMSTATE", e.State ? "1" :"0" }, { "CV4PVE_AUTOSNAP_DEBUG", _debug ? "1" :"0" }, { "CV4PVE_AUTOSNAP_DRY_RUN", _dryRun ? "1" :"0" }, }, _stdOut, _dryRun, _debug); if (ret.ExitCode != 0) { _stdOut.WriteLine($"Script return code: {ret.ExitCode}"); } if (!string.IsNullOrWhiteSpace(ret.StandardOutput)) { _stdOut.Write(ret.StandardOutput); } }
public async Task UpdateGitAsync() { var result = ShellHelper.Execute("git pull", _ciSettings.Value.SolutionPath); _logger.LogInformation("GIT pull result: " + result); }
public async Task DockerPushAsync() { var result = ShellHelper.Execute("docker push", _ciSettings.Value.SolutionPath); _logger.LogInformation("docker run result: " + result); }
public async Task DockerBuildAsync() { var result = ShellHelper.Execute("docker build", _ciSettings.Value.SolutionPath); _logger.LogInformation("docker build result: " + result); }