コード例 #1
0
		private void GetDictTraktEpisodesAndSeasons(Trakt_Show show, ref Dictionary<int, Trakt_Episode> dictTraktEpisodes, ref Dictionary<int, int> dictTraktSeasons)
		{
			dictTraktEpisodes = new Dictionary<int, Trakt_Episode>();
			dictTraktSeasons = new Dictionary<int, int>();
			try
			{
				Trakt_EpisodeRepository repEps = new Trakt_EpisodeRepository();

				// create a dictionary of absolute episode numbers for trakt episodes
				// sort by season and episode number
				// ignore season 0, which is used for specials
				List<Trakt_Episode> eps = repEps.GetByShowID(show.Trakt_ShowID);

				List<SortPropOrFieldAndDirection> sortCriteria = new List<SortPropOrFieldAndDirection>();
				sortCriteria.Add(new SortPropOrFieldAndDirection("Season", false, SortType.eInteger));
				sortCriteria.Add(new SortPropOrFieldAndDirection("EpisodeNumber", false, SortType.eInteger));
				eps = Sorting.MultiSort<Trakt_Episode>(eps, sortCriteria);

				int i = 1;
				int lastSeason = -999;
				foreach (Trakt_Episode ep in eps)
				{
					if (ep.Season == 0) continue;

					dictTraktEpisodes[i] = ep;

					if (ep.Season != lastSeason)
						dictTraktSeasons[ep.Season] = i;

					lastSeason = ep.Season;

					i++;

				}
			}
			catch (Exception ex)
			{
				logger.ErrorException(ex.ToString(), ex);
			}
		}
コード例 #2
0
        public static void SaveExtendedShowInfoV2(TraktV2ShowExtended tvshow, List<TraktV2Season> seasons)
        {
            try
            {
                // save this data to the DB for use later
                Trakt_ImageFanartRepository repFanart = new Trakt_ImageFanartRepository();
                Trakt_ShowRepository repShows = new Trakt_ShowRepository();
                Trakt_Show show = repShows.GetByTraktSlug(tvshow.ids.slug);
                if (show == null)
                    show = new Trakt_Show();

                show.Populate(tvshow);
                repShows.Save(show);

                if (tvshow.images != null && tvshow.images.fanart != null)
                {
                    if (!string.IsNullOrEmpty(tvshow.images.fanart.full))
                    {
                        Trakt_ImageFanart fanart = repFanart.GetByShowIDAndSeason(show.Trakt_ShowID, 1);
                        if (fanart == null)
                        {
                            fanart = new Trakt_ImageFanart();
                            fanart.Enabled = 0;
                        }

                        fanart.ImageURL = tvshow.images.fanart.full;
                        fanart.Season = 1;
                        fanart.Trakt_ShowID = show.Trakt_ShowID;
                        repFanart.Save(fanart);
                    }
                }

                // save the seasons
                Trakt_SeasonRepository repSeasons = new Trakt_SeasonRepository();
                Trakt_EpisodeRepository repEpisodes = new Trakt_EpisodeRepository();
                Trakt_ImagePosterRepository repPosters = new Trakt_ImagePosterRepository();

                // delete episodes if they no longer exist on Trakt
                if (seasons.Count > 0)
                {
                    foreach (Trakt_Episode epTemp in repEpisodes.GetByShowID(show.Trakt_ShowID))
                    {
                        TraktV2Episode ep = null;
                        TraktV2Season sea = seasons.FirstOrDefault(x => x.number == epTemp.Season);
                        if (sea != null)
                            ep = sea.episodes.FirstOrDefault(x => x.number == epTemp.EpisodeNumber);

                        // if the episode is null, it means it doesn't exist on Trakt, so we should delete it
                        if (ep == null)
                            repEpisodes.Delete(epTemp.Trakt_EpisodeID);
                    }
                }

                foreach (TraktV2Season sea in seasons)
                {
                    Trakt_Season season = repSeasons.GetByShowIDAndSeason(show.Trakt_ShowID, sea.number);
                    if (season == null)
                        season = new Trakt_Season();

                    season.Season = sea.number;
                    season.URL = string.Format(TraktURIs.WebsiteSeason, show.TraktID, sea.number);
                    season.Trakt_ShowID = show.Trakt_ShowID;
                    repSeasons.Save(season);

                    if (sea.images != null && sea.images.poster != null)
                    {
                        if (!string.IsNullOrEmpty(sea.images.poster.full))
                        {
                            Trakt_ImagePoster poster = repPosters.GetByShowIDAndSeason(show.Trakt_ShowID, season.Season);
                            if (poster == null)
                            {
                                poster = new Trakt_ImagePoster();
                                poster.Enabled = 0;
                            }

                            poster.ImageURL = sea.images.poster.full;
                            poster.Season = season.Season;
                            poster.Trakt_ShowID = show.Trakt_ShowID;
                            repPosters.Save(poster);
                        }
                    }

                    if (sea.episodes != null)
                    {
                        foreach (TraktV2Episode ep in sea.episodes)
                        {
                            Trakt_Episode episode = repEpisodes.GetByShowIDSeasonAndEpisode(show.Trakt_ShowID, ep.season, ep.number);
                            if (episode == null)
                                episode = new Trakt_Episode();

                            Console.Write(ep.ids.trakt);

                            if (ep.images.screenshot != null)
                                episode.EpisodeImage = ep.images.screenshot.full;
                            else
                                episode.EpisodeImage = string.Empty;

                            episode.TraktID = ep.ids.TraktID;
                            episode.EpisodeNumber = ep.number;
                            episode.Overview = string.Empty; // this is now part of a separate API call for V2, we get this info from TvDB anyway
                            episode.Season = ep.season;
                            episode.Title = ep.title;
                            episode.URL = string.Format(TraktURIs.WebsiteEpisode, show.TraktID, ep.season, ep.number);
                            episode.Trakt_ShowID = show.Trakt_ShowID;
                            repEpisodes.Save(episode);
                        }
                    }
                }

            }
            catch (Exception ex)
            {
                logger.ErrorException("Error in TraktTVHelper.SaveExtendedShowInfo: " + ex.ToString(), ex);
            }
        }
