示例#1
0
		/// <summary>
		/// Used to get a list of TvDB Series ID's that require updating
		/// </summary>
		/// <param name="tvDBIDs">The list Of Series ID's that need to be updated. Pass in an empty list</param>
		/// <returns>The current server time before the update started</returns>
		public string IncrementalTvDBUpdate(ref List<int> tvDBIDs, ref bool tvDBOnline)
		{
			// check if we have record of doing an automated update for the TvDB previously
			// if we have then we have kept a record of the server time and can do a delta update
			// otherwise we need to do a full update and keep a record of the time

			List<int> allTvDBIDs = new List<int>();
			tvDBIDs = new List<int>();
			tvDBOnline = true;

			try
			{
				CrossRef_AniDB_TvDBRepository repCrossRef = new CrossRef_AniDB_TvDBRepository();
				AnimeSeriesRepository repSeries = new AnimeSeriesRepository();

				// record the tvdb server time when we started
				// we record the time now instead of after we finish, to include any possible misses
				string currentTvDBServerTime = CurrentServerTime;
				if (currentTvDBServerTime.Length == 0)
				{
					tvDBOnline = false;
					return currentTvDBServerTime;
				}

				foreach (AnimeSeries ser in repSeries.GetAll())
				{
					List<CrossRef_AniDB_TvDBV2> xrefs = ser.GetCrossRefTvDBV2();
					if (xrefs == null) continue;

					foreach (CrossRef_AniDB_TvDBV2 xref in xrefs)
					{
						if (!allTvDBIDs.Contains(xref.TvDBID)) allTvDBIDs.Add(xref.TvDBID);
					}
				}

				// get the time we last did a TvDB update
				// if this is the first time it will be null
				// update the anidb info ever 24 hours
				ScheduledUpdateRepository repSched = new ScheduledUpdateRepository();
				ScheduledUpdate sched = repSched.GetByUpdateType((int)ScheduledUpdateType.TvDBInfo);

				string lastServerTime = "";
				if (sched != null)
				{
					TimeSpan ts = DateTime.Now - sched.LastUpdate;
					logger.Trace("Last tvdb info update was {0} hours ago", ts.TotalHours.ToString());
					if (!string.IsNullOrEmpty(sched.UpdateDetails))
						lastServerTime = sched.UpdateDetails;

					// the UpdateDetails field for this type will actually contain the last server time from
					// TheTvDB that a full update was performed
				}


				// get a list of updates from TvDB since that time
				if (lastServerTime.Length > 0)
				{
					List<int> seriesList = GetUpdatedSeriesList(lastServerTime);
					logger.Trace("{0} series have been updated since last download", seriesList.Count.ToString());
					logger.Trace("{0} TvDB series locally", allTvDBIDs.Count.ToString());

					foreach (int id in seriesList)
					{
						if (allTvDBIDs.Contains(id)) tvDBIDs.Add(id);
					}
					logger.Trace("{0} TvDB local series have been updated since last download", tvDBIDs.Count.ToString());
				}
				else
				{
					// use the full list
					tvDBIDs = allTvDBIDs;
				}

				return currentTvDBServerTime;
			}
			catch (Exception ex)
			{
				logger.ErrorException("IncrementalTvDBUpdate: "+ ex.ToString(), ex);
				return "";
			}
		}
示例#2
0
		public static void FixDuplicateTvDBLinks()
		{
			AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository();

			// delete all TvDB link duplicates
			CrossRef_AniDB_TvDBRepository repCrossRefTvDB = new CrossRef_AniDB_TvDBRepository();

			List<CrossRef_AniDB_TvDB> xrefsTvDBProcessed = new List<CrossRef_AniDB_TvDB>();
			List<CrossRef_AniDB_TvDB> xrefsTvDBToBeDeleted = new List<CrossRef_AniDB_TvDB>();

			List<CrossRef_AniDB_TvDB> xrefsTvDB = repCrossRefTvDB.GetAll();
			foreach (CrossRef_AniDB_TvDB xrefTvDB in xrefsTvDB)
			{
				bool deleteXref = false;
				foreach (CrossRef_AniDB_TvDB xref in xrefsTvDBProcessed)
				{
					if (xref.TvDBID == xrefTvDB.TvDBID && xref.TvDBSeasonNumber == xrefTvDB.TvDBSeasonNumber)
					{
						xrefsTvDBToBeDeleted.Add(xrefTvDB);
						deleteXref = true;
					}
				}
				if (!deleteXref)
					xrefsTvDBProcessed.Add(xrefTvDB);
			}


			foreach (CrossRef_AniDB_TvDB xref in xrefsTvDBToBeDeleted)
			{
				string msg = "";
				AniDB_Anime anime = repAnime.GetByAnimeID(xref.AnimeID);
				if (anime != null) msg = anime.MainTitle;

				logger.Warn("Deleting TvDB Link because of a duplicate: {0} ({1}) - {2}/{3}", xref.AnimeID, msg, xref.TvDBID, xref.TvDBSeasonNumber);
				repCrossRefTvDB.Delete(xref.CrossRef_AniDB_TvDBID);
			}
		}
