Esempio n. 1
0
        public static TraktResponse AddShowsToWatchedHistoryEx(TraktSyncShowsWatchedEx shows)
        {
            var response = SENDToTrakt(TraktURIs.SENDWatchedHistoryAdd, shows.ToJSON());

            return(response.FromJSON <TraktResponse>());
        }
Esempio n. 2
0
        /// <summary>
        /// Returns a list of shows for watched history sync as show objects with season / episode hierarchy
        /// </summary>
        private TraktSyncShowsWatchedEx GetWatchedShowsForSyncEx(IList <MediaItem> localWatchedEpisodes, List <TraktCache.EpisodeWatched> traktEpisodesWatched)
        {
            TraktLogger.Info("Finding local episodes to add to trakt.tv watched history");

            // prepare new sync object
            var syncWatchedEpisodes = new TraktSyncShowsWatchedEx();

            syncWatchedEpisodes.Shows = new List <TraktSyncShowWatchedEx>();

            // create a unique key to lookup and search for faster
            var onlineEpisodes = traktEpisodesWatched.ToLookup(twe => CreateLookupKey(twe), twe => twe);

            foreach (var episode in localWatchedEpisodes)
            {
                string tvdbKey = CreateLookupKey(episode);

                var traktEpisode = onlineEpisodes[tvdbKey].FirstOrDefault();

                // check if not watched on trakt and add it to sync list
                if (traktEpisode == null)
                {
                    // check if we already have the show added to our sync object
                    var syncShow = syncWatchedEpisodes.Shows.FirstOrDefault(swe => swe.Ids != null && swe.Ids.Tvdb == GetSeriesTvdbId(episode));
                    if (syncShow == null)
                    {
                        // get show data from episode
                        var show = GetSeriesTvdbId(episode);
                        if (show == 0)
                        {
                            continue;
                        }

                        // create new show
                        syncShow = new TraktSyncShowWatchedEx
                        {
                            Ids = new TraktShowId
                            {
                                Tvdb = GetSeriesTvdbId(episode),
                                Imdb = GetSeriesImdbId(episode)
                            },
                            Title = GetSeriesTitle(episode),
                            //Year = show.Year.ToNullableInt32()
                        };

                        // add a new season collection to show object
                        syncShow.Seasons = new List <TraktSyncShowWatchedEx.Season>();

                        // add show to the collection
                        syncWatchedEpisodes.Shows.Add(syncShow);
                    }

                    // check if season exists in show sync object
                    var syncSeason = syncShow.Seasons.FirstOrDefault(ss => ss.Number == GetSeasonIndex(episode));
                    if (syncSeason == null)
                    {
                        // create new season
                        syncSeason = new TraktSyncShowWatchedEx.Season
                        {
                            Number = GetSeasonIndex(episode)
                        };

                        // add a new episode collection to season object
                        syncSeason.Episodes = new List <TraktSyncShowWatchedEx.Season.Episode>();

                        // add season to the show
                        syncShow.Seasons.Add(syncSeason);
                    }

                    // add episode to season
                    syncSeason.Episodes.Add(new TraktSyncShowWatchedEx.Season.Episode
                    {
                        Number    = GetEpisodeIndex(episode),
                        WatchedAt = GetLastPlayedDate(episode)
                    });
                }
            }

            return(syncWatchedEpisodes);
        }