Beispiel #1
0
        private int DetermineSeason()
        {
            int season = 0;

            try
            {
                if (!string.IsNullOrEmpty(TvWord))
                {
                    if (TvWord.Length == 3)
                    {
                        string firstChar = TvWord.Substring(0, 1);
                        Int32.TryParse(firstChar, out season);
                        return(season);
                    }
                    else
                    {
                        TvWord = TvWord.ToUpper();
                        if (TvWord.Contains("X"))
                        {
                            var s = TvWord.Substring(0, TvWord.IndexOf('X'));
                            Logger.Trace(string.Format("For  tvWord {0} season is {1}", TvWord, s));

                            return(Int32.Parse(s));
                        }
                        else
                        {
                            if (TvWord.Length == 4)
                            {
                                return(Int32.Parse(TvWord.Substring(0, 2)));
                            }
                        }
                    }
                }

                var regex   = new Regex(@"\w*S[0-9][0-9]", RegexOptions.IgnoreCase);
                var matches = regex.Matches(PurifiedName);
                if (matches.Count > 0)
                {
                    season = Int32.Parse(matches[0].ToString().Substring(1));
                }
            }
            catch (Exception ex)
            {
                Logger.Debug(string.Format("Could not determine Season for {0} - {1}", PurifiedName, ex.Message));
                season = 0;
            }
            return(season);
        }
Beispiel #2
0
        private int DeterminEpisode()
        {
            var episode = 0;

            try
            {
                if (!string.IsNullOrEmpty(TvWord))
                {
                    if (TvWord.Length == 3)
                    {
                        return(Int32.Parse(TvWord.Substring(1, 2)));
                    }
                    else
                    {
                        TvWord = TvWord.ToUpper();
                        if (TvWord.Contains("X"))
                        {
                            var e = TvWord.Substring(TvWord.IndexOf('X') + 1);
                            return(Int32.Parse(e));
                        }
                        else
                        {
                            if (TvWord.Length.Equals(4))
                            {
                                return(Int32.Parse(TvWord.Substring(2, 2)));
                            }
                        }
                    }
                }

                var regex   = new Regex(@"\w*E\d+", RegexOptions.IgnoreCase);
                var matches = regex.Matches(PurifiedName);
                if (matches.Count > 0)
                {
                    var candidateEpisode = matches[0].ToString().ToUpper();
                    var eSpot            = candidateEpisode.IndexOf('E');
                    var epString         = candidateEpisode.Substring(eSpot + 1);
                    episode = Int32.Parse(epString);  // drop off the E
                }
            }
            catch (FormatException ex)
            {
                Logger.Debug(string.Format("Could not determine Episode for {0} - {1}", PurifiedName, ex.Message));
            }

            return(episode);
        }