private async Task checkSubtitlesAsync() { var groomer = new Groomer(Config.LastDirectory); lblStatus.Content = "Working..."; lblTotal.Content = 0; lblNeedMoving.Content = 0; lblWithoutVideo.Content = 0; lblWithoutSubtitles.Content = 0; lblRenamed.Content = 0; await groomer.CheckSubtitlesAsync(); lblStatus.Content = "Ready"; VideosWithoutSubtitles.Clear(); foreach (var video in groomer.VideosWithoutSubtitle .Where(video => !Config.IgnoredVideos.Any(ignored => video.FullName.EndsWith(ignored, StringComparison.OrdinalIgnoreCase)))) { VideosWithoutSubtitles.Add(video.FullName); } lblTotal.Content = groomer.SubtitlesTotal; lblNeedMoving.Content = groomer.SubtitlesNeedMoving.Count; lblWithoutVideo.Content = groomer.SubtitlesWithoutVideo.Count; lblWithoutLang.Content = groomer.SubtitlesWithoutLang; updateVideosWithoutSubtitleCount(); lbNeedMoving.ItemsSource = groomer.SubtitlesNeedMoving; SubtitlesWithoutVideo.Clear(); groomer.SubtitlesWithoutVideo.ForEach(fi => SubtitlesWithoutVideo.Add(new SubtitleData { Subtitle = fi })); }
private void subtitleItemVideo_SelectionChanged(object sender, SelectionChangedEventArgs e) { lblRenamed.Content = 0; if (e.AddedItems.Count == 0) { return; } var video = e.AddedItems[0] as string; if (video == null) { return; } var subtitleData = lvSubtitlesWithoutVideo.SelectedItem as SubtitleData; if (subtitleData == null) { return; } try { var hasLangCode = Groomer.HasSubtitleLangCode(subtitleData.Subtitle.Name); Groomer.RenameSubtitleToMatchVideo(subtitleData.Subtitle, video); SubtitlesWithoutVideo.Remove(subtitleData); lblWithoutVideo.Content = SubtitlesWithoutVideo.Count; if (!hasLangCode) { lblWithoutLang.Content = (int)lblWithoutLang.Content - 1; } var videoItem = VideosWithoutSubtitles.FirstOrDefault(v => v.Contains(video)); if (videoItem != null) { VideosWithoutSubtitles.Remove(videoItem); lblWithoutSubtitles.Content = VideosWithoutSubtitles.Count; } lblRenamed.Content = 1; } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
public async Task CheckSubtitlesAsync() { await Task.Run(() => { SubtitlesNeedMoving.Clear(); SubtitlesWithoutVideo.Clear(); SubtitlesTotal = 0; SubtitlesWithoutLang = 0; foreach (string file in GetFiles(rootDirectory, subtitleExtensionsPattern, SearchOption.AllDirectories)) { SubtitlesTotal++; var fi = new FileInfo(file); var subtitleNameWOExt = Path.GetFileNameWithoutExtension(fi.Name); bool needsRename = true; foreach (var code in langCodeMappings.Keys) { if (subtitleNameWOExt.EndsWith("." + code, StringComparison.OrdinalIgnoreCase)) { if (langCodeMappings[code] == code) { needsRename = false; } break; } } if (needsRename) { SubtitlesWithoutLang++; } // check if there is a video file next to subtitle file starting with the same name if (fi.Directory != null && fi.Directory.EnumerateFiles() .Any(f => videoExtensions.Contains(f.Extension) && fi.Name.StartsWith(Path.GetFileNameWithoutExtension(f.Name) + ".", StringComparison.OrdinalIgnoreCase))) { continue; } // check if there is a video file in parent folder of the subtitle file starting with the same name if (fi.Directory != null && fi.Directory.Parent != null && fi.Directory.Parent.EnumerateFiles() .Any(f => videoExtensions.Contains(f.Extension) && fi.Name.StartsWith(Path.GetFileNameWithoutExtension(f.Name) + ".", StringComparison.OrdinalIgnoreCase))) { SubtitlesNeedMoving.Add(fi); continue; } SubtitlesWithoutVideo.Add(fi); } foreach (string file in GetFiles(rootDirectory, videoExtensionsPattern, SearchOption.AllDirectories)) { var video = new FileInfo(file); if (video.Directory != null && !video.Directory.EnumerateFiles().Any(subtitle => subtitlePattern.IsMatch(subtitle.Extension) && subtitle.Name.StartsWith(Path.GetFileNameWithoutExtension(video.Name) + ".", StringComparison.OrdinalIgnoreCase))) { VideosWithoutSubtitle.Add(video); } } }); }