Esempio n. 1
0
        public FolderMonitorEdit([NotNull] PossibleNewTvShow hint)
        {
            InitializeComponent();

            codeFinderControl = new CombinedCodeFinder("", MediaConfiguration.MediaType.tv, TVDoc.ProviderType.TheTVDB)
            {
                Dock = DockStyle.Fill
            };
            codeFinderControl.SelectionChanged      += CodeChanged;
            codeFinderControl.lvMatches.DoubleClick += MatchDoubleClick;

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

            if (hint.CodeKnown)
            {
                codeFinderControl.SetHint(hint.TVDBCode.ToString());
            }
            else
            {
                string s = hint.Folder.FullName;
                int    p = s.LastIndexOf(System.IO.Path.DirectorySeparatorChar);
                codeFinderControl.SetHint(string.IsNullOrWhiteSpace(hint.RefinedHint)
                    ? s.Substring(p + 1)
                    : hint.RefinedHint);
            }
            Code = -1;
        }
        private static string GuessShowName([NotNull] PossibleNewTvShow ai, [NotNull] ShowLibrary library)
        {
            // see if we can guess a season number and show name, too
            // Assume is blah\blah\blah\show\season X
            string showName = ai.Folder.FullName;

            foreach (string seasonWord in library.SeasonWords())
            {
                string seasonFinder = ".*" + seasonWord + "[ _\\.]+([0-9]+).*";
                if (Regex.Matches(showName, seasonFinder, RegexOptions.IgnoreCase).Count == 0)
                {
                    continue;
                }

                try
                {
                    // remove season folder from end of the path
                    showName = Regex.Replace(showName, "(.*)\\\\" + seasonFinder, "$1", RegexOptions.IgnoreCase);
                    break;
                }
                catch (ArgumentException)
                {
                    //Ignore this Exception
                }
            }

            // assume last folder element is the show name
            showName = showName.Substring(showName.LastIndexOf(Path.DirectorySeparatorChar.ToString(),
                                                               StringComparison.Ordinal) + 1);

            return(showName);
        }
        private void AskUserAboutShow([NotNull] PossibleNewTvShow folder, IDialogParent owner)
        {
            if (folder.CodeKnown)
            {
                return;
            }

            BulkAddSeriesManager.GuessShowItem(folder, MDoc.TvLibrary, true);

            if (folder.CodeKnown)
            {
                return;
            }

            BulkAddEditShow ed = new BulkAddEditShow(folder);

            owner.ShowChildDialog(ed);
            DialogResult x    = ed.DialogResult;
            int          code = ed.Code;

            ed.Dispose();

            if (x != DialogResult.OK || code == -1)
            {
                return;
            }

            folder.SetId(code, TVDoc.ProviderType.TheTVDB);
        }
Esempio n. 4
0
        public static void GuessShowItem([NotNull] PossibleNewTvShow ai, [NotNull] ShowLibrary library, bool showErrorMsgBox)
        {
            string languageCode = TVSettings.Instance.DefaultProvider == TVDoc.ProviderType.TMDB
                ? TVSettings.Instance.TMDBLanguage
                : TVSettings.Instance.PreferredLanguageCode;

            string showName = GuessShowName(ai, library);
            //todo - (BulkAdd Manager needs to work for new providers)
            int tvdbId = FindTVDBShowCode(ai);

            if (string.IsNullOrEmpty(showName) && tvdbId == -1)
            {
                return;
            }

            if (tvdbId != -1)
            {
                try
                {
                    CachedSeriesInfo cachedSeries = TheTVDB.LocalCache.Instance.GetSeriesAndDownload(tvdbId, showErrorMsgBox);
                    if (cachedSeries != null)
                    {
                        ai.SetId(tvdbId, TVDoc.ProviderType.TheTVDB);
                        return;
                    }
                }
                catch (MediaNotFoundException)
                {
                    //continue to try the next method
                }
            }

            CachedSeriesInfo ser = TheTVDB.LocalCache.Instance.GetSeries(showName, showErrorMsgBox, languageCode);

            if (ser != null)
            {
                ai.SetId(tvdbId, TVDoc.ProviderType.TheTVDB);
                return;
            }

            //Try removing any year
            string showNameNoYear =
                Regex.Replace(showName, @"\(\d{4}\)", "").Trim();

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

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

            ser = TheTVDB.LocalCache.Instance.GetSeries(refinedHint, showErrorMsgBox, languageCode);

            ai.RefinedHint = refinedHint;
            if (ser != null)
            {
                ai.SetId(tvdbId, TVDoc.ProviderType.TheTVDB);
            }
        }
