示例#1
0
        public static List <ShowItem> FindShows([NotNull] List <string> possibleShowNames, TVDoc doc)
        {
            List <ShowItem> addedShows = new List <ShowItem>();

            foreach (string hint in possibleShowNames)
            {
                //if hint doesn't match existing added shows
                if (LookForSeries(hint, addedShows))
                {
                    Logger.Info($"Ignoring {hint} as it matches existing shows.");
                    continue;
                }

                //If the hint contains certain terms then we'll ignore it
                if (IgnoreHint(hint))
                {
                    Logger.Info($"Ignoring {hint} as it is in the ignore list (from Settings).");
                    continue;
                }

                //If the hint contains certain terms then we'll ignore it
                if (TVSettings.Instance.IgnoredAutoAddHints.Contains(hint))
                {
                    Logger.Info(
                        $"Ignoring {hint} as it is in the list of ignored terms the user has selected to ignore from prior Auto Adds.");

                    continue;
                }

                //Remove any (nnnn) in the hint - probably a year
                string refinedHint = Regex.Replace(hint, @"\(\d{4}\)", "");

                //Remove anything we can from hint to make it cleaner and hence more likely to match
                refinedHint = RemoveSeriesEpisodeIndicators(refinedHint, doc.Library.SeasonWords());

                if (string.IsNullOrWhiteSpace(refinedHint))
                {
                    Logger.Info($"Ignoring {hint} as it refines to nothing.");
                    continue;
                }

                //If there are no LibraryFolders then we cant use the simplified UI
                if (TVSettings.Instance.LibraryFolders.Count == 0)
                {
                    MessageBox.Show(
                        "Please add some monitor (library) folders under 'Bulk Add Shows' to use the 'Auto Add' functionity (Alternatively you can add them or turn it off in settings).",
                        "Can't Auto Add Show", MessageBoxButtons.OK, MessageBoxIcon.Error);

                    continue;
                }

                Logger.Info("****************");
                Logger.Info("Auto Adding New Show");

                //popup dialog
                AutoAddShow askForMatch = new AutoAddShow(refinedHint);

                DialogResult dr = askForMatch.ShowDialog();
                if (dr == DialogResult.OK)
                {
                    //If added add show to collection
                    addedShows.Add(askForMatch.ShowItem);
                }
                else if (dr == DialogResult.Abort)
                {
                    Logger.Info("Skippng Auto Add Process");
                    break;
                }
                else if (dr == DialogResult.Ignore)
                {
                    Logger.Info($"Permenantly Ignoring 'Auto Add' for: {hint}");
                    TVSettings.Instance.IgnoredAutoAddHints.Add(hint);
                }
                else
                {
                    Logger.Info($"Cancelled Auto adding new show {hint}");
                }
            }

            return(addedShows);
        }
