Exemple #1
0
        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();
            });
        }
Exemple #2
0
        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);
        }
Exemple #3
0
        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);
        }
Exemple #4
0
        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);
        }