コード例 #1
0
ファイル: TvShow.cs プロジェクト: JackP74/PMedia
        public bool LoadPlaylist(Playlist newPlaylist)
        {
            if (newPlaylist.currentList.files.Count() == 0)
            {
                CMBox.Show("Warning", "Empty playlist", Style.Warning, Buttons.OK);
                return(false);
            }
            else
            {
                episodeList.Clear();
                nextEpisode     = new EpisodeInfo();
                currentEpisode  = new EpisodeInfo();
                previousEpisode = new EpisodeInfo();

                episodeList.AddRange(newPlaylist.currentList.files);
                currentEpisode = episodeList[0];

                if (episodeList.Count() > 1)
                {
                    nextEpisode = episodeList[1];
                }

                return(true);
            }
        }
コード例 #2
0
ファイル: TvShow.cs プロジェクト: JackP74/PMedia
 public TvShow(TvShow tvShow)
 {
     EmptyEpisode    = new EpisodeInfo();
     episodeList     = tvShow.episodeList;
     nextEpisode     = tvShow.NextEpisode();
     currentEpisode  = tvShow.currentEpisode;
     previousEpisode = tvShow.PreviousEpisode();
 }
コード例 #3
0
        private void MenuOpen_Click(object sender, RoutedEventArgs e)
        {
            if (InfoList.Items.Count <= 0) // Ignore if no items
            {
                return;
            }

            if (InfoList.SelectedItems.Count <= 0) // Ignore if no selected items
            {
                return;
            }

            if (InfoList.SelectedItems.Count > 1)
            {
                CMBox.Show("Warning", "Multiple items selected not supported", MessageCustomHandler.Style.Warning, Buttons.OK);
                return;
            }

            EpisodeInfo selectedEpisode = null; // Make the item to be used by all senders

            foreach (ListViewItem item in InfoList.SelectedItems)
            {
                selectedEpisode = tvShow.episodeList.Find(x => $"{x.Name} - {x.Episode}" == item.Content.ToString());
                break;
            }

            if (sender is MenuItem menuItem)
            {
                if (menuItem.Name.EndsWith("File")) // Open file
                {
                    //Process.Start(selectedEpisode.FilePath);
                    ((MainWindow)this.Owner).OpenFile(selectedEpisode.FilePath);
                }

                else if (menuItem.Name.EndsWith("Dir")) // open directory
                {
                    Process.Start(new System.IO.FileInfo(selectedEpisode.FilePath).DirectoryName);
                }
            }
        }
コード例 #4
0
ファイル: TvShow.cs プロジェクト: JackP74/PMedia
        public void Load(string FilePath)
        {
            if (Patterns == null || Replacements == null)
            {
                throw new Exception("TvShow not made to load from an other TvShow");
            }

            if (episodeList.Count() <= 0 || episodeList.Where(x => x.FilePath == FilePath).Count() <= 0) // Is not part of the current list
            {
                // Clear everything
                episodeList.Clear();
                nextEpisode     = new EpisodeInfo();
                currentEpisode  = new EpisodeInfo();
                previousEpisode = new EpisodeInfo();

                // New video info
                currentEpisode = ParseFile(FilePath);

                if (currentEpisode.IsTvShow && currentEpisode.Search && !string.IsNullOrWhiteSpace(currentEpisode.SearchDir)) // Is TvShow
                {
                    episodeList.Add(currentEpisode);

                    List <string> dirList = new List <string> {
                        currentEpisode.SearchDir
                    };                                                                    // New List of dirs to check

                    foreach (string dir in Directory.GetDirectories(currentEpisode.SearchDir))
                    {
                        if (HasDirPermission(dir)) // Don't check dirs that the user doesn't have access to
                        {
                            // Only check dirs that start with the same name to limit search count
                            if (GetDirName(dir).StartsWith(currentEpisode.Name))
                            {
                                dirList.Add(dir);
                            }
                        }
                    }

                    List <string> fileList = new List <string>(); // File list to check

                    foreach (string dir in dirList)
                    {
                        // Only get files with video extensions to limit check count
                        var foundList = GetFilesByExtensions(new DirectoryInfo(dir), Extensions.Video.ToArray());
                        fileList.AddRange(foundList.ToList());
                    }

                    foreach (string file in fileList.Distinct()) // TvShow check
                    {
                        if (file != FilePath)                    // Don't re-check current file
                        {
                            EpisodeInfo currentInfo = ParseFile(file);

                            if (currentInfo.IsTvShow && currentInfo.Name == currentEpisode.Name && !episodeList.Contains(currentInfo)) // Check if TvShow and names match
                            {
                                episodeList.Add(currentInfo);
                            }
                        }
                    }

                    episodeList = episodeList.Distinct().ToList();
                    episodeList = episodeList.GroupBy(ep => ep.Episode).Select(ep => ep.First()).ToList();

                    episodeList.Sort((a, b) => a.Episode.CompareTo(b.Episode));

                    // Next/Previous episodes
                    int currentIdx = episodeList.IndexOf(currentEpisode);

                    if (currentIdx > 0)
                    {
                        previousEpisode = episodeList[currentIdx - 1];
                    }

                    if (currentIdx < episodeList.Count() - 1)
                    {
                        nextEpisode = episodeList[currentIdx + 1];
                    }
                }
                else
                {
                    episodeList.Add(currentEpisode); // Is not a tv show but add it empty for uniformity
                }
            }
            else // Part of current list
            {
                // Clear Next/Previous
                nextEpisode     = new EpisodeInfo();
                currentEpisode  = new EpisodeInfo();
                previousEpisode = new EpisodeInfo();

                // Set new current/next/previous episode
                currentEpisode = episodeList.Find(x => x.FilePath == FilePath);

                int currentIdx = episodeList.IndexOf(currentEpisode);

                if (currentIdx > 0)
                {
                    previousEpisode = episodeList[currentIdx - 1];
                }

                if (currentIdx < episodeList.Count() - 1)
                {
                    nextEpisode = episodeList[currentIdx + 1];
                }
            }

            neverSet = false;
        }
