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; }
private void MarkEpisodesAsUnWatched(DBSeries show, List<DBEpisode> episodes) { var syncThread = new Thread((o) => { // send show data as well in case tvdb ids are not available on trakt server // TraktSyncEpisodeRated object is good if we could trust trakt having the tvdb ids. // trakt is more likely to have a show tvdb id than a episode tvdb id var showEpisodes = new TraktSyncShowEx { Title = show[DBOnlineSeries.cOriginalName], Year = show.Year.ToNullableInt32(), Ids = new TraktShowId { Tvdb = show[DBSeries.cID], Imdb = BasicHandler.GetProperImdbId(show[DBOnlineSeries.cIMDBID]) } }; var seasons = new List<TraktSyncShowEx.Season>(); foreach (var episode in episodes) { if (seasons.Exists(s => s.Number == episode[DBOnlineEpisode.cSeasonIndex])) { // add the episode to the season collection seasons.First(s => s.Number == episode[DBOnlineEpisode.cSeasonIndex]) .Episodes.Add(new TraktSyncShowEx.Season.Episode { Number = episode[DBOnlineEpisode.cEpisodeIndex] }); } else { // create season and add episode to it's episode collection seasons.Add(new TraktSyncShowEx.Season { Number = episode[DBOnlineEpisode.cSeasonIndex], Episodes = new List<TraktSyncShowEx.Season.Episode> { new TraktSyncShowEx.Season.Episode { Number = episode[DBOnlineEpisode.cEpisodeIndex] } } }); } } showEpisodes.Seasons = seasons; var showSync = new TraktSyncShowsEx { Shows = new List<TraktSyncShowEx> { showEpisodes } }; // update local cache TraktCache.RemoveEpisodesFromWatchHistory(showEpisodes); var response = TraktAPI.TraktAPI.RemoveShowsFromWatchedHistoryEx(showSync); TraktLogger.LogTraktResponse(response); }) { IsBackground = true, Name = "ToggleWatched" }; syncThread.Start(); }
public static TraktSyncResponse AddShowToWatchlistEx(TraktSyncShowEx show) { var shows = new TraktSyncShowsEx { Shows = new List<TraktSyncShowEx>() { show } }; return AddShowsToWatchlistEx(shows); }
public static TraktSyncResponse RemoveShowFromWatchlistEx(TraktSyncShowEx show) { var shows = new TraktSyncShowsEx { Shows = new List<TraktSyncShowEx>() { show } }; return RemoveShowsFromWatchlistEx(shows); }
internal static void RemoveEpisodesFromWatchHistory(TraktSyncShowEx show) { if (_WatchedEpisodes == null) return; foreach (var season in show.Seasons) { foreach (var episode in season.Episodes) { RemoveEpisodeFromWatchHistory(new TraktShow { Ids = show.Ids }, new TraktEpisode { Number = episode.Number, Season = season.Number }); } } }
/// <summary> /// Use this method when no Episode Ids are available /// </summary> public static void RemoveEpisodeFromWatchList(TraktShowSummary show, TraktEpisodeSummary episode) { var episodeSync = new TraktSyncShowEx { Title = show.Title, Year = show.Year, Ids = show.Ids, Seasons = new List<TraktSyncShowEx.Season> { new TraktSyncShowEx.Season { Number = episode.Season, Episodes = new List<TraktSyncShowEx.Season.Episode> { new TraktSyncShowEx.Season.Episode { Number = episode.Number } } } } }; var syncThread = new Thread((objSyncData) => { var response = TraktAPI.TraktAPI.RemoveShowFromWatchlistEx(objSyncData as TraktSyncShowEx); TraktLogger.LogTraktResponse<TraktSyncResponse>(response); TraktCache.RemoveEpisodeFromWatchlist(show, episode); }) { IsBackground = true, Name = "RemoveWatchlist" }; syncThread.Start(episodeSync); }
/// <summary> /// Use this method when no Episode Ids are available /// </summary> public static void AddEpisodeToWatchHistory(TraktShow show, TraktEpisode episode) { var episodeSync = new TraktSyncShowEx { Title = show.Title, Year = show.Year, Ids = show.Ids, Seasons = new List<TraktSyncShowEx.Season> { new TraktSyncShowEx.Season { Number = episode.Season, Episodes = new List<TraktSyncShowEx.Season.Episode> { new TraktSyncShowEx.Season.Episode { Number = episode.Number } } } } }; var syncThread = new Thread((objSyncData) => { var response = TraktAPI.TraktAPI.AddShowToWatchedHistoryEx(objSyncData as TraktSyncShowEx); TraktLogger.LogTraktResponse<TraktSyncResponse>(response); TraktCache.AddEpisodeToWatchHistory(show, episode); }) { IsBackground = true, Name = "MarkWatched" }; syncThread.Start(episodeSync); }