public static void MarkSeasonAsWatched(TraktShow show, int season) { if (!GUICommon.CheckLogin(false)) return; var seenThread = new Thread(obj => { var objShow = obj as TraktShow; var syncData = new TraktSyncShowEx { Ids = new TraktShowId { Trakt = objShow.Ids.Trakt, Imdb = objShow.Ids.Imdb.ToNullIfEmpty(), Tmdb = objShow.Ids.Tmdb, Tvdb = objShow.Ids.Tvdb, TvRage = objShow.Ids.TvRage }, Title = show.Title, Year = show.Year, Seasons = new List<TraktSyncShowEx.Season>() }; var seasonObj = new TraktSyncShowEx.Season { Number = season }; syncData.Seasons.Add(seasonObj); TraktLogger.Info("Adding all episodes in season from show to trakt.tv watched history. Title = '{0}', Year = '{1}', IMDb ID = '{2}', TVDb ID = '{3}', TMDb ID = '{4}', Season = '{5}'", show.Title, show.Year.ToLogString(), show.Ids.Imdb.ToLogString(), show.Ids.Tvdb.ToLogString(), show.Ids.Tmdb.ToLogString(), season); var response = TraktAPI.TraktAPI.AddShowToWatchedHistoryEx(syncData); TraktLogger.LogTraktResponse(response); }) { IsBackground = true, Name = "MarkWatched" }; seenThread.Start(show); }
/// <summary> /// Returns a list of shows for removal sync as show objects with season / episode hierarchy /// </summary> private TraktSyncShowsEx GetRemovedShowsForSyncEx(List<DBEpisode> localCollectedEpisodes, List<TraktCache.EpisodeCollected> traktEpisodesCollected) { TraktLogger.Info("Finding local episodes to remove from trakt.tv collection"); // prepare new sync object var syncUnCollectedEpisodes = new TraktSyncShowsEx(); syncUnCollectedEpisodes.Shows = new List<TraktSyncShowEx>(); // create a unique key to lookup and search for faster var localEpisodes = localCollectedEpisodes.ToLookup(lce => CreateLookupKey(lce), lce => lce); foreach (var episode in traktEpisodesCollected) { string tvdbKey = CreateLookupKey(episode); var localEpisode = localEpisodes[tvdbKey].FirstOrDefault(); // check if not collected locally if (localEpisode == null) { // check if we already have the show added to our sync object var syncShow = syncUnCollectedEpisodes.Shows.FirstOrDefault(suce => suce.Ids != null && suce.Ids.Trakt == episode.ShowId); if (syncShow == null) { // get show data from episode and create new show syncShow = new TraktSyncShowEx { Ids = new TraktShowId { Trakt = episode.ShowId, Imdb = episode.ShowImdbId.ToNullIfEmpty(), Tvdb = episode.ShowTvdbId }, Title = episode.ShowTitle, Year = episode.ShowYear }; // add a new season collection to show object syncShow.Seasons = new List<TraktSyncShowEx.Season>(); // add show to the collection syncUnCollectedEpisodes.Shows.Add(syncShow); } // check if season exists in show sync object var syncSeason = syncShow.Seasons.FirstOrDefault(ss => ss.Number == episode.Season); if (syncSeason == null) { // create new season syncSeason = new TraktSyncShowEx.Season { Number = episode.Season }; // add a new episode collection to season object syncSeason.Episodes = new List<TraktSyncShowEx.Season.Episode>(); // add season to the show syncShow.Seasons.Add(syncSeason); } // add episode to season syncSeason.Episodes.Add(new TraktSyncShowEx.Season.Episode { Number = episode.Number }); } } return syncUnCollectedEpisodes; }