예제 #1
0
        public TVEpisodeInfo GetShowInfo(string showName, int season, int episode)
        {
            TVEpisodeInfo retval = null;

            //  Get API key information from application config
            APIKey    = ConfigurationManager.AppSettings["Rovi_APIKey"];
            APISecret = ConfigurationManager.AppSettings["Rovi_APISecret"];

            //  If we can't find it, throw an exception
            if (string.IsNullOrEmpty(this.APIKey) || string.IsNullOrEmpty(this.APISecret))
            {
                throw new ApplicationException("Missing Rovi API key or secret.  Please include the Rovi_APIKey and Rovi_APISecret in the application config");
                return(retval);
            }

            //  The Rovi result information
            RoviVideoResult roviResult = null;

            try
            {
                //  Get the sig
                string sig = GetSig();

                //  Construct the url
                string baseUrl = string.Format("http://api.rovicorp.com/data/v1.1/video/season/{2}/episode/{3}/info?apikey={0}&sig={1}&video={4}&include=synopsis",
                                               this.APIKey,
                                               sig,
                                               season,
                                               episode,
                                               showName
                                               );

                //  Get our JSON back
                roviResult = baseUrl.GetJsonFromUrl().FromJson <RoviVideoResult>();
            }
            catch (Exception ex)
            {
                /* Not sure what to do here yet */
            }

            if (roviResult != null)
            {
                retval = new TVEpisodeInfo()
                {
                    EpisodeNumber   = episode,
                    EpisodeSummary  = roviResult.EpisodeInfo.Synopsis.SynopsisText,
                    EpisodeTitle    = roviResult.EpisodeInfo.EpisodeTitle,
                    OriginalAirDate = roviResult.EpisodeInfo.OriginalAirDate,
                    SeasonNumber    = season,
                    ShowName        = roviResult.EpisodeInfo.ShowTitle
                };
            }

            //  Return it
            return(retval);
        }
예제 #2
0
        public void GetEpisode_WithAliasValidSeasonEpisode_ReturnsTVEpisode()
        {
            //  Arrange
            ShowInformationManager showMgr = new ShowInformationManager();

            //  Act
            TVEpisodeInfo episode = showMgr.GetEpisodeInfo("Once Upon a Time", 3, 2);

            //  Assert
            Assert.AreEqual <int>(3, episode.SeasonNumber);
            Assert.AreEqual <int>(2, episode.EpisodeNumber);
            Assert.AreEqual <string>("Once Upon a Time (2011)", episode.ShowName); /* Notice this changes */
            Assert.AreEqual <string>("Lost Girl", episode.EpisodeTitle);
        }
예제 #3
0
        public void GetEpisode_WithValidAirdate_ReturnsTVEpisode()
        {
            //  Arrange
            ShowInformationManager showMgr = new ShowInformationManager();

            //  Act
            TVEpisodeInfo episode = showMgr.GetEpisodeInfo("The Colbert Report", 2013, 9, 30);

            //  Assert
            Assert.AreEqual <int>(10, episode.SeasonNumber);
            Assert.AreEqual <int>(1, episode.EpisodeNumber);
            Assert.AreEqual <string>("The Colbert Report", episode.ShowName);
            Assert.AreEqual <string>("Vince Gilligan", episode.EpisodeTitle);
        }
예제 #4
0
        public void ForFullPath_WithValidAirdateFileName_ReturnsTVEpisodeInfo()
        {
            //  Arrange
            ShowInformationManager showMgr = new ShowInformationManager();
            string filename = @"C:\Users\desparza\Downloads\The.Colbert.Report.2013.10.10.Reed.Albergotti.and.Vanessa.OConnell.HDTV.x264-LMAO.mp4";

            //  Act
            TVEpisodeInfo episode = showMgr.GetEpisodeInfoForFilename(filename);

            //  Assert
            Assert.AreEqual <int>(10, episode.SeasonNumber);
            Assert.AreEqual <int>(8, episode.EpisodeNumber);
            Assert.AreEqual <string>("The Colbert Report", episode.ShowName);
            Assert.AreEqual <string>("Reed Albergotti & Vanessa O'Connell", episode.EpisodeTitle);
        }