Esempio n. 5
0
        public BulkAddEditShow([NotNull] PossibleNewTvShow hint)
        {
            InitializeComponent();

            codeFinderControl = new CombinedCodeFinder("", MediaConfiguration.MediaType.tv, TVSettings.Instance.DefaultProvider)
            {
                Dock = DockStyle.Fill
            };
            codeFinderControl.SelectionChanged      += CodeChanged;
            codeFinderControl.lvMatches.DoubleClick += MatchDoubleClick;
            label1.Text = $"Search for {TVSettings.Instance.DefaultProvider.PrettyPrint()} entry, by partial name or ID:";

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

            if (hint.CodeKnown)
            {
                codeFinderControl.SetHint(hint.ProviderCode.ToString(), hint.Provider);
            }
            else
            {
                string s = hint.Folder.FullName;
                int    p = s.LastIndexOf(System.IO.Path.DirectorySeparatorChar);
                codeFinderControl.SetHint(string.IsNullOrWhiteSpace(hint.RefinedHint)
                    ? s.Substring(p + 1)
                    : hint.RefinedHint, TVDoc.ProviderType.libraryDefault);
            }
            Code = -1;
        }
        private void AddToLibrary([NotNull] PossibleNewTvShow ai)
        {
            // see if there is a matching show item
            ShowConfiguration found = mDoc.TvLibrary.GetShowItem(ai.TVDBCode);

            if (found is null)
            {
                // need to add a new showitem
                found = new ShowConfiguration(ai.TVDBCode, TVDoc.ProviderType.TheTVDB); //todo fix up for TVMAZE to allow searching vis TVMaze too (BulkAdd)
                mDoc.TvLibrary.Add(found);
            }

            found.AutoAddFolderBase = ai.Folder.FullName;

            if (ai.HasSeasonFoldersGuess)
            {
                found.AutoAddType = ai.SeasonFolderFormat == TVSettings.Instance.SeasonFolderFormat
                    ? ShowConfiguration.AutomaticFolderType.libraryDefault
                    : ShowConfiguration.AutomaticFolderType.custom;

                found.AutoAddCustomFolderFormat = ai.SeasonFolderFormat;
            }
            else
            {
                found.AutoAddType = ShowConfiguration.AutomaticFolderType.baseOnly;
            }

            mDoc.Stats().AutoAddedShows++;
        }
        private void AskUserAboutShow([NotNull] PossibleNewTvShow folder, IDialogParent owner)
        {
            if (folder.CodeKnown)
            {
                return;
            }

            BulkAddSeriesManager.GuessShowItem(folder, MDoc.TvLibrary, true);

            if (folder.CodeKnown)
            {
                return;
            }

            FolderMonitorEdit ed = new FolderMonitorEdit(folder);

            owner.ShowChildDialog(ed);
            DialogResult x    = ed.DialogResult;
            int          code = ed.Code;

            ed.Dispose();

            if (x != DialogResult.OK || code == -1)
            {
                return;
            }

            folder.TVDBCode = code;
        }
        public (bool finished, DirectoryInfo[] subDirs) CheckFolderForShows([NotNull] DirectoryInfo di2, bool andGuess, bool fullLogging, bool showErrorMsgBox)
        {
            try
            {
                // ..and not already a folder for one of our shows
                string theFolder = di2.FullName.ToLower();
                foreach (ShowConfiguration si in mDoc.TvLibrary.GetSortedShowItems())
                {
                    if (RejectFolderIfIncludedInShow(fullLogging, si, theFolder))
                    {
                        return(true, null);
                    }
                } // for each showitem

                //We don't have it already
                bool hasSeasonFolders = HasSeasonFolders(di2, out DirectoryInfo[] subDirectories, out string folderFormat);

                //This is an indication that something is wrong
                if (subDirectories is null)
                {
                    return(false, null);
                }

                bool hasSubFolders = subDirectories.Length > 0;
                if (hasSubFolders && !hasSeasonFolders)
                {
                    return(false, subDirectories);
                }

                if (TVSettings.Instance.BulkAddCompareNoVideoFolders && !HasFilmFiles(di2))
                {
                    return(false, subDirectories);
                }

                if (TVSettings.Instance.BulkAddIgnoreRecycleBin && IsRecycleBin(di2))
                {
                    return(false, subDirectories);
                }

                // ....its good!
                PossibleNewTvShow ai = new PossibleNewTvShow(di2, hasSeasonFolders, folderFormat);

                AddItems.Add(ai);
                Logger.Info("Adding {0} as a new folder", theFolder);
                if (andGuess)
                {
                    GuessShowItem(ai, mDoc.TvLibrary, showErrorMsgBox);
                }
                return(hasSeasonFolders, subDirectories);
            }
            catch (UnauthorizedAccessException)
            {
                Logger.Info("Can't access {0}, so ignoring it", di2.FullName);
                return(true, null);
            }
        }
        public static void GuessShowItem([NotNull] PossibleNewTvShow ai, [NotNull] ShowLibrary library, bool showErrorMsgBox)
        {
            string showName = GuessShowName(ai, library);

            int tvdbId = FindShowCode(ai);

            if (string.IsNullOrEmpty(showName) && tvdbId == -1)
            {
                return;
            }

            if (tvdbId != -1)
            {
                try
                {
                    CachedSeriesInfo cachedSeries = TheTVDB.LocalCache.Instance.GetSeriesAndDownload(tvdbId, showErrorMsgBox);
                    if (cachedSeries != null)
                    {
                        ai.TVDBCode = tvdbId;
                        return;
                    }
                }
                catch (ShowNotFoundException)
                {
                    //continue to try the next method
                }
            }

            CachedSeriesInfo ser = TheTVDB.LocalCache.Instance.GetSeries(showName, showErrorMsgBox);

            if (ser != null)
            {
                ai.TVDBCode = ser.TvdbCode;
                return;
            }

            //Try removing any year
            string showNameNoYear =
                Regex.Replace(showName, @"\(\d{4}\)", "").Trim();

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

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

            ser = TheTVDB.LocalCache.Instance.GetSeries(refinedHint, showErrorMsgBox);

            ai.RefinedHint = refinedHint;
            if (ser != null)
            {
                ai.TVDBCode = ser.TvdbCode;
            }
        }