示例#3
0
		public static void MigrateTvDBLinks_V1_to_V2()
		{
			try
			{
				AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository();
				TvDB_EpisodeRepository repEps = new TvDB_EpisodeRepository();

				CrossRef_AniDB_TvDBRepository repCrossRefTvDB = new CrossRef_AniDB_TvDBRepository();
				CrossRef_AniDB_TvDBV2Repository repCrossRefTvDBNew = new CrossRef_AniDB_TvDBV2Repository();

				using (var session = JMMService.SessionFactory.OpenSession())
				{
					List<CrossRef_AniDB_TvDB> xrefsTvDB = repCrossRefTvDB.GetAll();
					foreach (CrossRef_AniDB_TvDB xrefTvDB in xrefsTvDB)
					{
						CrossRef_AniDB_TvDBV2 xrefNew = new CrossRef_AniDB_TvDBV2();
						xrefNew.AnimeID = xrefTvDB.AnimeID;
						xrefNew.CrossRefSource = xrefTvDB.CrossRefSource;
						xrefNew.TvDBID = xrefTvDB.TvDBID;
						xrefNew.TvDBSeasonNumber = xrefTvDB.TvDBSeasonNumber;

						TvDB_Series ser = xrefTvDB.GetTvDBSeries(session);
						if (ser != null)
							xrefNew.TvDBTitle = ser.SeriesName;

						// determine start ep type
						if (xrefTvDB.TvDBSeasonNumber == 0)
							xrefNew.AniDBStartEpisodeType = (int)AniDBAPI.enEpisodeType.Special;
						else
							xrefNew.AniDBStartEpisodeType = (int)AniDBAPI.enEpisodeType.Episode;

						xrefNew.AniDBStartEpisodeNumber = 1;
						xrefNew.TvDBStartEpisodeNumber = 1;

						repCrossRefTvDBNew.Save(xrefNew);
					}

					// create cross ref's for specials
					foreach (CrossRef_AniDB_TvDB xrefTvDB in xrefsTvDB)
					{
						AniDB_Anime anime = repAnime.GetByAnimeID(xrefTvDB.AnimeID);
						if (anime == null) continue;

						// this anime has specials
						if (anime.EpisodeCountSpecial <= 0) continue;

						// this tvdb series has a season 0 (specials)
						List<int> seasons = repEps.GetSeasonNumbersForSeries(xrefTvDB.TvDBID);
						if (!seasons.Contains(0)) continue;

						//make sure we are not doubling up
						CrossRef_AniDB_TvDBV2 temp = repCrossRefTvDBNew.GetByTvDBID(xrefTvDB.TvDBID, 0, 1, xrefTvDB.AnimeID, (int)AniDBAPI.enEpisodeType.Special, 1);
						if (temp != null) continue;

						CrossRef_AniDB_TvDBV2 xrefNew = new CrossRef_AniDB_TvDBV2();
						xrefNew.AnimeID = xrefTvDB.AnimeID;
						xrefNew.CrossRefSource = xrefTvDB.CrossRefSource;
						xrefNew.TvDBID = xrefTvDB.TvDBID;
						xrefNew.TvDBSeasonNumber = 0;
						xrefNew.TvDBStartEpisodeNumber = 1;
						xrefNew.AniDBStartEpisodeType = (int)AniDBAPI.enEpisodeType.Special;
						xrefNew.AniDBStartEpisodeNumber = 1;

						TvDB_Series ser = xrefTvDB.GetTvDBSeries(session);
						if (ser != null)
							xrefNew.TvDBTitle = ser.SeriesName;

						repCrossRefTvDBNew.Save(xrefNew);
					}
				}

			}
			catch (Exception ex)
			{
				logger.ErrorException("Could not MigrateTvDBLinks_V1_to_V2: " + ex.ToString(), ex);
			}
		}