コード例 #3
0
        public List<Contract_Trakt_Episode> GetAllTraktEpisodes(int? traktShowID)
        {
            List<Contract_Trakt_Episode> allEps = new List<Contract_Trakt_Episode>();
            try
            {
                Trakt_EpisodeRepository repEpisodes = new Trakt_EpisodeRepository();
                List<Trakt_Episode> allEpisodes = null;
                if (traktShowID.HasValue)
                    allEpisodes = repEpisodes.GetByShowID(traktShowID.Value);
                else
                    allEpisodes = repEpisodes.GetAll();

                foreach (Trakt_Episode ep in allEpisodes)
                    allEps.Add(ep.ToContract());

                return allEps;

            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
                return allEps;
            }
        }
コード例 #4
0
        public static void RemoveTraktDBEntries(Trakt_Show show)
        {
            Trakt_ShowRepository repShows = new Trakt_ShowRepository();
            CrossRef_AniDB_TraktV2Repository repXRefs = new CrossRef_AniDB_TraktV2Repository();
            Trakt_ImageFanartRepository repFanart = new Trakt_ImageFanartRepository();
            Trakt_SeasonRepository repSeasons = new Trakt_SeasonRepository();
            Trakt_EpisodeRepository repEpisodes = new Trakt_EpisodeRepository();
            Trakt_ImagePosterRepository repPosters = new Trakt_ImagePosterRepository();

            // this means Trakt has no record of this slug.
            // 1. Delete any cross ref links
            foreach (CrossRef_AniDB_TraktV2 xref in repXRefs.GetByTraktID(show.TraktID))
                repXRefs.Delete(xref.CrossRef_AniDB_TraktV2ID);

            // 2. Delete default image links

            // 3. Delete episodes
            foreach (Trakt_Episode epTemp in repEpisodes.GetByShowID(show.Trakt_ShowID))
                repEpisodes.Delete(epTemp.Trakt_EpisodeID);

            // 4. Delete fanart and posters
            foreach (Trakt_ImageFanart fanart in repFanart.GetByShowID(show.Trakt_ShowID))
                repFanart.Delete(fanart.Trakt_ImageFanartID);

            foreach (Trakt_ImagePoster poster in repPosters.GetByShowID(show.Trakt_ShowID))
                repPosters.Delete(poster.Trakt_ImagePosterID);

            // 5. Delete seasons
            foreach (Trakt_Season season in repSeasons.GetByShowID(show.Trakt_ShowID))
                repSeasons.Delete(season.Trakt_SeasonID);

            // 6. Delete the show
            repShows.Delete(show.Trakt_ShowID);
        }
コード例 #5
0
        private void PopulateTraktDetails()
        {
            try
            {
                Trakt_ShowRepository repShows = new Trakt_ShowRepository();
                Show = repShows.GetByTraktSlug(TraktID);
                if (Show == null) return;

                Trakt_EpisodeRepository repTvEps = new Trakt_EpisodeRepository();
                traktEpisodes = repTvEps.GetByShowID(Show.Trakt_ShowID);

                if (traktEpisodes.Count > 0)
                {
                    List<SortPropOrFieldAndDirection> sortCriteria = new List<SortPropOrFieldAndDirection>();
                    sortCriteria.Add(new SortPropOrFieldAndDirection("Season", false, SortType.eInteger));
                    sortCriteria.Add(new SortPropOrFieldAndDirection("EpisodeNumber", false, SortType.eInteger));
                    traktEpisodes = Sorting.MultiSort<Trakt_Episode>(traktEpisodes, sortCriteria);
                }
            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
            }
        }