Exemple #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;
            }
        }
Exemple #2
0
        public void RefreshFolder()
        {
            if (TB_FolderPath.Text == "")
            {
                return;
            }

            Cursor.Current = Cursors.WaitCursor;

            ClearFiles();

            try
            {
                BlackList = NameExtractor.PreBlackList;
                if (File.Exists("RenamerBlackList.txt"))
                {
                    var pb = new List <string>();
                    foreach (var item in File.ReadAllLines("RenamerBlackList.txt"))
                    {
                        if (!BlackList.Contains(item))
                        {
                            pb.Add(Regex.Escape(item));
                        }
                    }
                    BlackList = FormatBlackList(BlackList.Union(pb).ToArray());
                }
                else
                {
                    File.WriteAllText("RenamerBlackList.txt", "");
                }
            }
            catch (Exception) { BlackList = FormatBlackList(NameExtractor.PreBlackList); }

            try
            {
                var Files      = new List <string>();
                var VideoFiles = new List <string>();

                foreach (var item in Directory.EnumerateFiles(TB_FolderPath.Text, "*.*", SearchOption.AllDirectories))
                {
                    if (IsVideoFile(item) && (MovieMode || Episode.PathIsValid(item)))
                    {
                        VideoFiles.Add(item);
                        if (VideoFiles.Count > 650)
                        {
                            throw new StackOverflowException("File Count exceeded Limit");
                        }
                    }
                    else
                    {
                        Files.Add(item);
                    }
                }

                if (MovieMode) // Movie Mode
                {
                    foreach (var Video in VideoFiles)
                    {
                        Movies.Add(new Movie(Video));
                    }

                    L_SeasonCount.Text = Movies.Count.ToString();

                    foreach (var Movie in Movies.OrderByDescending(x => x.Name))
                    {
                        Movie.Control = new MovieControl(Movie)
                        {
                            Dock = DockStyle.Top
                        };
                        Form1.reviewSubForm.P_Main.Controls.Add(Movie.Control);
                        Movie.Control.Show();
                    }
                }
                else // Series Mode
                {
                    var Episodes = new List <Episode>();
                    foreach (var item in VideoFiles)
                    {
                        Episodes.Add(new Episode(item));
                    }
                    foreach (var SNumber in Season.GetSeasons(Episodes))
                    {
                        Seasons.Add(new Season(SNumber, Episodes.Where(x => x.SeasonNumber == SNumber).ToList()));
                    }

                    L_SeasonCount.Text = Seasons.Count.ToString();
                    L_EpCount.Text     = Episodes.Count.ToString();

                    foreach (var Season in Seasons.OrderByDescending(x => x.SeasonNumber))
                    {
                        Season.Control = new SeasonControl(Season)
                        {
                            Dock = DockStyle.Top
                        };
                        Form1.reviewSubForm.P_Main.Controls.Add(Season.Control);
                        Season.Control.Show();
                    }
                }

                if (O_IncludeSubs)
                {
                    AddSubtitles();
                }

                JunkFiles = Files.Where(f => Movies.All(m => m.FilePath != f && m.Subs.All(s => s.FilePath != f)) &&
                                        Seasons.All(S => S.Episodes.All(e => e.FilePath != f && e.Subs.All(sub => sub.FilePath != f))) &&
                                        !(new FileInfo(f).Attributes.HasFlag(FileAttributes.Hidden))).ToList();

                if (!O_IncludeSubs)
                {
                    JunkFiles.RemoveAll(x => x.EndsWith(".srt"));
                }

                L_SeasonCount.ForeColor = L_EpCount.ForeColor = L_SubCount.ForeColor = FormState.N_Focused.Color;
                CurrentFormState        = GetFormState();
            }
            catch (Exception ex)
            {
                ClearFiles();
                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;
            }
            Cursor.Current = Cursors.Default;
        }