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
            }));
        }
Beispiel #2
0
        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);
                    }
                }
            });
        }