예제 #5
0
        public void ForFilenameAlt_WithValidSEFileName_ReturnsTVEpisodeInfo()
        {
            //  Arrange
            ShowInformationManager showMgr = new ShowInformationManager();
            string filename = "once.upon.a.time.305.hdtv-lol.mp4";

            //  Act
            TVEpisodeInfo episode = showMgr.GetEpisodeInfoForFilename(filename);

            //  Assert
            Assert.AreEqual <int>(3, episode.SeasonNumber);
            Assert.AreEqual <int>(5, episode.EpisodeNumber);
            Assert.AreEqual <string>("Once Upon a Time (2011)", episode.ShowName);
            Assert.AreEqual <string>("Good Form", episode.EpisodeTitle);
        }
예제 #6
0
        public void ForFilename_CollegeFootball_ReturnsTVEpisodeInfo()
        {
            //  Arrange
            ShowInformationManager showMgr = new ShowInformationManager();
            string filename = "Purdue Boilermakers - Ohio State Buckeyes 02.11.13.mkv";

            //  Act
            TVEpisodeInfo episode = showMgr.GetEpisodeInfoForFilename(filename);

            //  Assert
            Assert.AreEqual <int>(6, episode.SeasonNumber);
            Assert.AreEqual <int>(5, episode.EpisodeNumber);
            Assert.AreEqual <string>("Parks and Recreation", episode.ShowName);
            Assert.AreEqual <string>("Gin It Up!", episode.EpisodeTitle);
        }
예제 #7
0
        public void ForFilename_PR_ReturnsTVEpisodeInfo()
        {
            //  Arrange
            ShowInformationManager showMgr = new ShowInformationManager();
            string filename = "Parks.and.Recreation.S06E05.HDTV.x264-LOL.mp4";

            //  Act
            TVEpisodeInfo episode = showMgr.GetEpisodeInfoForFilename(filename);

            //  Assert
            Assert.AreEqual <int>(6, episode.SeasonNumber);
            Assert.AreEqual <int>(5, episode.EpisodeNumber);
            Assert.AreEqual <string>("Parks and Recreation", episode.ShowName);
            Assert.AreEqual <string>("Gin It Up!", episode.EpisodeTitle);
        }
예제 #8
0
        public void ForFilename_WithValidSEFileName_ReturnsTVEpisodeInfo()
        {
            //  Arrange
            ShowInformationManager showMgr = new ShowInformationManager();
            string filename = "Once.Upon.a.Time.S03E01.720p.HDTV.X264-DIMENSION.mkv";

            //  Act
            TVEpisodeInfo episode = showMgr.GetEpisodeInfoForFilename(filename);

            //  Assert
            Assert.AreEqual <int>(3, episode.SeasonNumber);
            Assert.AreEqual <int>(1, episode.EpisodeNumber);
            Assert.AreEqual <string>("Once Upon a Time (2011)", episode.ShowName);
            Assert.AreEqual <string>("The Heart of the Truest Believer", episode.EpisodeTitle);
        }
예제 #9
0
        public void GetEpisode_WithValidSeasonEpisode_ReturnsTVEpisode()
        {
            //  Arrange
            ShowInformationManager showMgr = new ShowInformationManager(GetRealSeasonEpisodeShowInfoProivders(),
                                                                        GetRealAirDateShowInfoProviders(),
                                                                        GetShowAliasProvider());

            //  Act
            TVEpisodeInfo episode = showMgr.GetEpisodeInfo("The Colbert Report", 10, 1);

            //  Assert
            Assert.AreEqual <int>(10, episode.SeasonNumber);
            Assert.AreEqual <int>(1, episode.EpisodeNumber);
            Assert.AreEqual <string>("The Colbert Report", episode.ShowName);
            Assert.AreEqual <string>("Vince Gilligan", episode.EpisodeTitle);
        }
예제 #10
0
        public void ForFilename_WithValidAirdateFileName_ReturnsTVEpisodeInfo()
        {
            //  Arrange
            ShowInformationManager showMgr = new ShowInformationManager(GetRealSeasonEpisodeShowInfoProivders(),
                                                                        GetRealAirDateShowInfoProviders(),
                                                                        GetShowAliasProvider());
            string filename = "Colbert.Report.2013.10.10.Reed.Albergotti.and.Vanessa.OConnell.HDTV.x264-LMAO.mp4";

            //  Act
            TVEpisodeInfo episode = showMgr.GetEpisodeInfoForFilename(filename);

            //  Assert
            Assert.AreEqual <int>(10, episode.SeasonNumber);
            Assert.AreEqual <int>(8, episode.EpisodeNumber);
            Assert.AreEqual <string>("The Colbert Report", episode.ShowName);
            Assert.AreEqual <string>("Reed Albergotti & Vanessa O'Connell", episode.EpisodeTitle);
        }