Esempio n. 10
0
 private static void UpdateResultEntry([NotNull] PossibleNewTvShow ai, [NotNull] ListViewItem lvi)
 {
     lvi.SubItems.Clear();
     lvi.Text = ai.Folder.FullName;
     lvi.SubItems.Add(ai.CodeKnown ? TheTVDB.LocalCache.Instance.GetSeries(ai.TVDBCode)?.Name : ""); //todo - get bulk add to work for TVmaze
     lvi.SubItems.Add(ai.HasSeasonFoldersGuess ? "Folder per season" : "Flat");
     lvi.SubItems.Add(ai.CodeKnown ? ai.TVDBCode.ToString() : "");
     lvi.Tag        = ai;
     lvi.ImageIndex = ai.CodeKnown && !string.IsNullOrWhiteSpace(ai.Folder.FullName)?1:0;
 }
Esempio n. 11
0
        private void EditEntry([NotNull] PossibleNewTvShow fme)
        {
            FolderMonitorEdit ed = new FolderMonitorEdit(fme);

            if (ed.ShowDialog(this) != DialogResult.OK || ed.Code == -1)
            {
                return;
            }

            fme.TVDBCode = ed.Code;
        }
Esempio n. 12
0
        private void EditEntry([NotNull] PossibleNewTvShow fme)
        {
            BulkAddEditShow ed = new BulkAddEditShow(fme);

            if (ed.ShowDialog(this) != DialogResult.OK || ed.Code == -1)
            {
                return;
            }

            fme.SetId(ed.Code, ed.ProviderType);
        }
