Example #1
0
        /// <summary>
        /// Returns a list of shows for collection sync as show objects with season / episode hierarchy
        /// </summary>
        private TraktSyncShowsCollectedEx GetCollectedShowsForSyncEx(List<DBEpisode> localCollectedEpisodes, List<TraktCache.EpisodeCollected> traktEpisodesCollected)
        {
            TraktLogger.Info("Finding local episodes to add to trakt.tv collection");

            // prepare new sync object
            var syncCollectedEpisodes = new TraktSyncShowsCollectedEx();
            syncCollectedEpisodes.Shows = new List<TraktSyncShowCollectedEx>();

            // filter out any invalid episodes or ignored series by user
            var episodes = localCollectedEpisodes.Where(lce => lce[DBOnlineEpisode.cEpisodeIndex] != "" &&
                                                               lce[DBOnlineEpisode.cEpisodeIndex] != "0").ToList();

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

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

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

                // check if not collected 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 = syncCollectedEpisodes.Shows.FirstOrDefault(sce => sce.Ids != null && sce.Ids.Tvdb == episode[DBOnlineEpisode.cSeriesID]);
                    if (syncShow == null)
                    {
                        // get show data from episode
                        var show = Helper.getCorrespondingSeries(episode[DBOnlineEpisode.cSeriesID]);
                        if (show == null) continue;

                        // create new show
                        syncShow = new TraktSyncShowCollectedEx
                        {
                            Ids = new TraktShowId
                            {
                                Tvdb = show[DBSeries.cID],
                                Imdb = BasicHandler.GetProperImdbId(show[DBOnlineSeries.cIMDBID])
                            },
                            Title = show[DBOnlineSeries.cOriginalName],
                            Year = show.Year.ToNullableInt32()
                        };

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

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

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

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

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

                    // add episode to season
                    syncSeason.Episodes.Add(new TraktSyncShowCollectedEx.Season.Episode
                    {
                        Number = episode[DBOnlineEpisode.cEpisodeIndex],
                        CollectedAt = episode[DBEpisode.cFileDateAdded].ToString().ToISO8601(0, true),
                        MediaType = GetEpisodeMediaType(episode),
                        Resolution = GetEpisodeResolution(episode),
                        AudioCodec = GetEpisodeAudioCodec(episode),
                        AudioChannels = GetEpisodeAudioChannels(episode),
                        Is3D = false
                    });
                }
            }

            return syncCollectedEpisodes;
        }
Example #2
0
 public static TraktSyncResponse AddShowsToCollectonEx(TraktSyncShowsCollectedEx shows)
 {
     var response = PostToTrakt(TraktURIs.SyncCollectionAdd, shows.ToJSON());
     return response.FromJSON<TraktSyncResponse>();
 }