示例#4
0
		public Contract_Trakt_Friend ToContract()
		{
			CrossRef_AniDB_TraktRepository repXrefTrakt = new CrossRef_AniDB_TraktRepository();
			CrossRef_AniDB_TvDBRepository repXrefTvDB = new CrossRef_AniDB_TvDBRepository();
			AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository();
			AnimeSeriesRepository repSeries = new AnimeSeriesRepository();
			Trakt_FriendRepository repFriends = new Trakt_FriendRepository();
			Trakt_EpisodeRepository repEpisodes = new Trakt_EpisodeRepository();

			Trakt_Friend traktFriend = repFriends.GetByUsername(username);
			if (traktFriend == null) return null;

			Contract_Trakt_Friend contract = new Contract_Trakt_Friend();

			contract.Trakt_FriendID = traktFriend.Trakt_FriendID;
			contract.Username = username;
			contract.Full_name = full_name;
			contract.Gender = gender;
			contract.Age = age;
			contract.Location = location;
			contract.About = about;
			contract.Joined = joined;
			contract.Avatar = avatar;
			contract.Url = url;
			contract.JoinedDate = Utils.GetAniDBDateAsDate(joined);



			contract.WatchedEpisodes = new List<Contract_Trakt_WatchedEpisode>();

			// we only care about the watched episodes
			foreach (TraktTVWatched wtch in watched)
			{
				if (wtch.episode != null)
				{
					Contract_Trakt_WatchedEpisode watchedEp = new Contract_Trakt_WatchedEpisode();

					watchedEp.Watched = wtch.watched;
					watchedEp.WatchedDate = Utils.GetAniDBDateAsDate(wtch.watched);

					if (!contract.LastEpisodeWatched.HasValue)
						contract.LastEpisodeWatched = watchedEp.WatchedDate;

					if (watchedEp.WatchedDate.HasValue && watchedEp.WatchedDate > contract.LastEpisodeWatched)
						contract.LastEpisodeWatched = watchedEp.WatchedDate;

					watchedEp.AnimeSeriesID = null;

					watchedEp.Episode_Number = wtch.episode.number;
					watchedEp.Episode_Overview = wtch.episode.overview;
					watchedEp.Episode_Season = wtch.episode.season;
					watchedEp.Episode_Title = wtch.episode.title;
					watchedEp.Episode_Url = wtch.episode.url;

					

					if (wtch.episode.images != null)
						watchedEp.Episode_Screenshot = wtch.episode.images.screen;

					if (wtch.show != null)
					{
						watchedEp.TraktShow = wtch.show.ToContract();

						// find the anime and series based on the trakt id
						int? animeID = null;
						CrossRef_AniDB_Trakt xref = repXrefTrakt.GetByTraktID(wtch.show.TraktID, int.Parse(wtch.episode.season));
						if (xref != null)
							animeID = xref.AnimeID;
						else
						{
							// try the tvdb id instead
							//TODO
							/*
							CrossRef_AniDB_TvDB xrefTvDB = repXrefTvDB.GetByTvDBID(int.Parse(wtch.show.tvdb_id), int.Parse(wtch.episode.season));
							if (xrefTvDB != null)
								animeID = xrefTvDB.AnimeID;*/
						}

						if (animeID.HasValue)
						{

							AnimeSeries ser = repSeries.GetByAnimeID(animeID.Value);
							if (ser != null)
								watchedEp.AnimeSeriesID = ser.AnimeSeriesID;

							AniDB_Anime anime = repAnime.GetByAnimeID(animeID.Value);
							if (anime != null)
								watchedEp.Anime = anime.ToContract(true, null);

						}
					}

					

					contract.WatchedEpisodes.Add(watchedEp);
					break; // only show the latest show
				}

			}

			List<SortPropOrFieldAndDirection> sortCriteria = new List<SortPropOrFieldAndDirection>();
			sortCriteria.Add(new SortPropOrFieldAndDirection("WatchedDate", true, SortType.eDateTime));
			contract.WatchedEpisodes = Sorting.MultiSort<Contract_Trakt_WatchedEpisode>(contract.WatchedEpisodes, sortCriteria);

			return contract;
		}