private static void SearchForDuplicates([NotNull] ProcessedEpisode pep, StringBuilder output, ShowItem si, int seasonId, [NotNull] IEnumerable <ProcessedEpisode> seasonEpisodes, DirFilesCache dfc, List <PossibleDuplicateEpisode> returnValue) { if (pep.Type == ProcessedEpisode.ProcessedEpisodeType.merged) { output.AppendLine(si.ShowName + " - Season: " + seasonId + " - " + pep.NumsAsString() + " - " + pep.Name + " is:"); foreach (Episode sourceEpisode in pep.SourceEpisodes) { output.AppendLine(" - " + sourceEpisode.AiredEpNum + " - " + sourceEpisode.Name); } } foreach (ProcessedEpisode comparePep in seasonEpisodes.Where(comparePep => EpisodesMatch(pep, comparePep))) { // Tell user about this possibility output.AppendLine($"{si.ShowName} - Season: {seasonId} - {pep.FirstAired.ToString()} - {pep.AiredEpNum}({pep.Name}) - {comparePep.AiredEpNum}({comparePep.Name})"); //do the 'name' test string root = Helpers.GetCommonStartString(pep.Name, comparePep.Name); bool sameLength = pep.Name.Length == comparePep.Name.Length; bool sameName = !root.Trim().Equals("Episode") && sameLength && root.Length > 3 && root.Length > pep.Name.Length / 2; bool oneFound = false; bool largerFileSize = false; if (sameName) { oneFound = IsOneFound(output, dfc, pep, comparePep, ref largerFileSize); } returnValue.Add(new PossibleDuplicateEpisode(pep, comparePep, seasonId, true, sameName, oneFound, largerFileSize)); } }
public static string GetBestNameFor([NotNull] List <string> episodeNames, string defaultName) { string root = Helpers.GetCommonStartString(episodeNames); int shortestEpisodeName = episodeNames.Min(x => x.Length); int longestEpisodeName = episodeNames.Max(x => x.Length); bool namesSameLength = (shortestEpisodeName == longestEpisodeName); bool rootIsIgnored = root.Trim().StartsWith("Episode", StringComparison.OrdinalIgnoreCase) || root.Trim().StartsWith("Part", StringComparison.OrdinalIgnoreCase); if (!namesSameLength || rootIsIgnored || root.Length <= 3 || root.Length <= shortestEpisodeName / 2) { return(defaultName); } char[] charsToTrim = { ',', '.', ';', ':', '-', '(' }; string[] wordsToTrim = { "part", "episode", "pt", "chapter" }; return(root.Trim().TrimEnd(wordsToTrim).Trim().TrimEnd(charsToTrim).Trim()); }