예제 #1
0
        public void AddSubtitles()
        {
            DeleteSubtitles();

            try
            {
                var SubFiles = Directory.GetFiles(TB_FolderPath.Text, "*.srt", SearchOption.AllDirectories);
                var Subs     = new List <Subtitle>();

                if (MovieMode)
                {
                    foreach (var item in SubFiles)
                    {
                        Subs.Add(new Subtitle(item));
                    }

                    foreach (var Movie in Movies)
                    {
                        Movie.AddSubs(Subs.Where(x => MatchMovieAndSubs(x, Movie)));
                    }

                    foreach (var Movie in Movies)
                    {
                        foreach (var Sub in Movie.Subs)
                        {
                            Sub.Movie = Movie;
                        }
                    }

                    L_SubCount.Text = (Movies.Sum(x => x.Subs.Count)).ToString();
                }
                else
                {
                    foreach (var item in SubFiles.Where(x => Episode.PathIsValid(x)))
                    {
                        Subs.Add(new Subtitle(item));
                    }

                    foreach (var Season in Seasons)
                    {
                        foreach (var Episode in Season.Episodes)
                        {
                            Episode.AddSubs(Subs.Where(s => s.EpisodeNumber == Episode.EpisodeNumber && s.SeasonNumber == Episode.SeasonNumber));
                        }
                    }

                    foreach (var Season in Seasons)
                    {
                        foreach (var Episode in Season.Episodes)
                        {
                            foreach (var Sub in Episode.Subs)
                            {
                                Sub.Episode = Episode;
                            }
                        }
                    }

                    L_SubCount.Text = (Seasons.Sum(e => e.Episodes.Sum(x => x.Subs.Count))).ToString();
                }
            }
            catch (Exception ex)
            {
                DeleteSubtitles();
                Form1.ShowError(ex.Message);
                L_SeasonCount.Text      = L_EpCount.Text = L_SubCount.Text = "0";
                L_SeasonCount.ForeColor = L_EpCount.ForeColor = L_SubCount.ForeColor = Color.FromArgb(242, 60, 53);
                Clipboard.SetText(ex.ToString());
                CurrentFormState = FormState.Busy;
            }
        }