Beispiel #1
0
        public AutoAddShow(string hint, string filename)
        {
            InitializeComponent();
            ShowConfiguration  = new ShowConfiguration();
            MovieConfiguration = new MovieConfiguration();
            bool assumeMovie = FinderHelper.IgnoreHint(hint);

            lblFileName.Text = "Filename: " + filename;

            tvCodeFinder = new TheTvdbCodeFinder("")
            {
                Dock = DockStyle.Fill
            };
            movieCodeFinder = new TmdbCodeFinder("")
            {
                Dock = DockStyle.Fill
            };

            (!assumeMovie ? tpTV : tpMovie).Show();

            tvCodeFinder.SetHint(hint);
            movieCodeFinder.SetHint(hint);

            tvCodeFinder.SelectionChanged    += MTCCF_SelectionChanged;
            movieCodeFinder.SelectionChanged += MTCCF_SelectionChanged;

            pnlCF.SuspendLayout();
            pnlCF.Controls.Add(tvCodeFinder);
            pnlCF.ResumeLayout();

            panel1.SuspendLayout();
            panel1.Controls.Add(movieCodeFinder);
            panel1.ResumeLayout();

            ActiveControl = (!assumeMovie ? tvCodeFinder : movieCodeFinder); // set initial focus to the code entry/show finder control

            UpdateDirectoryDropDown(cbDirectory, TVSettings.Instance.LibraryFolders, TVSettings.Instance.DefShowLocation, TVSettings.Instance.DefShowAutoFolders && TVSettings.Instance.DefShowUseDefLocation, tpTV);
            UpdateDirectoryDropDown(cbMovieDirectory, TVSettings.Instance.MovieLibraryFolders, TVSettings.Instance.DefMovieDefaultLocation, true, tpMovie);

            originalHint = hint;
        }
Beispiel #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) + ".";

                //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);
                    }
                }

                //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.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
                {
                    //TODO - Make generic, currently uses TMDB only
                    CachedMovieInfo?foundMovie = TMDB.LocalCache.Instance.GetMovie(refinedHint, null, TVSettings.Instance.TMDBLanguage, 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
                AutoAddMedia askForMatch = new AutoAddMedia(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);
        }