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); }
private static void AskUserAboutFileReplacement(FileInfo file1, FileInfo file2, [NotNull] MovieConfiguration pep, IDialogParent owner) { try { ChooseFile question = new ChooseFile(file1, file2); owner.ShowChildDialog(question); ChooseFile.ChooseFileDialogResult result = question.Answer; question.Dispose(); switch (result) { case ChooseFile.ChooseFileDialogResult.ignore: LOGGER.Info($" User has selected keeping {file1.FullName} and {file2.FullName} and they will not be merged"); return; case ChooseFile.ChooseFileDialogResult.left: UpgradeFile("User selected to", file1, pep, file2); return; case ChooseFile.ChooseFileDialogResult.right: UpgradeFile("User selected to", file2, pep, file1); return; default: throw new ArgumentOutOfRangeException(); } } catch (System.IO.FileNotFoundException) { return; } }
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; }
/// <summary> /// Processes a set of actions, running them in a multi-threaded way based on the application's settings. /// </summary> /// <param name="theList">An ItemList to be processed.</param> /// <param name="showUi">Whether or not we should display a UI to inform the user about progress.</param> public void DoActions(ItemList?theList, bool showUi, IDialogParent owner) { if (theList is null) { Logger.Info("Asked to do actions, but none provided...."); return; } Logger.Info("**********************"); Logger.Info($"Doing Selected Actions.... ({theList.Count} items detected, {theList.Actions.Count} actions to be completed )"); // Run tasks in parallel (as much as is sensible) ActionQueue[] queues = ActionProcessorMakeQueues(theList); actionPause = false; // If not /hide, show CopyMoveProgress dialog CopyMoveProgress cmp = null; if (showUi) { cmp = new CopyMoveProgress(this, queues); } Thread actionProcessorThread = new Thread(ActionProcessor) { Name = "ActionProcessorThread" }; actionProcessorThread.Start(queues); if (showUi) { owner.ShowChildDialog(cmp); if (cmp.DialogResult == DialogResult.Cancel) { actionProcessorThread.Abort(); } } actionProcessorThread.Join(); theList.RemoveAll(x => x is Action action && action.Outcome.Done && !action.Outcome.Error); foreach (Action slia in theList.Actions) { Logger.Warn(slia.Outcome.LastError, $"Failed to complete the following action: {slia.Name}, doing {slia}. Error was {slia.Outcome.LastError?.Message}"); } Logger.Info("Completed Selected Actions"); Logger.Info("**************************"); }
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); }
private void CreateSeasonFolder(ShowConfiguration si, int snum, ICollection <string> ignoredLocations, string proposedFolderName, IDialogParent owner) { string folder = proposedFolderName; // generate new filename info // ReSharper disable once RedundantAssignment bool goAgain = false; DirectoryInfo di = null; bool firstAttempt = true; do { goAgain = false; if (!string.IsNullOrEmpty(folder)) { try { di = new DirectoryInfo(folder); } catch (Exception e) { LOGGER.Warn($"Could not create Season Folder {folder} as {e.Message}."); break; } } if (ignoredLocations.Contains(folder)) { break; } if (di != null && di.Exists) { continue; } string?otherFolder = null; FaResult whatToDo = GetDefaultAction(); if (TVSettings.Instance.AutoCreateFolders && firstAttempt) { whatToDo = FaResult.kfaCreate; firstAttempt = false; } if (whatToDo == FaResult.kfaNotSet) { // no command line guidance, so ask the user MissingFolderAction mfa = new MissingFolderAction(si.ShowName, snum + " of " + si.MaxSeason(), folder); owner.ShowChildDialog(mfa); whatToDo = mfa.Result; otherFolder = mfa.FolderName; mfa.Dispose(); } switch (whatToDo) { case FaResult.kfaRetry: goAgain = true; break; case FaResult.kfaDifferentFolder: if (otherFolder != null) { folder = otherFolder; } goAgain = UpdateDirectory(si, snum, folder); break; case FaResult.kfaNotSet: break; case FaResult.kfaCancel: throw new TVRenameOperationInterruptedException(); case FaResult.kfaCreate: TryCreateDirectory(folder, si.ShowName, snum + " of " + si.MaxSeason()); goAgain = true; break; case FaResult.kfaIgnoreOnce: ignoredLocations.Add(folder); break; case FaResult.kfaIgnoreAlways: si.IgnoreSeasons.Add(snum); Doc.SetDirty(); break; default: throw new ArgumentOutOfRangeException(); } } while (goAgain); }
public static List <MediaConfiguration> FindMedia([NotNull] IEnumerable <string> possibleShowNames, TVDoc doc, IDialogParent owner) { List <MediaConfiguration> addedShows = new List <MediaConfiguration>(); 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 (LookForMovies(hint, addedShows)) { Logger.Info($"Ignoring {hint} as it matches existing movies."); 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.TvLibrary.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 + 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; } Logger.Info("****************"); Logger.Info($"Auto Adding New Show/Movie for '{refinedHint}'"); //popup dialog AutoAddShow askForMatch = new AutoAddShow(refinedHint, hint); owner.ShowChildDialog(askForMatch); DialogResult dr = askForMatch.DialogResult; askForMatch.Dispose(); if (dr == DialogResult.OK) { //If added add show to collection if (askForMatch.ShowConfiguration.Code > 0) { addedShows.Add(askForMatch.ShowConfiguration); doc.Stats().AutoAddedShows++; } else { 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}"); } } return(addedShows); }