コード例 #5
0
ファイル: TvShow.cs プロジェクト: JackP74/PMedia
        public TvShow()
        {
            // Init default patterns.
            Patterns = new List <MatchPattern>
            {
                // Filename only pattern

                // Series\Season...\S01E01* or Series\Season...\1x01*
                new MatchPattern {
                    Enabled = true, Pattern = @"(?<series>[^\\]*)\\[^\\]*(?<seasonnum>\d+)[^\\]*\\S*(?<seasonnum>\d+)[EX](?<episodenum>\d+)*(?<episode>.*)\.", RegexOptions = RegexOptions.IgnoreCase
                },

                // MP1 EpisodeScanner recommendations for recordings: Series - (Episode) S1E1, also "S1 E1", "S1-E1", "S1.E1", "S1_E1"
                new MatchPattern {
                    Enabled = true, Pattern = @"(?<series>[^\\]+) - \((?<episode>.*)\) S(?<seasonnum>[0-9]+?)[\s|\.|\-|_]{0,1}E(?<episodenum>[0-9]+?)", RegexOptions = RegexOptions.IgnoreCase
                },

                // "Series 1x1 - Episode" and multi-episodes "Series 1x1_2 - Episodes"
                new MatchPattern {
                    Enabled = true, Pattern = @"(?<series>[^\\]+)\W(?<seasonnum>\d+)x((?<episodenum>\d+)_?)+ - (?<episode>.*)\.", RegexOptions = RegexOptions.IgnoreCase
                },

                // "Series S1E01 - Episode" and multi-episodes "Series S1E01_02 - Episodes", also "S1 E1", "S1-E1", "S1.E1", "S1_E1"
                new MatchPattern {
                    Enabled = true, Pattern = @"(?<series>[^\\]+)\WS(?<seasonnum>\d+)[\s|\.|\-|_]{0,1}E((?<episodenum>\d+)_?)+ - (?<episode>.*)\.", RegexOptions = RegexOptions.IgnoreCase
                },

                // "Series.Name.1x01.Episode.Or.Release.Info"
                new MatchPattern {
                    Enabled = true, Pattern = @"(?<series>[^\\]+).(?<seasonnum>\d+)x((?<episodenum>\d+)_?)+(?<episode>.*)\.", RegexOptions = RegexOptions.IgnoreCase
                },

                // "Series.Name.S01E01.Episode.Or.Release.Info", also "S1 E1", "S1-E1", "S1.E1", "S1_E1"
                new MatchPattern {
                    Enabled = true, Pattern = @"(?<series>[^\\]+).S(?<seasonnum>\d+)[\s|\.|\-|_]{0,1}E((?<episodenum>\d+)_?)+(?<episode>.*)\.", RegexOptions = RegexOptions.IgnoreCase
                },

                // Folder + filename pattern

                // "Series\1\11 - Episode" "Series\Staffel 2\11 - Episode" "Series\Season 3\12 Episode" "Series\3. Season\13-Episode"
                new MatchPattern {
                    Enabled = false, Pattern = @"(?<series>[^\\]*)\\[^\\|\d]*(?<seasonnum>\d+)\D*\\(?<episodenum>\d+)\s*-\s*(?<episode>[^\\]+)\.", RegexOptions = RegexOptions.IgnoreCase
                },

                // "Series.Name.101.Episode.Or.Release.Info", attention: this expression can lead to false matches for every filename with nnn included
                new MatchPattern {
                    Enabled = false, Pattern = @"(?<series>[^\\]+).\W(?<seasonnum>\d{1})(?<episodenum>\d{2})\W(?<episode>.*)\.", RegexOptions = RegexOptions.IgnoreCase
                },
            };

            // Init default replacements
            Replacements = new List <Replacement>
            {
                new Replacement {
                    Enabled = true, Pattern = "360p", ReplaceBy = "", IsRegex = false
                },
                new Replacement {
                    Enabled = true, Pattern = "480p", ReplaceBy = "", IsRegex = false
                },
                new Replacement {
                    Enabled = true, Pattern = "720p", ReplaceBy = "", IsRegex = false
                },
                new Replacement {
                    Enabled = true, Pattern = "1080i", ReplaceBy = "", IsRegex = false
                },
                new Replacement {
                    Enabled = true, Pattern = "1080p", ReplaceBy = "", IsRegex = false
                },
                new Replacement {
                    Enabled = true, Pattern = "x264", ReplaceBy = "", IsRegex = false
                },
                new Replacement {
                    Enabled = true, Pattern = "x265", ReplaceBy = "", IsRegex = false
                },
                new Replacement {
                    Enabled = true, Pattern = @"(?<!(?:S\d+.?E\\d+\-E\d+.*|S\d+.?E\d+.*|\s\d+x\d+.*))P[ar]*t\s?(\d+)(\s?of\s\d{1,2})?", ReplaceBy = "S01E${1}", IsRegex = true
                },
            };

            // Init variables
            EmptyEpisode    = new EpisodeInfo();
            episodeList     = new List <EpisodeInfo>();
            nextEpisode     = new EpisodeInfo();
            currentEpisode  = new EpisodeInfo();
            previousEpisode = new EpisodeInfo();
        }