Exemplo n.º 1
0
        private async Task OnExecuteAsync()
        {
            if (version)
            {
                Console.WriteLine(Assembly.GetEntryAssembly().GetCustomAttribute <AssemblyInformationalVersionAttribute>().InformationalVersion);
                Environment.Exit(0);
            }

            Console.WriteLine($"AutoTag v{Assembly.GetEntryAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion}");
            Console.WriteLine("https://jtattersall.net");
            settings = new AutoTagSettings(configPath);

            if (tv)
            {
                settings.config.mode = AutoTagConfig.Modes.TV;
            }
            else if (movie)
            {
                settings.config.mode = AutoTagConfig.Modes.Movie;
            }
            if (noRename)
            {
                settings.config.renameFiles = false;
            }
            if (noTag)
            {
                settings.config.tagFiles = false;
            }
            if (noCoverArt)
            {
                settings.config.addCoverArt = false;
            }
            if (manualMode)
            {
                settings.config.manualMode = true;
            }
            if (!string.IsNullOrEmpty(tvRenamePattern))
            {
                settings.config.tvRenamePattern = tvRenamePattern;
            }
            if (!string.IsNullOrEmpty(movieRenamePattern))
            {
                settings.config.movieRenamePattern = movieRenamePattern;
            }
            if (!string.IsNullOrEmpty(pattern))
            {
                settings.config.parsePattern = pattern;
            }
            if (windowsSafe)
            {
                settings.config.windowsSafe = true;
            }
            if (extendedTagging)
            {
                settings.config.extendedTagging = true;
            }
            if (verbose)
            {
                settings.config.verbose = true;
            }
            if (setDefault)
            {
                settings.Save();
            }

            if (!RemainingArguments.Any())
            {
                Console.Error.WriteLine("No files provided");
                Environment.Exit(1);
            }

            IProcessor processor;

            if (settings.config.mode == AutoTagConfig.Modes.TV)
            {
                processor = new TVProcessor(Keys.TMDBKey);
            }
            else
            {
                processor = new MovieProcessor(Keys.TMDBKey);
            }

            AddFiles(RemainingArguments);

            if (!files.Any())
            {
                Console.Error.WriteLine("No files found");
                Environment.Exit(1);
            }

            files.Sort((x, y) => x.Path.CompareTo(y.Path));

            for (index = 0; index < files.Count; index++)
            {
                success &= await processor.Process(files[index].Path, p => {}, SetStatus, ChooseResult, settings.config);
            }

            Console.ResetColor();

            if (success)
            {
                if (warnings == 0)
                {
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine($"\n\n{(files.Count() > 1 ? $"All {files.Count()} files": "File")} successfully processed.");
                }
                else
                {
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.WriteLine($"\n\n{(files.Count() > 1 ? $"All {files.Count()} files": "File")} successfully processed with {warnings} warning{(warnings > 1 ? "s" : "")}.");
                }
                Console.ResetColor();
                Environment.Exit(0);
            }
            else
            {
                int failedFiles = files.Where(f => !f.Success).Count();

                if (failedFiles < files.Count())
                {
                    if (warnings == 0)
                    {
                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.WriteLine($"\n\n{files.Count() - failedFiles} file{(files.Count() - failedFiles > 1 ? "s" : "")} successfully processed.");
                    }
                    else
                    {
                        Console.ForegroundColor = ConsoleColor.Yellow;
                        Console.WriteLine($"\n\n{files.Count() - failedFiles} file{(files.Count() - failedFiles > 1 ? "s" : "")} successfully processed with {warnings} warning{(warnings > 1 ? "s" : "")}.");
                    }
                    Console.ForegroundColor = ConsoleColor.DarkRed;
                    Console.Error.WriteLine($"Errors encountered for {failedFiles} file{(failedFiles > 1 ? "s" : "")}:");
                }
                else
                {
                    Console.Error.WriteLine("\n\nErrors encountered for all files:");
                }

                foreach (TaggingFile file in files.Where(f => !f.Success))
                {
                    Console.ForegroundColor = ConsoleColor.Magenta;
                    Console.Error.WriteLine($"{file.Path}:");
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.Error.WriteLine($"    {file.Status}\n");
                }

                Console.ResetColor();
                Environment.Exit(1);
            }
        }
