Beispiel #1
0
        public Task <Result <MediaLocation> > HandleVideoDownloadRequest(MediaDownloadJob job)
        {
            if (!Uri.TryCreate(job.DownloadLink, UriKind.Absolute, out _))
            {
                return(Task.FromResult(Result.Failure <MediaLocation>("The URL is not valid")));
            }

            var commandlineArguments = new List <string> {
                $"\"{job.DownloadLink}\"",
                "-c",
                "-i",
                "-w",
                "--no-part",
                "--no-call-home",
                $"-o \"{_vidloadConfiguration.FilesystemConfiguration.DownloadDirectory}/{job.TraceId}.%(ext)s\"",
            };

            if (_vidloadConfiguration.NetworkConfiguration.UseProxy)
            {
                commandlineArguments.Add($"--proxy \"{_vidloadConfiguration.NetworkConfiguration.Proxy}\"");
            }


            if (FormatSpecifier.IsAudioFormat(job.TargetFormat))
            {
                commandlineArguments.Add("--extract-audio");
                commandlineArguments.Add($"--audio-format {job.TargetFormat.ToString().ToLower()}");
                commandlineArguments.Add("-f \"bestaudio\"");
            }

            if (FormatSpecifier.IsVideoFormat(job.TargetFormat))
            {
                commandlineArguments.Add("-f \"bestvideo\"");
                commandlineArguments.Add($"--recode-video {job.TargetFormat.ToString().ToLower()}");
            }

            var downloadResult = _shellCommandExecutor
                                 .Execute("youtube-dl", commandlineArguments, TimeSpan.FromHours(1));

            if (downloadResult.IsSuccess)
            {
                var fileName = $"{job.TraceId}.{FormatSpecifier.GetFileExtensionsForFormat(job.TargetFormat)}";
                var filePath = Path.Join(_vidloadConfiguration.FilesystemConfiguration.DownloadDirectory, fileName);

                return(Task.FromResult(File.Exists(filePath)
          ? Result.Success(new MediaLocation {
                    FilePath = filePath, TraceId = job.TraceId, DownloadLink = job.DownloadLink
                })
          : Result.Failure <MediaLocation>("Could not post-process the video. Output File not found")));
            }

            return(Task.FromResult(Result.Failure <MediaLocation>("WHOOOP")));
        }
Beispiel #2
0
        public DriverVersion GetDriverVersion()
        {
            var driverVersionString = _shellCommandExecutor.Execute(_directoryWithDriver.FullName, "chromedriver.exe", "--version");
            var driverVersion       = DriverVersion.ParseCommandLineVersionString(driverVersionString);

            return(driverVersion);
        }