Пример #1
0
    private static void SetupProgram()
    {
        try
        {
            var config = SetupConfig();
            _defaultOutputFormat = config.GetValue <string>("defaultOutputFormat").ToLower();
            _defaultOutputDir    = config.GetValue <string>("defaultOutputDir");

            if (!Directory.Exists(_defaultOutputDir))
            {
                var path = Path.Join(Environment.CurrentDirectory, "Output");
                Directory.CreateDirectory(path);
                _defaultOutputDir = path;
            }

            if (String.IsNullOrEmpty(_defaultOutputFormat) ||
                !VideoFormat.IsSupportedVideoFormat(_defaultOutputFormat))
            {
                _defaultOutputFormat = VideoFormat.Mp4;
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine($"Error in config. {ex.Message}");
            Console.WriteLine("Press any key to quit");
            Console.ReadKey();
            Environment.Exit((int)ExitCode.Error);
        }
    }
Пример #2
0
    private static ExitCode HandleOptions(Options options)
    {
        if (options.OutputFormat is not null)
        {
            if (!VideoFormat.IsSupportedVideoFormat(options.OutputFormat))
            {
                Console.WriteLine($"Output format is not supported.");
                return(ExitCode.Error);
            }

            _outputFormat = options.OutputFormat;
        }

        if (!String.IsNullOrEmpty(options.InputFile))
        {
            bool validUrl = false;
            if (options.InputFile.StartsWith("http"))
            {
                validUrl = Utility.IsValidUrl(options.InputFile);
                if (!validUrl)
                {
                    Console.WriteLine("Input uri not well formed.");
                    return(ExitCode.Error);
                }
            }

            if (!validUrl && !File.Exists(options.InputFile))
            {
                Console.WriteLine("Input file does not exist.");
                return(ExitCode.Error);
            }

            var inputFormat = Path.GetExtension(options.InputFile).Replace(".", "");
            if (inputFormat.Equals(_outputFormat))
            {
                Console.WriteLine("Output and input formats are the same.");
                return(ExitCode.Error);
            }

            _inputFile = options.InputFile;
        }

        if (options.OutputPath is not null)
        {
            _outputDir = options.OutputPath;
        }

        return(ExitCode.OK);
    }
Пример #3
0
 public void TestSupportedVideoFormat(string format, bool isSupported)
 {
     Assert.Equal(isSupported, VideoFormat.IsSupportedVideoFormat(format));
 }