Exemplo n.º 2
0
        private async Task OnExecuteAsync()
        {
            if (version)
            {
                Console.WriteLine(Assembly.GetEntryAssembly().GetCustomAttribute <AssemblyInformationalVersionAttribute>().InformationalVersion);
                Environment.Exit(0);
            }

            Console.WriteLine($"AutoTag v{Assembly.GetEntryAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion}");
            Console.WriteLine("https://jtattersall.net");
            settings = new AutoTagSettings(configPath);

            if (tv)
            {
                settings.config.mode = AutoTagConfig.Modes.TV;
            }
            else if (movie)
            {
                settings.config.mode = AutoTagConfig.Modes.Movie;
            }
            if (noRename)
            {
                settings.config.renameFiles = false;
            }
            if (noTag)
            {
                settings.config.tagFiles = false;
            }
            if (noCoverArt)
            {
                settings.config.addCoverArt = false;
            }
            if (manualMode)
            {
                settings.config.manualMode = true;
            }
            if (!string.IsNullOrEmpty(tvRenamePattern))
            {
                settings.config.tvRenamePattern = tvRenamePattern;
            }
            if (!string.IsNullOrEmpty(movieRenamePattern))
            {
                settings.config.movieRenamePattern = movieRenamePattern;
            }
            if (!string.IsNullOrEmpty(pattern))
            {
                settings.config.parsePattern = pattern;
            }
            if (windowsSafe)
            {
                settings.config.windowsSafe = true;
            }
            if (verbose)
            {
                settings.config.verbose = true;
            }
            if (setDefault)
            {
                settings.Save();
            }

            if (RemainingArguments.Length == 0)
            {
                Console.Error.WriteLine("No files provided");
                Environment.Exit(1);
            }

            IProcessor processor;

            if (settings.config.mode == AutoTagConfig.Modes.TV)
            {
                processor = new TVProcessor("TQLC3N5YDI1AQVJF");
            }
            else
            {
                processor = new MovieProcessor("b342b6005f86daf016533bf0b72535bc");
            }

            AddFiles(RemainingArguments);
            files.Sort((x, y) => x.Path.CompareTo(y.Path));

            Action <string> setPath = p => { return; };
            Action <string, MessageType> setStatus = (s, t) => SetStatus(s, t);

            Func <List <Tuple <string, string> >, int> choose = (results) => ChooseResult(results);

            for (index = 0; index < files.Count; index++)
            {
                success = success & await processor.process(files[index].Path, setPath, setStatus, choose, settings.config);
            }

            Console.ResetColor();

            if (success)
            {
                if (warnings == 0)
                {
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine($"\n\n{(files.Count() > 1 ? $"All {files.Count()} files": "File")} successfully processed.");
                }
                else
                {
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.WriteLine($"\n\n{(files.Count() > 1 ? $"All {files.Count()} files": "File")} successfully processed with {warnings} warning{(warnings > 1 ? "s" : "")}.");
                }
                Console.ResetColor();
                Environment.Exit(0);
            }
            else
            {
                int failedFiles = files.Where(f => !f.Success).Count();

                if (failedFiles < files.Count())
                {
                    if (warnings == 0)
                    {
                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.WriteLine($"\n\n{files.Count() - failedFiles} file{(files.Count() - failedFiles > 1 ? "s" : "")} successfully processed.");
                    }
                    else
                    {
                        Console.ForegroundColor = ConsoleColor.Yellow;
                        Console.WriteLine($"\n\n{files.Count() - failedFiles} file{(files.Count() - failedFiles > 1 ? "s" : "")} successfully processed with {warnings} warning{(warnings > 1 ? "s" : "")}.");
                    }
                    Console.ForegroundColor = ConsoleColor.DarkRed;
                    Console.Error.WriteLine($"Errors encountered for {failedFiles} file{(failedFiles > 1 ? "s" : "")}:");
                }
                else
                {
                    Console.Error.WriteLine("\n\nErrors encountered for all files:");
                }

                foreach (TaggingFile file in files.Where(f => !f.Success))
                {
                    Console.ForegroundColor = ConsoleColor.Magenta;
                    Console.Error.WriteLine($"{file.Path}:");
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.Error.WriteLine($"    {file.Status}\n");
                }

                Console.ResetColor();
                Environment.Exit(1);
            }
        }