Esempio n. 1
0
        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();
        }
Esempio n. 2
0
        public static TraktSyncResponse AddShowToWatchlistEx(TraktSyncShowEx show)
        {
            var shows = new TraktSyncShowsEx
            {
                Shows = new List<TraktSyncShowEx>() { show }
            };

            return AddShowsToWatchlistEx(shows);
        }
Esempio n. 3
0
        /// <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;
        }
Esempio n. 4
0
 public static TraktSyncResponse AddShowsToWatchlistEx(TraktSyncShowsEx shows)
 {
     var response = PostToTrakt(TraktURIs.SyncWatchlistAdd, shows.ToJSON());
     return response.FromJSON<TraktSyncResponse>();
 }
Esempio n. 5
0
 public static TraktSyncResponse AddShowsToCollectonEx(TraktSyncShowsEx shows)
 {
     var response = PostToTrakt(TraktURIs.SyncCollectionAdd, shows.ToJSON());
     return response.FromJSON<TraktSyncResponse>();
 }
Esempio n. 6
0
 public static TraktSyncResponse RemoveShowsFromWatchlistEx(TraktSyncShowsEx shows)
 {
     var response = PostToTrakt(TraktURIs.SyncWatchlistRemove, shows.ToJSON());
     return response.FromJSON<TraktSyncResponse>();
 }
Esempio n. 7
0
 public static TraktSyncResponse RemoveShowsFromCollectonEx(TraktSyncShowsEx shows)
 {
     var response = PostToTrakt(TraktURIs.SyncCollectionRemove, shows.ToJSON());
     return response.FromJSON<TraktSyncResponse>();
 }
Esempio n. 8
0
        public static TraktSyncResponse RemoveShowFromWatchlistEx(TraktSyncShowEx show)
        {
            var shows = new TraktSyncShowsEx
            {
                Shows = new List<TraktSyncShowEx>() { show }
            };

            return RemoveShowsFromWatchlistEx(shows);
        }