Ejemplo n.º 1
0
		public bool Init(AnimeEpisode aniepisode)
		{
			try
			{
				if (string.IsNullOrEmpty(ServerSettings.Trakt_Username) || string.IsNullOrEmpty(ServerSettings.Trakt_Password))
					return false;
				
				username = ServerSettings.Trakt_Username;
				password = Utils.CalculateSHA1(ServerSettings.Trakt_Password, Encoding.Default);

				imdb_id = "";
				AnimeSeries ser = aniepisode.GetAnimeSeries();
				if (ser == null) return false;

				CrossRef_AniDB_TraktRepository repCrossRef = new CrossRef_AniDB_TraktRepository();
				CrossRef_AniDB_Trakt xref = repCrossRef.GetByAnimeID(ser.AniDB_ID);
				if (xref == null) return false;

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

				tvdb_id = show.TvDB_ID.Value.ToString();
				title = show.Title;
				year = show.Year;

				int retEpNum = 0, retSeason = 0;
				GetTraktEpisodeNumber(aniepisode, show, xref.TraktSeasonNumber, ref retEpNum, ref retSeason);
				if (retEpNum < 0) return false;

				episode = retEpNum.ToString();
				season = retSeason.ToString();

				AniDB_Episode aniep = aniepisode.AniDB_Episode;
				if (aniep != null)
				{
					TimeSpan t = TimeSpan.FromSeconds(aniep.LengthSeconds + 14);
					int toMinutes = int.Parse(Math.Round(t.TotalMinutes).ToString());
					duration = toMinutes.ToString();
				}
				else
					duration = "25";

				progress = "100";

				plugin_version = "0.4";
				media_center_version = "1.2.0.1";
				media_center_date = "Dec 17 2010";

				
			}
			catch (Exception ex)
			{
				logger.ErrorException(ex.ToString(), ex);
				return false;
			}

			return true;
		}
Ejemplo n.º 2
0
		public Contract_CrossRef_AniDB_Trakt GetTraktCrossRef(int animeID)
		{
			try
			{
				CrossRef_AniDB_TraktRepository repCrossRef = new CrossRef_AniDB_TraktRepository();
				CrossRef_AniDB_Trakt xref = repCrossRef.GetByAnimeID(animeID);
				if (xref == null) return null;

				return xref.ToContract();
			}
			catch (Exception ex)
			{
				logger.ErrorException(ex.ToString(), ex);
				return null;
			}
		}
Ejemplo n.º 3
0
		public CrossRef_AniDB_Trakt GetCrossRefTrakt(ISession session)
		{
			CrossRef_AniDB_TraktRepository repCrossRef = new CrossRef_AniDB_TraktRepository();
			return repCrossRef.GetByAnimeID(session, this.AnimeID);
		}
Ejemplo n.º 4
0
		public static bool PostShoutShow(int animeID, string shoutText, bool isSpoiler, ref string returnMessage)
		{
			returnMessage = "";
			try
			{
				if (string.IsNullOrEmpty(ServerSettings.Trakt_Username) || string.IsNullOrEmpty(ServerSettings.Trakt_Password))
				{
					returnMessage = "Trakt credentials have not been entered";
					return false;
				}

				if (string.IsNullOrEmpty(shoutText))
				{
					returnMessage = "Please enter text for your shout";
					return false;
				}

				CrossRef_AniDB_TraktRepository repXrefTrakt = new CrossRef_AniDB_TraktRepository();
				Trakt_ShowRepository repTraktShow = new Trakt_ShowRepository();

				CrossRef_AniDB_Trakt traktXRef = repXrefTrakt.GetByAnimeID(animeID);
				if (traktXRef == null)
				{
					returnMessage = string.Format("Could not find trakt show for Anime ID: {0}", animeID);
					return false;
				}

				Trakt_Show show = repTraktShow.GetByTraktID(traktXRef.TraktID);
				if (show == null || !show.TvDB_ID.HasValue)
				{
					returnMessage = string.Format("Could not find trakt show for Anime ID: {0}", animeID);
					return false;
				}

				TraktTVPost_ShoutShow cmd = new TraktTVPost_ShoutShow();
				cmd.Init(shoutText, isSpoiler, show.TvDB_ID.Value);

				string url = string.Format(Constants.TraktTvURLs.URLPostShoutShow, Constants.TraktTvURLs.APIKey);
				logger.Trace("PostShoutShow: {0}", url);

				string json = JSONHelper.Serialize<TraktTVPost_ShoutShow>(cmd);
				string jsonResponse = SendData(url, json);

				TraktTVGenericResponse genResponse = JSONHelper.Deserialize<TraktTVGenericResponse>(jsonResponse);
				if (genResponse.IsSuccess)
				{
					returnMessage = genResponse.message;
					return true;
				}
				else
				{
					returnMessage = genResponse.error;
					return false;
				}

			}
			catch (Exception ex)
			{
				logger.ErrorException("Error in TraktTVHelper.PostShoutShow: " + ex.ToString(), ex);
				returnMessage = ex.Message;
				return false;
			}
		}