Esempio n. 13
0
        private void UpdateListItem(PossibleNewTvShow ai, bool makevis)
        {
            foreach (ListViewItem lvi in lvFMNewShows.Items)
            {
                if (lvi.Tag == ai)
                {
                    UpdateResultEntry(ai, lvi);

                    if (makevis)
                    {
                        lvi.EnsureVisible();
                    }
                }
            }
        }
Esempio n. 14
0
        private void RemoveNewFolder()
        {
            if (lvFMNewShows.SelectedItems.Count == 0)
            {
                return;
            }

            foreach (ListViewItem lvi in lvFMNewShows.SelectedItems)
            {
                PossibleNewTvShow ai = (PossibleNewTvShow)lvi.Tag;
                engine.AddItems.Remove(ai);
            }

            FillNewShowList(false);
        }
Esempio n. 15
0
        private static int FindShowCode(PossibleNewTvShow ai)
        {
            List <string> possibleFilenames = new List <string> {
                "cachedSeries.xml", "tvshow.nfo"
            };

            foreach (string fileName in possibleFilenames)
            {
                try
                {
                    IEnumerable <FileInfo> files = ai.Folder.EnumerateFiles(fileName).ToList();
                    if (files.Any())
                    {
                        foreach (int x in files.Select(FindShowCode).Where(x => x != -1))
                        {
                            return(x);
                        }
                    }
                }
                catch (System.IO.DirectoryNotFoundException e)
                {
                    Logger.Warn($"Could not look in {fileName} for any ShowCodes {e.Message}");
                }
                catch (UnauthorizedAccessException e)
                {
                    Logger.Warn($"Could not look in {fileName} for any ShowCodes {e.Message}");
                }
                catch (NotSupportedException e)
                {
                    Logger.Warn($"Could not look in {fileName} for any ShowCodes {e.Message}");
                }
                catch (System.IO.IOException e)
                {
                    Logger.Warn($"Could not look in {fileName} for any ShowCodes {e.Message}");
                }
            }
            //Can't find it
            return(-1);
        }
Esempio n. 16
0
        private static void UpdateResultEntry([NotNull] PossibleNewTvShow ai, [NotNull] ListViewItem lvi)
        {
            lvi.SubItems.Clear();
            lvi.Text = ai.Folder.FullName;
            if (ai.CodeKnown)
            {
                CachedSeriesInfo?x = ai.CachedSeries;

                lvi.SubItems.Add(x?.Name);
                lvi.SubItems.Add(ai.HasSeasonFoldersGuess ? "Folder per season" : "Flat");
                lvi.SubItems.Add(ai.CodeKnown ? ai.ProviderCode.ToString() : string.Empty);
            }
            else
            {
                lvi.SubItems.Add(ai.RefinedHint);
                lvi.SubItems.Add(ai.HasSeasonFoldersGuess ? "Folder per season" : "Flat");
                lvi.SubItems.Add(string.Empty);
            }

            lvi.Tag        = ai;
            lvi.ImageIndex = ai.CodeKnown && !string.IsNullOrWhiteSpace(ai.Folder.FullName)?1:0;
        }
Esempio n. 17
0
        private void bnIgnoreNewFolder_Click(object _, System.EventArgs e)
        {
            if (lvFMNewShows.SelectedItems.Count == 0)
            {
                return;
            }

            DialogResult res = MessageBox.Show("Add selected folders to the 'Bulk Add Shows' ignore folders list?", "Bulk Add Shows", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

            if (res != DialogResult.Yes)
            {
                return;
            }

            foreach (ListViewItem lvi in lvFMNewShows.SelectedItems)
            {
                PossibleNewTvShow ai = (PossibleNewTvShow)lvi.Tag;
                TVSettings.Instance.IgnoreFolders.Add(ai.Folder.FullName.ToLower());
                engine.AddItems.Remove(ai);
            }
            mDoc.SetDirty();
            FillNewShowList(false);
            FillFolderStringLists();
        }