예제 #11
0
        public TVEpisodeInfo GetShowInfo(string showName, int year, int month, int day)
        {
            TVEpisodeInfo retval = null;

            logger.Debug("Getting TVDB show information for: {0} date: {1}-{2}-{3}", showName, year, month, day);

            //  If we can't find it, throw an exception
            if (string.IsNullOrEmpty(this.APIKey))
            {
                throw new ApplicationException("Missing TheTVDB API key.  Please include the TheTVDB_APIKey in the application config");
                return(retval);
            }

            //  Get the seriesId for the show
            TVDBSeriesResult series = GetSeriesForShow(showName);

            //  If we were able to get the seriesId...
            if (series != null && series.SeriesInfo != null && series.SeriesInfo.SeriesId != null)
            {
                //  Get the episode information using the seriesId, airdate
                string apiUrl = string.Format("http://thetvdb.com/api/GetEpisodeByAirDate.php?apikey={0}&seriesid={1}&airdate={2}-{3}-{4}",
                                              this.APIKey,
                                              series.SeriesInfo.SeriesId,
                                              year,
                                              month,
                                              day);

                TVDBEpisodeResult response = GetAPIResponse <TVDBEpisodeResult>(apiUrl);

                if (response != null)
                {
                    retval = new TVEpisodeInfo()
                    {
                        EpisodeNumber   = response.EpisodeInfo.EpisodeNumber,
                        EpisodeSummary  = response.EpisodeInfo.EpisodeSummary,
                        EpisodeTitle    = response.EpisodeInfo.EpisodeName,
                        OriginalAirDate = response.EpisodeInfo.OriginalAirDate,
                        SeasonNumber    = response.EpisodeInfo.SeasonNumber,
                        ShowName        = series.SeriesInfo.SeriesName
                    };
                }
            }

            return(retval);
        }
예제 #12
0
        public TVEpisodeInfo GetShowInfo(string showName, int season, int episode)
        {
            TVEpisodeInfo retval = null;

            logger.Debug("Getting TVDB show information for: {0} season {1}, episode {2}", showName, season, episode);

            //  If we can't find it, throw an exception
            if (string.IsNullOrEmpty(this.APIKey))
            {
                throw new Exception("Missing TheTVDB API key.  Please include the TheTVDB_APIKey in the application config");
                return(retval);
            }

            //  Get the seriesId for the show
            TVDBSeriesResult series = GetSeriesForShow(showName);

            //  If we were able to get the seriesId...
            if (series != null && series.SeriesInfo != null && series.SeriesInfo.SeriesId != null)
            {
                //  Get the episode information using the API key, seriesId, season, episode
                string apiUrl = string.Format("http://thetvdb.com/api/{0}/series/{1}/default/{2}/{3}",
                                              this.APIKey,
                                              series.SeriesInfo.SeriesId,
                                              season,
                                              episode);

                TVDBEpisodeResult response = GetAPIResponse <TVDBEpisodeResult>(apiUrl);

                if (response != null)
                {
                    retval = new TVEpisodeInfo()
                    {
                        EpisodeNumber   = response.EpisodeInfo.EpisodeNumber,
                        EpisodeSummary  = response.EpisodeInfo.EpisodeSummary,
                        EpisodeTitle    = response.EpisodeInfo.EpisodeName,
                        OriginalAirDate = response.EpisodeInfo.OriginalAirDate,
                        SeasonNumber    = response.EpisodeInfo.SeasonNumber,
                        ShowName        = series.SeriesInfo.SeriesName
                    };
                }
            }

            return(retval);
        }
예제 #13
0
        /// <summary>
        /// Get show information for a given show / airdate
        /// </summary>
        /// <param name="showName">The TV show name to get information for</param>
        /// <param name="year">The show airdate year</param>
        /// <param name="month">The show airdate month</param>
        /// <param name="day">The show airdate day</param>
        /// <returns></returns>
        public TVEpisodeInfo GetEpisodeInfo(string showName, int year, int month, int day)
        {
            //  Create our new episode information:
            TVEpisodeInfo retval = null;

            //  Resolve the show alias (if it exists)
            showName = ResolveShowToAlias(showName);

            foreach (var provider in ADShowInfoProviders)
            {
                retval = provider.GetShowInfo(showName, year, month, day);

                //  If we found our information, get out
                if (retval != null)
                {
                    break;
                }
            }

            return(retval);
        }