Ejemplo n.º 5
0
		// Removes all Trakt information from a series, bringing it back to a blank state.
		public static void RemoveLinkAniDBTrakt(AnimeSeries ser)
		{
			CrossRef_AniDB_TraktRepository repCrossRef = new CrossRef_AniDB_TraktRepository();
			CrossRef_AniDB_Trakt xref = repCrossRef.GetByAnimeID(ser.AniDB_ID);
			if (xref == null) return;

			repCrossRef.Delete(xref.CrossRef_AniDB_TraktID);

			CommandRequest_WebCacheDeleteXRefAniDBTrakt req = new CommandRequest_WebCacheDeleteXRefAniDBTrakt(ser.AniDB_ID);
			req.Save();
		}
Ejemplo n.º 6
0
		public static void LinkAniDBTrakt(ISession session, int animeID, string traktID, int seasonNumber, bool fromWebCache)
		{
			CrossRef_AniDB_TraktRepository repCrossRef = new CrossRef_AniDB_TraktRepository();
			CrossRef_AniDB_Trakt xrefTemp = repCrossRef.GetByTraktID(traktID, seasonNumber);
			if (xrefTemp != null)
			{
				string msg = string.Format("Not using Trakt link as one already exists {0} ({1}) - {2}", traktID, seasonNumber, animeID);
				logger.Warn(msg);
				return;
			}

			// check if we have this information locally
			// if not download it now
			Trakt_ShowRepository repShow = new Trakt_ShowRepository();
			Trakt_Show traktShow = repShow.GetByTraktID(traktID);
			if (traktShow == null)
			{
				// we download the series info here
				TraktTVShow tvshow = GetShowInfo(traktID);
				if (tvshow == null) return;
			}

			// download fanart, posters
			DownloadAllImages(traktID);

			CrossRef_AniDB_Trakt xref = repCrossRef.GetByAnimeID(animeID);
			if (xref == null)
				xref = new CrossRef_AniDB_Trakt();

			xref.AnimeID = animeID;
			if (fromWebCache)
				xref.CrossRefSource = (int)CrossRefSource.WebCache;
			else
				xref.CrossRefSource = (int)CrossRefSource.User;

			xref.TraktID = traktID;
			xref.TraktSeasonNumber = seasonNumber;
			repCrossRef.Save(xref);

			StatsCache.Instance.UpdateUsingAnime(session, animeID);

			logger.Trace("Changed trakt association: {0}", animeID);

			CommandRequest_WebCacheSendXRefAniDBTrakt req = new CommandRequest_WebCacheSendXRefAniDBTrakt(xref.CrossRef_AniDB_TraktID);
			req.Save();
		}
Ejemplo n.º 7
0
		public static List<TraktTV_ShoutGet> GetShowShouts(ISession session, int animeID)
		{
			List<TraktTV_ShoutGet> shouts = null;
			try
			{
				if (string.IsNullOrEmpty(ServerSettings.Trakt_Username) || string.IsNullOrEmpty(ServerSettings.Trakt_Password))
					return null;

				CrossRef_AniDB_TraktRepository repXrefTrakt = new CrossRef_AniDB_TraktRepository();
				CrossRef_AniDB_Trakt traktXRef = repXrefTrakt.GetByAnimeID(session, animeID);
				if (traktXRef == null) return null;

				string url = string.Format(Constants.TraktTvURLs.URLGetShowShouts, Constants.TraktTvURLs.APIKey, traktXRef.TraktID);
				logger.Trace("GetShowShouts: {0}", url);

				// Search for a series
				string json = Utils.DownloadWebPage(url);

				if (json.Trim().Length == 0) return new List<TraktTV_ShoutGet>();

				shouts = JSONHelper.Deserialize<List<TraktTV_ShoutGet>>(json);

				Trakt_FriendRepository repFriends = new Trakt_FriendRepository();
				foreach (TraktTV_ShoutGet shout in shouts)
				{
					Trakt_Friend traktFriend = repFriends.GetByUsername(session, shout.user.username);
					if (traktFriend == null)
					{
						traktFriend = new Trakt_Friend();
						traktFriend.LastAvatarUpdate = DateTime.Now;
					}

					traktFriend.Populate(shout.user);
					repFriends.Save(traktFriend);

					if (!string.IsNullOrEmpty(traktFriend.FullImagePath))
					{
						bool fileExists = File.Exists(traktFriend.FullImagePath);
						TimeSpan ts = DateTime.Now - traktFriend.LastAvatarUpdate;

						if (!fileExists || ts.TotalHours > 8)
						{
							traktFriend.LastAvatarUpdate = DateTime.Now;
							CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(traktFriend.Trakt_FriendID, JMMImageType.Trakt_Friend, true);
							cmd.Save(session);
						}
					}
				}

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

			return shouts;
		}