Exemplo n.º 1
0
		public static void MarkEpisodeUnwatched(AnimeEpisode ep)
		{
			try
			{
				if (string.IsNullOrEmpty(ServerSettings.Trakt_Username) || string.IsNullOrEmpty(ServerSettings.Trakt_Password))
					return;

				CrossRef_AniDB_Trakt xref = ep.GetAnimeSeries().CrossRefTrakt;
				if (xref == null) return;

				Trakt_ShowRepository repShows = new Trakt_ShowRepository();
				Trakt_Show show = repShows.GetByTraktID(xref.TraktID);
				if (show == null) return;
				if (!show.TvDB_ID.HasValue) return;

				Dictionary<int, int> dictTraktSeasons = null;
				Dictionary<int, Trakt_Episode> dictTraktEpisodes = null;
				Dictionary<int, Trakt_Episode> dictTraktSpecials = null;
				GetDictTraktEpisodesAndSeasons(show, ref dictTraktEpisodes, ref dictTraktSpecials, ref dictTraktSeasons);

				TraktTVPost_ShowEpisodeUnseen postUnseen = new TraktTVPost_ShowEpisodeUnseen();
				postUnseen.episodes = new List<TraktTVSeasonEpisode>();
				postUnseen.SetCredentials();
				postUnseen.imdb_id = "";
				postUnseen.title = show.Title;
				postUnseen.year = show.Year;
				postUnseen.tvdb_id = show.TvDB_ID.Value.ToString();

				int retEpNum = -1;
				int retSeason = -1;

				GetTraktEpisodeNumber(ep, ep.GetAnimeSeries(), show, xref.TraktSeasonNumber, ref retEpNum, ref retSeason, dictTraktEpisodes, dictTraktSpecials, dictTraktSeasons);
				if (retEpNum < 0) return;

				TraktTVSeasonEpisode traktEp = new TraktTVSeasonEpisode();
				traktEp.episode = retEpNum.ToString();
				traktEp.season = retSeason.ToString();
				postUnseen.episodes.Add(traktEp);

				logger.Trace("Marking episode as unwatched on Trakt: {0} - S{1} - EP{2}", show.Title, retSeason, retEpNum);

				string urlUnseen = string.Format(Constants.TraktTvURLs.URLPostShowEpisodeUnseen, Constants.TraktTvURLs.APIKey);
				string json = JSONHelper.Serialize<TraktTVPost_ShowEpisodeUnseen>(postUnseen);

				SendData(urlUnseen, json);

			}
			catch (Exception ex)
			{
				logger.ErrorException("Error in TraktTVHelper.MarkEpisodeWatched: " + ex.ToString(), ex);
			}

		}
Exemplo n.º 2
0
		public static void SyncCollectionToTrakt_Series(AnimeSeries series)
		{
			try
			{
				// check that we have at least one user nominated for Trakt
				JMMUserRepository repUsers = new JMMUserRepository();
				List<JMMUser> traktUsers = repUsers.GetTraktUsers();
				if (traktUsers.Count == 0) return;

				string url = string.Format(Constants.TraktTvURLs.URLPostShowEpisodeLibrary, Constants.TraktTvURLs.APIKey);
				string urlSeen = string.Format(Constants.TraktTvURLs.URLPostShowEpisodeSeen, Constants.TraktTvURLs.APIKey);

				int retEpNum = 0, retSeason = 0;

				CrossRef_AniDB_Trakt xref = series.CrossRefTrakt;
				if (xref == null) return;

				Trakt_ShowRepository repShows = new Trakt_ShowRepository();
				Trakt_Show show = repShows.GetByTraktID(xref.TraktID);
				if (show == null) return;
				if (!show.TvDB_ID.HasValue) return;

				Dictionary<int, int> dictTraktSeasons = null;
				Dictionary<int, Trakt_Episode> dictTraktEpisodes = null;
				Dictionary<int, Trakt_Episode> dictTraktSpecials = null;
				GetDictTraktEpisodesAndSeasons(show, ref dictTraktEpisodes, ref dictTraktSpecials, ref dictTraktSeasons);


				TraktTVPost_ShowEpisodeLibrary postLibrary = new TraktTVPost_ShowEpisodeLibrary();
				postLibrary.episodes = new List<TraktTVSeasonEpisode>();
				postLibrary.SetCredentials();
				postLibrary.imdb_id = "";
				postLibrary.title = show.Title;
				postLibrary.year = show.Year;
				postLibrary.tvdb_id = show.TvDB_ID.Value.ToString();

				TraktTVPost_ShowEpisodeSeen postSeen = new TraktTVPost_ShowEpisodeSeen();
				postSeen.episodes = new List<TraktTVSeasonEpisode>();
				postSeen.SetCredentials();
				postSeen.imdb_id = "";
				postSeen.title = show.Title;
				postSeen.year = show.Year;
				postSeen.tvdb_id = show.TvDB_ID.Value.ToString();

				foreach (AnimeEpisode ep in series.GetAnimeEpisodes())
				{
					if (ep.GetVideoLocals().Count > 0)
					{
						retEpNum = -1;
						retSeason = -1;

						GetTraktEpisodeNumber(ep, series, show, xref.TraktSeasonNumber, ref retEpNum, ref retSeason, dictTraktEpisodes, dictTraktSpecials, dictTraktSeasons);
						if (retEpNum < 0) continue;

						TraktTVSeasonEpisode traktEp = new TraktTVSeasonEpisode();
						traktEp.episode = retEpNum.ToString();
						traktEp.season = retSeason.ToString();
						postLibrary.episodes.Add(traktEp);

						AnimeEpisode_User userRecord = null;
						foreach (JMMUser juser in traktUsers)
						{
							userRecord = ep.GetUserRecord(juser.JMMUserID);
							if (userRecord != null) break;
						}

						if (userRecord != null) 
							postSeen.episodes.Add(traktEp);
					}
				}

				if (postLibrary.episodes.Count > 0)
				{
					logger.Info("PostShowEpisodeLibrary: {0}/{1}/{2} eps", show.Title, show.TraktID, postLibrary.episodes.Count);

					string json = JSONHelper.Serialize<TraktTVPost_ShowEpisodeLibrary>(postLibrary);
					string jsonResponse = SendData(url, json);
					logger.Info("PostShowEpisodeLibrary RESPONSE: {0}", jsonResponse);
				}

				if (postSeen.episodes.Count > 0)
				{
					logger.Info("PostShowEpisodeSeen: {0}/{1}/{2} eps", show.Title, show.TraktID, postSeen.episodes.Count);

					string json = JSONHelper.Serialize<TraktTVPost_ShowEpisodeSeen>(postSeen);
					string jsonResponse = SendData(urlSeen, json);
					logger.Info("PostShowEpisodeSeen RESPONSE: {0}", jsonResponse);
				}
			}
			catch (Exception ex)
			{
				logger.ErrorException("Error in TraktTVHelper.SyncCollectionToTrakt_Series: " + ex.ToString(), ex);
			}
		}