Пример #1
0
        public static int GetSeason(string n)
        {
            Episode e = GetEpisodeFromName(n);

            return(e == null ? -1 : e.season);
        }
Пример #2
0
        public static int GetEpisode(string n)
        {
            Episode e = GetEpisodeFromName(n);

            return(e == null ? -1 : e.number);
        }
Пример #3
0
        /// <summary>
        /// Function to get Season or Episode number from string name
        /// </summary>
        /// <param name="n">File name</param>
        /// <param name="season">IsSeason</param>
        /// <returns>Value of Season or Episode</returns>
        public static Episode GetEpisodeFromName(string n)
        {
            string path = n;

            n = Path.GetFileNameWithoutExtension(n);
            int   result = -1;
            Match m      = Regex.Match(n, "s(\\d{1,2})e(\\d{1,2})", RegexOptions.IgnoreCase);

            if (m.Success)
            {
                int     indexof = n.ToLower().IndexOf('e', m.Index);
                Episode e       = new Episode();

                if (int.TryParse(n.Substring(m.Index + 1, indexof - m.Index - 1), out result))
                {
                    e.season = result;
                }
                if (int.TryParse(n.Substring(indexof + 1, m.Length - (indexof - m.Index) - 1), out result))
                {
                    e.number = result;
                }

                e.title = n.Substring(m.Index + m.Length, n.Length - m.Index - m.Length);
                e.title = TestForEndings(ContextAwareDotReplace(Regex.Replace(e.title, "^[\\.\\- ]*", ""))).Trim();

                e.show = new Show(ContextAwareDotReplace(n.Substring(0, m.Index)).Trim());
                e.path = path;

                return(e);
            }

            m = Regex.Match(n, "(\\d{1,2})x(\\d{1,2})", RegexOptions.IgnoreCase);
            if (m.Success)
            {
                int     indexof = n.ToLower().IndexOf('x', m.Index);
                Episode e       = new Episode();

                if (int.TryParse(n.Substring(m.Index, indexof - m.Index), out result))
                {
                    e.season = result;
                }
                if (int.TryParse(n.Substring(indexof + 1, m.Length - (indexof - m.Index) - 1), out result))
                {
                    e.number = result;
                }

                e.title = n.Substring(m.Index + m.Length, n.Length - m.Index - m.Length);
                indexof = e.title.LastIndexOf('.');
                if (indexof > 0)
                {
                    e.title = e.title.Substring(0, indexof);
                }
                e.title = TestForEndings(ContextAwareDotReplace(Regex.Replace(e.title, "^[-. ]*", ""))).Trim();
                e.show  = new Show(n.Substring(0, m.Index).Trim());
                e.path  = path;

                return(e);
            }
            m = Regex.Match(n, @"(\d+)$");
            if (m.Success)
            {
                return(new Episode(null, 1, int.Parse(m.Value), path, new Show(n.Substring(0, m.Index))));
            }

            if (result == -1 && n.ToLower().Contains("pilot"))
            {
                string[] split = Regex.Split(n, "pilot", RegexOptions.IgnoreCase);
                return(new Episode(split[0], 1, 0, new Show(Regex.Replace(split[1], "\\..*", "")))
                {
                    path = path
                });
            }
            else
            {
                return(null);
            }
        }