Exemple #1
0
        /// <summary>
        /// returns a list of shows with episodes to mark as watched
        /// must send to trakt per show!
        /// </summary>
        private List<TraktEpisodeSync> GetWatchedEpisodeData(List<TraktEpisode> episodes)
        {
            var traktEpisodesSync = new List<TraktEpisodeSync>();

            // seperate episodes list into shows
            foreach (var showId in episodes.Select(e => e.TVDbId).Distinct())
            {
                var episodesInShow = episodes.Where(e => e.TVDbId == showId);
                var episodesWatchedData = new List<TraktEpisodeSync.Episode>();

                if (episodesInShow.Count() == 0) continue;

                episodesWatchedData.AddRange(from episode in episodesInShow
                                             select new TraktEpisodeSync.Episode
                                             {
                                                 EpisodeIndex = episode.Episode.ToString(),
                                                 SeasonIndex = episode.Season.ToString()
                                             });

                if (episodesWatchedData.Count() == 0) continue;

                var episodeSyncData = new TraktEpisodeSync
                {
                    UserName = AppSettings.TraktUsername,
                    Password = AppSettings.TraktPassword,
                    EpisodeList = episodesWatchedData,
                    SeriesID = showId.ToString(),
                    Title = episodesInShow.First().Title,
                    Year = episodesInShow.First().Year.ToString()
                };

                traktEpisodesSync.Add(episodeSyncData);
            }

            return traktEpisodesSync;
        }
Exemple #2
0
        /// <summary>
        /// Sends episode sync data to Trakt
        /// </summary>
        /// <param name="syncData">The sync data to send</param>
        /// <param name="mode">The sync mode to use</param>
        public static TraktResponse SyncEpisodeLibrary(TraktEpisodeSync syncData, TraktSyncModes mode)
        {
            // check that we have everything we need
            if (syncData == null || string.IsNullOrEmpty(syncData.SeriesID))
                return null;

            // serialize data to JSON and send to server
            string response = TraktWeb.Transmit(string.Format(TraktURIs.SyncEpisodeLibrary, mode.ToString()), syncData.ToJSON());

            // return success or failure
            return response.FromJSON<TraktResponse>();
        }