Esempio n. 1
0
        protected override void ProcessRecord()
        {
            if (!Url.IsValidUrl())
            {
                WriteVerbose($"The given url: \"{Url}\" is not valid.");
                return;
            }

            var client = new YoutubeDL {
                VideoUrl = Url
            };

            if (!string.IsNullOrWhiteSpace(ConfigurationFile))
            {
                var resolvedPath = this.ResolvePaths(false, ConfigurationFile).SingleOrDefault()
                                   ?? throw new ArgumentException(
                                             "Cannot find the configuration file at the given path.",
                                             nameof(ConfigurationFile));

                WriteVerbose($"Using \"{resolvedPath}\"");
                client.Options = Options.Deserialize(File.ReadAllText(resolvedPath));
            }
            else if (!string.IsNullOrWhiteSpace(ConfigurationJson))
            {
                WriteVerbose("Using json configuration");
                client.Options = Options.Deserialize(ConfigurationJson);
            }
            else
            {
                WriteVerbose("Using default media options");
                var includeThumbnail = !(NoThumbnail.IsPresent && NoThumbnail.ToBool());
                client.ApplyDefaultMediaOptions(includeThumbnail);
            }

            WriteVerbose("Executing Youtubedl using the following parameters:");
            WriteVerbose(client.Options.ToCliParameters());

            if (MyInvocation.BoundParameters.ContainsKey("Verbose"))
            {
                client.StandardOutputEvent += (sender, output) => WriteLineExternal(output, ConsoleColor.Yellow);
            }

            client.StandardErrorEvent += (sender, errorOutput) => WriteLineExternal(errorOutput, ConsoleColor.Red);
            client.Download();
        }