Beispiel #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);
        }
Beispiel #2
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);
            }
        }
Beispiel #3
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);
                }
            }
        }