private async Task DownloadYoutubeDl(Payloads.Download download, string fullPath) { var process = new Process(); process.StartInfo.UseShellExecute = false; process.StartInfo.FileName = "youtube-dl"; process.StartInfo.Arguments = GetYoutubeDlArguments(download.Url, fullPath); process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardError = true; process.StartInfo.RedirectStandardInput = true; process.Start(); // TODO: not the best approach research for a better solution. await Task.Run(() => { process.WaitForExit(); if (process.ExitCode != 0) { var errorMessage = process.StandardError.ReadToEnd(); process.Dispose(); throw new Exception($"Process failed: {errorMessage}"); } process.Dispose(); }); }
private bool CreatAndGetFullPath(Payloads.Download data, out string fullPath) { fullPath = Path.Join(_environment.WebRootPath, data.Path); if (File.Exists(fullPath)) { return(true); } var directoryName = Path.GetDirectoryName(fullPath); Directory.CreateDirectory(directoryName); return(false); }
public async Task downloadHttp(Payloads.Download download) { if (CreatAndGetFullPath(download, out var fullPath)) { return; } var httpClient = _httpClientFactory.CreateClient(); var response = await httpClient.GetAsync(download.Url); var bytes = await response.Content.ReadAsByteArrayAsync(); await File.WriteAllBytesAsync(fullPath, bytes); }
public async Task downloadProcess(Payloads.Download download) { if (CreatAndGetFullPath(download, out var fullPath)) { return; } var ext = GetExt(download.Url); if (ext == ".webm") { await DownloadYoutubeDl(download, fullPath); return; } var path = $"/tmp/{Guid.NewGuid().ToString()}{ext}"; await DownloadYoutubeDl(download, path); await ConvertToWebm(path, fullPath); File.Delete(path); }