private string lookupBothDirAndTVDB(string show)
        {
            string regs = "[^\\w\\.@-]";

            var showSimple = Regex.Replace(show, regs, "");

            var showsLike = from f in Directory.GetDirectories(ShowFolder)
                            let file = new FileInfo(f).Name
                                       let simplefile = Regex.Replace(file, regs, "") // this is a minor perf issue
                                                        where simplefile.Equals(showSimple, StringComparison.InvariantCultureIgnoreCase)
                                                        select file;

            var rval = showsLike.FirstOrDefault();

            if (!string.IsNullOrEmpty(rval))
            {
                return(rval);
            }

            // make sure its on TVDB
            var showMetaData = TheTVDBData.GetDataFromXML("http://www.thetvdb.com/api/GetSeries.php?seriesname=" + show);

            System.Diagnostics.Trace.WriteLine(showMetaData.SeriesDetail.Status);

            // lets compare the RAW values, eg change (yyyy) to yyyy and remove any - or other chars

            if (showMetaData == null || string.IsNullOrEmpty(showMetaData.SeriesDetail.SeriesName))
            {
                return(null);
            }

            var lookupSimple = Regex.Replace(showMetaData.SeriesDetail.SeriesName, regs, "");

            //showSimple = Regex.Replace(showSimple, "  ", " ");
            //lookupSimple = Regex.Replace(lookupSimple, "  ", " ");

            if (!showSimple.Equals(lookupSimple, StringComparison.InvariantCultureIgnoreCase))
            {
                // we did not get an 100% match, lets hope we got the correct one
                // if we end in a YEAR then we could have got an OLD version
                if (Regex.Match(showMetaData.SeriesDetail.SeriesName, "([0-9][0-9][0-9][0-9])").Success)
                {
                    var year = Regex.Match(showMetaData.SeriesDetail.SeriesName, "([0-9][0-9][0-9][0-9])").Value;

                    // lets just see if we have a folder, this is crude
                    // TODO improve
                    var showsLikeWithYear = from f in Directory.GetDirectories(ShowFolder)
                                            let file = new FileInfo(f).Name
                                                       let filenoyear = Regex.Replace(file, "([0-9][0-9][0-9][0-9])", "")
                                                                        let simplefile = Regex.Replace(filenoyear, regs, "") // this is a minor perf issue

                                                                                         where simplefile.Equals(showSimple, StringComparison.InvariantCultureIgnoreCase)
                                                                                         select file;

                    rval = showsLikeWithYear.FirstOrDefault();
                    if (!string.IsNullOrEmpty(rval))
                    {
                        return(rval);
                    }
                }
                // No year, let it go back as is, drop through
            }
            return(showMetaData.SeriesDetail.SeriesName);
        }
Beispiel #2
0
        public void processShow(string show)
        {
            // re working
            try
            {
                var lastSeason = getLastSeason(show);
                if (lastSeason == -1)
                {
                    return;
                }
                var lastEpisode = getLastEpisode(show, lastSeason);
                if (lastEpisode == -1)
                {
                    return;
                }


                var showMetaData = TheTVDBData.GetDataFromXML(String.Format("http://www.thetvdb.com/api/GetSeries.php?seriesname={0}", show));
                showMetaData = TheTVDBData.GetDataFromXML(String.Format("http://www.thetvdb.com/api/{0}/series/{1}/all/", apiKey, showMetaData.SeriesDetail.id));
                if (showMetaData == null || showMetaData.SeriesDetail.id == "")
                {
                    return;
                }

                // New ep?
                var nextEpisode = (from e in showMetaData.Episodes
                                   where int.Parse(e.SeasonNumber) == lastSeason && int.Parse(e.EpisodeNumber) == lastEpisode + 1
                                   select e.FirstAired).FirstOrDefault();


                if (string.IsNullOrEmpty(nextEpisode)
                    //|| DateTime.ParseExact(nextEpisode, "yyyy-MM-dd", CultureInfo.InvariantCulture) > DateTime.Now
                    )
                {
                    // no next episode, or its not been on
                    // do we have a new season
                    var nextSeason = (from e in showMetaData.Episodes
                                      where int.Parse(e.SeasonNumber) == lastSeason + 1
                                      select e.FirstAired).FirstOrDefault();


                    if (!string.IsNullOrEmpty(nextSeason)
                        // && DateTime.ParseExact(nextSeason, "yyyy-MM-dd", CultureInfo.InvariantCulture) < DateTime.Now
                        )
                    {
                        // new season has be aired
                        Shows.Add(new NewShowInfo()
                        {
                            ShowID = int.Parse(showMetaData.SeriesDetail.id), ShowName = show, SuggestedSeason = lastSeason + 1, SuggestedEp = 1, NextSuggetionAired = DateTime.ParseExact(nextSeason, "yyyy-MM-dd", CultureInfo.InvariantCulture)
                        });
                        return;
                    }
                }
                else
                {
                    // ok we have a new ep
                    //if (!string.IsNullOrEmpty(nextEpisode))
                    {
                        // we have one
                        Shows.Add(new NewShowInfo()
                        {
                            ShowID = int.Parse(showMetaData.SeriesDetail.id), ShowName = show, SuggestedSeason = lastSeason, SuggestedEp = lastEpisode + 1, NextSuggetionAired = DateTime.ParseExact(nextEpisode, "yyyy-MM-dd", CultureInfo.InvariantCulture)
                        });
                        return;
                    }
                }
                // looks like its not running
                Shows.Add(new NewShowInfo()
                {
                    ShowID = int.Parse(showMetaData.SeriesDetail.id), ShowName = show, SuggestedSeason = 0, SuggestedEp = 0, NextSuggetionAired = DateTime.MinValue
                });
            }
            catch {
                // messy
            };
        }