/* * Предыдущая секция нужна в случае если конвертитуется обрезок, т.к. * его размер должен включать размер реза, который находится перед ним. */ private Lane ConvertSection(Section input, Section prevSection, Section nextSection) { Lane result = new Lane(); result.Size = input.Size; switch (input.SectionType) { case SectionType.Cut: result.LaneType = LaneType.Cut; result.SizeType = SizeType.Automatic; break; case SectionType.Element: result.LaneType = LaneType.Detail; result.SizeType = SizeType.Changeable; result.Name = DetailNameFixer.Convert(Transliterator.Convert(input.Label)); break; case SectionType.NewLine: result.LaneType = LaneType.Lane; result.SizeType = SizeType.Changeable; break; case SectionType.Remain: result.LaneType = LaneType.Rest; result.SizeType = SizeType.Changeable; break; case SectionType.Scrap: result.LaneType = LaneType.Cutoff; result.SizeType = SizeType.Automatic; if (prevSection != null && prevSection.SectionType == SectionType.Cut) { result.Size = input.Size + prevSection.Size; } if (nextSection != null && nextSection.SectionType == SectionType.Cut) { result.Size = input.Size + nextSection.Size; } break; case SectionType.Free: result.LaneType = LaneType.Cutoff; result.SizeType = SizeType.Automatic; if (prevSection != null && prevSection.SectionType == SectionType.Cut) { result.Size = input.Size + prevSection.Size; } if (nextSection != null && nextSection.SectionType == SectionType.Cut) { result.Size = input.Size + nextSection.Size; } break; } return(result); }
private async Task FindMovieCommandAsync(string name, CancellationToken cancellationToken = default) { if (string.IsNullOrWhiteSpace(Folder) || !Directory.Exists(Folder)) { this.Say("Директория фильмов не найдена. Пожалуйста, укажите ее и попробуйте снова"); this.ShowSettings(); return; } this.Say($"Ищу фильм {name}"); var files = GetFiles(Folder, Folder2, Folder3); if (!files.Any()) { this.Say("Ничего не найдено"); await CheckTorrentAsync(name, cancellationToken).ConfigureAwait(false); return; } var translitedGost = Transliterator.Convert(name, Transliterator.TranslateType.Gost); var translitedIso = Transliterator.Convert(name, Transliterator.TranslateType.Iso); var distances = new List <Tuple <int, string> >(); foreach (var path in files) { distances.Add(GetDistance(path, name)); distances.Add(GetDistance(path, translitedGost)); distances.Add(GetDistance(path, translitedIso)); } distances = distances.OrderBy(i => i.Item1).ToList(); var minimumItem = distances.FirstOrDefault(); var minimumDistance = minimumItem?.Item1 ?? int.MaxValue; if (minimumDistance > MaximumDistance) { this.Print($"Ближайшее совпадение: дистанция {minimumDistance} и строка {minimumItem?.Item2}"); this.Say("Ничего подходящего не найдено"); await CheckTorrentAsync(name, cancellationToken).ConfigureAwait(false); return; } var goodDistances = distances.Where(i => Math.Abs(i.Item1 - minimumDistance) <= 2).Distinct().ToList(); if (goodDistances.Count == 1) { StartMovie(goodDistances[0].Item2); return; } foreach (var distance in goodDistances) { this.Print($"File {distance.Item2}. Distance: {distance.Item1}"); } StartMovie(goodDistances[0].Item2); }