示例#2
0
        public static List <MediaConfiguration> FindMedia([NotNull] IEnumerable <FileInfo> possibleShows, TVDoc doc, IDialogParent owner)
        {
            List <MediaConfiguration> addedShows = new List <MediaConfiguration>();

            foreach (FileInfo file in possibleShows)
            {
                string hint = file.RemoveExtension(TVSettings.Instance.UseFullPathNameToMatchSearchFolders) + ".";

                //If the hint contains certain terms then we'll ignore it
                if (TVSettings.Instance.IgnoredAutoAddHints.Contains(hint))
                {
                    Logger.Info(
                        $"Ignoring {hint} as it is in the list of ignored terms the user has selected to ignore from prior Auto Adds.");

                    continue;
                }
                //remove any search folders  from the hint. They are probbably useless at helping specify the showname
                foreach (var path in TVSettings.Instance.DownloadFolders)
                {
                    if (hint.StartsWith(path, StringComparison.OrdinalIgnoreCase))
                    {
                        hint = hint.RemoveFirst(path.Length);
                    }
                }

                //Remove any (nnnn) in the hint - probably a year
                string refinedHint = Regex.Replace(hint, @"\(\d{4}\)", "");

                //Remove anything we can from hint to make it cleaner and hence more likely to match
                refinedHint = RemoveSeriesEpisodeIndicators(refinedHint, doc.TvLibrary.SeasonWords());

                if (string.IsNullOrWhiteSpace(refinedHint))
                {
                    Logger.Info($"Ignoring {hint} as it refines to nothing.");
                    continue;
                }

                //if hint doesn't match existing added shows
                if (LookForSeries(refinedHint, addedShows))
                {
                    Logger.Info($"Ignoring {hint} as it matches shows already being added.");
                    continue;
                }
                if (LookForMovies(refinedHint, addedShows))
                {
                    Logger.Info($"Ignoring {hint} as it matches existing movies already being added: {addedShows.Where(si => si.NameMatch(refinedHint)).Select(s => s.ShowName).ToCsv()}");
                    continue;
                }

                //if hint doesn't match existing added shows
                if (LookForSeries(refinedHint, doc.TvLibrary.Shows))
                {
                    Logger.Info($"Ignoring {hint} as it matches shows already in the library.");
                    continue;
                }
                if (LookForMovies(refinedHint, doc.FilmLibrary.Movies))
                {
                    Logger.Info($"Ignoring {hint} as it matches existing movies already in the library: {doc.FilmLibrary.Movies.Where(si => si.NameMatch(refinedHint)).Select(s=>s.ShowName).ToCsv()}");
                    continue;
                }

                //If there are no LibraryFolders then we cant use the simplified UI
                if (TVSettings.Instance.LibraryFolders.Count + TVSettings.Instance.MovieLibraryFolders.Count == 0)
                {
                    MessageBox.Show(
                        "Please add some monitor (library) folders under 'Bulk Add Shows' to use the 'Auto Add' functionality (Alternatively you can add them or turn it off in settings).",
                        "Can't Auto Add Show", MessageBoxButtons.OK, MessageBoxIcon.Error);

                    continue;
                }

                bool assumeMovie = FinderHelper.IgnoreHint(hint) || !file.FileNameNoExt().ContainsAnyCharactersFrom("0123456789");

                if (assumeMovie && TVSettings.Instance.DefMovieDefaultLocation.HasValue() && TVSettings.Instance.DefMovieUseDefaultLocation && true)//todo use  TVSettings.Instance.AutomateAutoAddWhenOneMovieFound
                {
                    var foundMovie = LocalCache.Instance.GetMovie(refinedHint, null, true, true);
                    if (foundMovie != null)
                    {
                        // no need to popup dialog
                        Logger.Info($"Auto Adding New Movie for '{refinedHint}' (directly) : {foundMovie.Name}");

                        MovieConfiguration newMovie = new MovieConfiguration();
                        newMovie.TmdbCode            = foundMovie.TmdbCode;
                        newMovie.UseAutomaticFolders = true;
                        newMovie.AutomaticFolderRoot = TVSettings.Instance.DefMovieDefaultLocation;
                        newMovie.Format = MovieConfiguration.MovieFolderFormat.singleDirectorySingleFile;
                        newMovie.UseCustomFolderNameFormat = false;
                        newMovie.ConfigurationProvider     = TVDoc.ProviderType.TMDB;

                        if (!hint.Contains(foundMovie?.Name ?? string.Empty, StringComparison.OrdinalIgnoreCase))
                        {
                            newMovie.AliasNames.Add(hint);
                        }


                        addedShows.Add(newMovie);
                        doc.Stats().AutoAddedMovies++;
                        continue;
                    }
                }
                //popup dialog
                AutoAddShow askForMatch = new AutoAddShow(refinedHint, file, assumeMovie);

                if (askForMatch.SingleTvShowFound && !askForMatch.SingleMovieFound && true) //todo use  TVSettings.Instance.AutomateAutoAddWhenOneShowFound
                {
                    // no need to popup dialog
                    Logger.Info($"Auto Adding New Show for '{refinedHint}' : {askForMatch.ShowConfiguration.CachedShow.Name}");
                    addedShows.Add(askForMatch.ShowConfiguration);
                    doc.Stats().AutoAddedShows++;
                }
                else if (askForMatch.SingleMovieFound && !askForMatch.SingleTvShowFound && true) //todo use  TVSettings.Instance.AutomateAutoAddWhenOneMovieFound
                {
                    // no need to popup dialog
                    Logger.Info($"Auto Adding New Movie for '{refinedHint}' : {askForMatch.MovieConfiguration.CachedMovie.Name}");
                    addedShows.Add(askForMatch.MovieConfiguration);
                    doc.Stats().AutoAddedMovies++;
                }
                else
                {
                    Logger.Info($"Auto Adding New Show/Movie by asking about for '{refinedHint}'");
                    owner.ShowChildDialog(askForMatch);
                    DialogResult dr = askForMatch.DialogResult;

                    if (dr == DialogResult.OK)
                    {
                        //If added add show ot collection
                        if (askForMatch.ShowConfiguration.Code > 0)
                        {
                            addedShows.Add(askForMatch.ShowConfiguration);
                            doc.Stats().AutoAddedShows++;
                        }
                        else if (askForMatch.MovieConfiguration.Code > 0)
                        {
                            addedShows.Add(askForMatch.MovieConfiguration);
                            doc.Stats().AutoAddedMovies++;
                        }
                    }
                    else if (dr == DialogResult.Abort)
                    {
                        Logger.Info("Skippng Auto Add Process");
                        break;
                    }
                    else if (dr == DialogResult.Ignore)
                    {
                        Logger.Info($"Permenantly Ignoring 'Auto Add' for: {hint}");
                        TVSettings.Instance.IgnoredAutoAddHints.Add(hint);
                    }
                    else
                    {
                        Logger.Info($"Cancelled Auto adding new show/movie {hint}");
                    }
                }

                askForMatch.Dispose();
            }

            return(addedShows);
        }