Esempio n. 1
0
        protected override async Task ExecuteAsync(CommandLineApplication app)
        {
            var selectedIndex = 0;

            if (Verbose)
            {
                _logger.LogInformation($"Searching for subtitles using method '{Method}' with argument '{Search}' for language '{Language}'.");
            }
            var subtitles = await _apiClient.FindSubtitlesAsync(Method, Search, Language);

            if (subtitles.Length == 0)
            {
                OutputExtensions.WriteError($"No subtitles found.");
                return;
            }

            if (!First)
            {
                var consoleList = new ConsoleList("What subtitles do you want to download",
                                                  subtitles.Select(x => x.SubFileName).ToArray());

                selectedIndex = consoleList.ReadResult();
            }

            var selectedSubtitles = subtitles[selectedIndex];
            var outputFilePath    = BuildOutputFilePath(Output, selectedSubtitles.SubFileName);

            if (Verbose)
            {
                OutputExtensions.WriteVerbose($"Downloading: '{selectedSubtitles.MovieName} ({selectedSubtitles.MovieYear})' to '{outputFilePath}'.");
            }
            await _apiClient.DownloadSubtitleAsync(selectedSubtitles, outputFilePath);
        }
Esempio n. 2
0
        public static async Task <int> Main(string[] args)
        {
            var config      = new ConfigurationBuilder().AddJsonFile("app.config").Build();
            var hostBuilder = new HostBuilder();

            hostBuilder.ConfigureLogging((context, builder) => { builder.AddConsole(); });

            try
            {
                var api = new OpenSubtitlesClient();
                var openSubtitlesOptions = new OpenSubtitlesOptions();
                config.GetSection(OpenSubtitlesOptions.OpenSubtitles).Bind(openSubtitlesOptions);
                await api.LogInAsync(openSubtitlesOptions.Language,
                                     openSubtitlesOptions.Agent,
                                     openSubtitlesOptions.Username,
                                     openSubtitlesOptions.Password);

                hostBuilder.ConfigureServices(builder => { builder.AddSingleton <OpenSubtitlesClient>(api); });
            }
            catch (Exception ex)
            {
                OutputExtensions.WriteError(ex.Message);
                Environment.Exit(0);
            }

            return(await hostBuilder.RunCommandLineApplicationAsync <Program>(args));
        }
Esempio n. 3
0
        private async Task RenameAsync(string file)
        {
            var f = new FileInfo(file);

            if (Verbose)
            {
                OutputExtensions.WriteVerbose($"Retrieving information about file '{f.Name}'.");
            }

            // Retrieve file information
            var mediaInfo = await _mifactory.CreateAsync(file);

            if (Verbose)
            {
                OutputExtensions.WriteVerbose($"Identified as '{mediaInfo}'.");
            }
            // Generate output file path
            var outputFilePath = _filePathGenerator.Generate(mediaInfo, Output);

            if (Verbose)
            {
                OutputExtensions.WriteVerbose($"New path for file generated '{outputFilePath}'.");
            }
            // Check if direcotry exists if not create
            new FileInfo(outputFilePath).Directory.Create();

            if (File.Exists(outputFilePath) && !Replace)
            {
                OutputExtensions.WriteError("File already exists. Skipping.");
                return;
            }

            OutputExtensions.WriteInfo($"Moving '{f.Name}' to '{outputFilePath}'.");

            // Move file to newly generated path
            File.Move(mediaInfo.FilePath, outputFilePath, Replace);

            // Write new file path
            if (PrintOutput)
            {
                Console.WriteLine(outputFilePath);
            }
        }
Esempio n. 4
0
        protected override async Task ExecuteAsync(CommandLineApplication app)
        {
            _allowedExtensions = Extensions.Split('|').Select(e => $".{e}").ToArray();

            foreach (var file in GetFiles(Input))
            {
                if (Verbose)
                {
                    OutputExtensions.WriteVerbose($"File found '{file}'.");
                }

                try
                {
                    await RenameAsync(file);
                }
                catch (Exception exception)
                {
                    OutputExtensions.WriteError(exception.Message);
                }
            }
        }