예제 #14
0
        /// <summary>
        /// Gets show information for the given filename
        /// </summary>
        /// <param name="filename">The filename to get TV show information for</param>
        /// <returns></returns>
        public TVEpisodeInfo GetEpisodeInfoForFilename(string filename)
        {
            //  Create our new episode information:
            TVEpisodeInfo retval = null;

            string parsedShowName      = string.Empty;
            int    parsedSeasonNumber  = 0;
            int    parsedEpisodeNumber = 0;

            int parsedAirdateYear  = 0;
            int parsedAirdateMonth = 1;
            int parsedAirdateDay   = 1;

            //  Make sure we're just using a filename - not an entire path:
            filename = Path.GetFileName(filename);

            /******* PARSE THE FILENAME ********/

            //  Season/Episode parsers
            Regex rxSE  = new Regex(@"^((?<series_name>.+?)[. _-]+)?s(?<season_num>\d+)[. _-]*e(?<ep_num>\d+)(([. _-]*e|-)(?<extra_ep_num>(?!(1080|720)[pi])\d+))*[. _-]*((?<extra_info>.+?)((?<![. _-])-(?<release_group>[^-]+))?)?$", RegexOptions.IgnoreCase);
            Regex rxSE2 = new Regex(@"(?<series_name>.*?)\.S?(?<season_num>\d{1,2})[Ex-]?(?<ep_num>\d{2})\.(.*)", RegexOptions.IgnoreCase);

            //  Airdate parsers
            Regex rxD = new Regex(@"^((?<series_name>.+?)[. _-]+)(?<year>\d{4}).(?<month>\d{1,2}).(?<day>\d{1,2})", RegexOptions.IgnoreCase);

            //  Process our regexes:
            var seMatch          = rxSE.Match(filename);
            var seMatch2         = rxSE2.Match(filename);
            var dMatch           = rxD.Match(filename);
            var currentParseType = ParseType.Unknown;

            //  See how we made out...
            if (seMatch.Success)
            {
                currentParseType    = ParseType.SeasonEpisode;
                parsedShowName      = Regex.Replace(seMatch.Groups["series_name"].ToString().Trim(), @"[\W]|_", " ");
                parsedSeasonNumber  = Convert.ToInt32(seMatch.Groups["season_num"].Value);
                parsedEpisodeNumber = Convert.ToInt32(seMatch.Groups["ep_num"].Value);
            }
            //  See if we have a year/month/day match:
            else if (dMatch.Success)
            {
                currentParseType   = ParseType.Airdate;
                parsedShowName     = Regex.Replace(dMatch.Groups["series_name"].ToString().Trim(), @"[\W]|_", " ");
                parsedAirdateYear  = Convert.ToInt32(dMatch.Groups["year"].Value);
                parsedAirdateMonth = Convert.ToInt32(dMatch.Groups["month"].Value);
                parsedAirdateDay   = Convert.ToInt32(dMatch.Groups["day"].Value);
            }
            //  Try an alternate S/E match
            else if (seMatch2.Success)
            {
                currentParseType    = ParseType.SeasonEpisode;
                parsedShowName      = Regex.Replace(seMatch2.Groups["series_name"].ToString().Trim(), @"[\W]|_", " ");
                parsedSeasonNumber  = Convert.ToInt32(seMatch2.Groups["season_num"].Value);
                parsedEpisodeNumber = Convert.ToInt32(seMatch2.Groups["ep_num"].Value);
            }


            //  Resolve the show alias (if it exists)
            parsedShowName = ResolveShowToAlias(parsedShowName);

            //  Based on the type of information parsed, use either
            //  season/episode data providers or airdate data providers
            switch (currentParseType)
            {
            case ParseType.SeasonEpisode:
                //  If it parses to a show/season/episode, get
                //  information from the SEShowInfoProviders
                foreach (var provider in SEShowInfoProviders)
                {
                    retval = provider.GetShowInfo(parsedShowName, parsedSeasonNumber, parsedEpisodeNumber);

                    //  If we found our information, get out
                    if (retval != null)
                    {
                        break;
                    }
                }
                break;

            case ParseType.Airdate:
                //  If it parses to show/airdate, get information
                //  from the ADShowInfoProviders
                foreach (var provider in ADShowInfoProviders)
                {
                    retval = provider.GetShowInfo(parsedShowName, parsedAirdateYear, parsedAirdateMonth, parsedAirdateDay);

                    //  If we found our information, get out
                    if (retval != null)
                    {
                        break;
                    }
                }
                break;
            }

            return(retval);
        }