Example #1
0
		/// <summary>
		/// Updates the followung
		/// 1. Series Info
		/// 2. Episode Info
		/// 3. Episode Images
		/// 4. Fanart, Poster and Wide Banner Images
		/// </summary>
		/// <param name="seriesID"></param>
		/// <param name="forceRefresh"></param>
		public void UpdateAllInfoAndImages(int seriesID, bool forceRefresh, bool downloadImages)
		{
			TvDB_EpisodeRepository repEpisodes = new TvDB_EpisodeRepository();
			TvDB_SeriesRepository repSeries = new TvDB_SeriesRepository();

			string fileName = string.Format("{0}.xml", ServerSettings.TvDB_Language);

			Dictionary<string, XmlDocument> docSeries = GetFullSeriesInfo(seriesID);
			if (docSeries.ContainsKey(fileName))
			{
				try
				{
					// update the series info
					XmlDocument xmlDoc = docSeries[fileName];
					if (xmlDoc != null)
					{
						TvDB_Series tvSeries = repSeries.GetByTvDBID(seriesID);
						if (tvSeries == null)
							tvSeries = new TvDB_Series();

						tvSeries.PopulateFromSeriesInfo(xmlDoc);
						repSeries.Save(tvSeries);
					}

					if (downloadImages)
					{
						// get all fanart, posters and wide banners
						if (docSeries.ContainsKey("banners.xml"))
						{
							XmlDocument xmlDocBanners = docSeries["banners.xml"];
							if (xmlDocBanners != null)
								DownloadAutomaticImages(xmlDocBanners, seriesID, forceRefresh);
						}
					}

					// update all the episodes and download episode images
					XmlNodeList episodeItems = xmlDoc["Data"].GetElementsByTagName("Episode");
					logger.Trace("Found {0} Episode nodes", episodeItems.Count.ToString());

					List<int> existingEpIds = new List<int>();
					foreach (XmlNode node in episodeItems)
					{
						try
						{
							

							// the episode id
							int id = int.Parse(node["id"].InnerText.Trim());
							existingEpIds.Add(id);

							TvDB_Episode ep = repEpisodes.GetByTvDBID(id);
							if (ep == null)
								ep = new TvDB_Episode();
							ep.Populate(node);
							repEpisodes.Save(ep);

							//BaseConfig.MyAnimeLog.Write("Refreshing episode info for: {0}", ep.ToString());

							if (downloadImages)
							{
								// download the image for this episode
								if (!string.IsNullOrEmpty(ep.Filename))
								{
									bool fileExists = File.Exists(ep.FullImagePath);
									if (!fileExists || (fileExists && forceRefresh))
									{
										CommandRequest_DownloadImage cmd = new CommandRequest_DownloadImage(ep.TvDB_EpisodeID, JMMImageType.TvDB_Episode, forceRefresh);
										cmd.Save();
									}
								}
							}
						}
						catch (Exception ex)
						{
							logger.ErrorException("Error in TVDBHelper.GetEpisodes: " + ex.ToString(), ex);
						}
					}

					// get all the existing tvdb episodes, to see if any have been deleted
					List<TvDB_Episode> allEps = repEpisodes.GetBySeriesID(seriesID);
					foreach (TvDB_Episode oldEp in allEps)
					{
						if (!existingEpIds.Contains(oldEp.Id))
							repEpisodes.Delete(oldEp.TvDB_EpisodeID);
					}


				}
				catch (Exception ex)
				{
					logger.ErrorException("Error in TVDBHelper.GetEpisodes: " + ex.ToString(), ex);
				}
			}
		}
Example #2
0
		public static string LinkAniDBTvDB(int animeID, enEpisodeType aniEpType, int aniEpNumber, int tvDBID, int tvSeasonNumber, int tvEpNumber, bool excludeFromWebCache)
		{
			using (var session = JMMService.SessionFactory.OpenSession())
			{
				CrossRef_AniDB_TvDBV2Repository repCrossRef = new CrossRef_AniDB_TvDBV2Repository();
				List<CrossRef_AniDB_TvDBV2> xrefTemps = repCrossRef.GetByAnimeIDEpTypeEpNumber(session, animeID, (int)aniEpType, aniEpNumber);
				if (xrefTemps != null && xrefTemps.Count > 0)
				{
                    foreach (CrossRef_AniDB_TvDBV2 xrefTemp in xrefTemps)
                    {
                        // delete the existing one if we are updating
                        TvDBHelper.RemoveLinkAniDBTvDB(xrefTemp.AnimeID, (enEpisodeType)xrefTemp.AniDBStartEpisodeType, xrefTemp.AniDBStartEpisodeNumber,
                            xrefTemp.TvDBID, xrefTemp.TvDBSeasonNumber, xrefTemp.TvDBStartEpisodeNumber);
                    }
				}

				// check if we have this information locally
				// if not download it now
				TvDB_SeriesRepository repSeries = new TvDB_SeriesRepository();
				TvDB_Series tvSeries = repSeries.GetByTvDBID(tvDBID);
				if (tvSeries == null)
				{
					// we download the series info here just so that we have the basic info in the
					// database before the queued task runs later
					tvSeries = GetSeriesInfoOnline(tvDBID);
				}

				// download and update series info, episode info and episode images
				// will also download fanart, posters and wide banners
				CommandRequest_TvDBUpdateSeriesAndEpisodes cmdSeriesEps = new CommandRequest_TvDBUpdateSeriesAndEpisodes(tvDBID, false);
				cmdSeriesEps.Save();

				CrossRef_AniDB_TvDBV2 xref = repCrossRef.GetByTvDBID(session, tvDBID, tvSeasonNumber, tvEpNumber, animeID, (int)aniEpType, aniEpNumber);
				if (xref == null)
					xref = new CrossRef_AniDB_TvDBV2();

				xref.AnimeID = animeID;
				xref.AniDBStartEpisodeType = (int)aniEpType;
				xref.AniDBStartEpisodeNumber = aniEpNumber;

				xref.TvDBID = tvDBID;
				xref.TvDBSeasonNumber = tvSeasonNumber;
				xref.TvDBStartEpisodeNumber = tvEpNumber;
				if (tvSeries != null)
					xref.TvDBTitle = tvSeries.SeriesName;

				if (excludeFromWebCache)
					xref.CrossRefSource = (int)CrossRefSource.WebCache;
				else
					xref.CrossRefSource = (int)CrossRefSource.User;

				repCrossRef.Save(xref);

				StatsCache.Instance.UpdateUsingAnime(animeID);

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

				if (!excludeFromWebCache)
				{
					CommandRequest_WebCacheSendXRefAniDBTvDB req = new CommandRequest_WebCacheSendXRefAniDBTvDB(xref.CrossRef_AniDB_TvDBV2ID);
					req.Save();
				}

                if (ServerSettings.Trakt_IsEnabled && !string.IsNullOrEmpty(ServerSettings.Trakt_AuthToken))
                {
                    CrossRef_AniDB_TraktV2Repository repTraktXrefs = new CrossRef_AniDB_TraktV2Repository();
                    if (repTraktXrefs.GetByAnimeID(animeID).Count == 0)
                    {
                        // check for Trakt associations
                        CommandRequest_TraktSearchAnime cmd2 = new CommandRequest_TraktSearchAnime(animeID, false);
                        cmd2.Save(session);
                    }
                }
            }

			return "";
		}
Example #3
0
		public static TvDB_Series GetSeriesInfoOnline(int seriesID)
		{
			try
			{
				//Init();

				string url = string.Format(Constants.TvDBURLs.urlSeriesBaseXML, URLMirror, Constants.TvDBURLs.apiKey, seriesID, ServerSettings.TvDB_Language);
				logger.Trace("GetSeriesInfo: {0}", url);

				// Search for a series
				string xmlSeries = Utils.DownloadWebPage(url);
				logger.Trace("GetSeriesInfo RESULT: {0}", xmlSeries);

				if (xmlSeries.Trim().Length == 0) return null;

				XmlDocument docSeries = new XmlDocument();
				docSeries.LoadXml(xmlSeries);

				TvDB_Series tvSeries = null;
				if (docSeries != null)
				{
					TvDB_SeriesRepository repSeries = new TvDB_SeriesRepository();
					tvSeries = repSeries.GetByTvDBID(seriesID);
					if (tvSeries == null)
						tvSeries = new TvDB_Series();

					tvSeries.PopulateFromSeriesInfo(docSeries);
					repSeries.Save(tvSeries);
				}

				return tvSeries;

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

			return null;
		}
Example #4
0
        public Contract_AniDB_AnimeCrossRefs GetCrossRefDetails(int animeID)
        {
            Contract_AniDB_AnimeCrossRefs result = new Contract_AniDB_AnimeCrossRefs();
            result.AnimeID = animeID;

            try
            {
                using (var session = JMMService.SessionFactory.OpenSession())
                {
                    TvDB_SeriesRepository repSeries = new TvDB_SeriesRepository();
                    AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository();
                    AniDB_Anime anime = repAnime.GetByAnimeID(animeID);
                    if (anime == null) return result;

                    TvDB_ImageFanartRepository repFanart = new TvDB_ImageFanartRepository();
                    TvDB_ImagePosterRepository repPosters = new TvDB_ImagePosterRepository();
                    TvDB_ImageWideBannerRepository repBanners = new TvDB_ImageWideBannerRepository();

                    // TvDB
                    foreach (CrossRef_AniDB_TvDBV2 xref in anime.GetCrossRefTvDBV2())
                    {
                        result.CrossRef_AniDB_TvDB.Add(xref.ToContract());

                        TvDB_Series ser = repSeries.GetByTvDBID(session, xref.TvDBID);
                        if (ser != null)
                            result.TvDBSeries.Add(ser.ToContract());

                        foreach (TvDB_Episode ep in anime.GetTvDBEpisodes())
                            result.TvDBEpisodes.Add(ep.ToContract());

                        foreach (TvDB_ImageFanart fanart in repFanart.GetBySeriesID(session, xref.TvDBID))
                            result.TvDBImageFanarts.Add(fanart.ToContract());

                        foreach (TvDB_ImagePoster poster in repPosters.GetBySeriesID(session, xref.TvDBID))
                            result.TvDBImagePosters.Add(poster.ToContract());

                        foreach (TvDB_ImageWideBanner banner in repBanners.GetBySeriesID(xref.TvDBID))
                            result.TvDBImageWideBanners.Add(banner.ToContract());

                    }

                    // Trakt

                    Trakt_ImageFanartRepository repTraktFanart = new Trakt_ImageFanartRepository();
                    Trakt_ImagePosterRepository repTraktPosters = new Trakt_ImagePosterRepository();
                    Trakt_ShowRepository repTrakt = new Trakt_ShowRepository();

                    foreach (CrossRef_AniDB_TraktV2 xref in anime.GetCrossRefTraktV2())
                    {
                        result.CrossRef_AniDB_Trakt.Add(xref.ToContract());

                        Trakt_Show show = repTrakt.GetByTraktSlug(session, xref.TraktID);
                        if (show != null)
                        {
                            result.TraktShows.Add(show.ToContract());

                            foreach (Trakt_ImageFanart fanart in repTraktFanart.GetByShowID(session, show.Trakt_ShowID))
                                result.TraktImageFanarts.Add(fanart.ToContract());

                            foreach (Trakt_ImagePoster poster in repTraktPosters.GetByShowID(session, show.Trakt_ShowID))
                                result.TraktImagePosters.Add(poster.ToContract());
                        }
                    }

                    // MovieDB
                    CrossRef_AniDB_Other xrefMovie = anime.GetCrossRefMovieDB();
                    if (xrefMovie == null)
                        result.CrossRef_AniDB_MovieDB = null;
                    else
                        result.CrossRef_AniDB_MovieDB = xrefMovie.ToContract();

                    MovieDB_Movie movie = anime.GetMovieDBMovie();
                    if (movie == null)
                        result.MovieDBMovie = null;
                    else
                        result.MovieDBMovie = movie.ToContract();

                    foreach (MovieDB_Fanart fanart in anime.GetMovieDBFanarts())
                    {
                        if (fanart.ImageSize.Equals(Constants.MovieDBImageSize.Original, StringComparison.InvariantCultureIgnoreCase))
                            result.MovieDBFanarts.Add(fanart.ToContract());
                    }

                    foreach (MovieDB_Poster poster in anime.GetMovieDBPosters())
                    {
                        if (poster.ImageSize.Equals(Constants.MovieDBImageSize.Original, StringComparison.InvariantCultureIgnoreCase))
                            result.MovieDBPosters.Add(poster.ToContract());
                    }

                    // MAL
                    List<CrossRef_AniDB_MAL> xrefMAL = anime.GetCrossRefMAL();
                    if (xrefMAL == null)
                        result.CrossRef_AniDB_MAL = null;
                    else
                    {
                        result.CrossRef_AniDB_MAL = new List<Contract_CrossRef_AniDB_MAL>();
                        foreach (CrossRef_AniDB_MAL xrefTemp in xrefMAL)
                            result.CrossRef_AniDB_MAL.Add(xrefTemp.ToContract());
                    }

                }
                return result;
            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
                return result;
            }
        }
Example #5
0
        public List<Contract_AnimeSeries> GetAllSeries(int userID)
        {
            AnimeSeriesRepository repSeries = new AnimeSeriesRepository();
            AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository();
            AniDB_Anime_TitleRepository repTitles = new AniDB_Anime_TitleRepository();

            //TODO: Custom Tags: Do I need to add custom tags for searches

            // get all the series
            List<Contract_AnimeSeries> seriesContractList = new List<Contract_AnimeSeries>();

            try
            {

                DateTime start = DateTime.Now;
                DateTime start2 = DateTime.Now;

                List<AnimeSeries> series = repSeries.GetAll();

                List<AniDB_Anime> animes = repAnime.GetAll();
                Dictionary<int, AniDB_Anime> dictAnimes = new Dictionary<int, AniDB_Anime>();
                foreach (AniDB_Anime anime in animes)
                    dictAnimes[anime.AnimeID] = anime;

                TimeSpan ts2 = DateTime.Now - start2; logger.Info("GetAllSeries:Anime:RawData in {0} ms", ts2.TotalMilliseconds); start2 = DateTime.Now;

                // tvdb - cross refs
                CrossRef_AniDB_TvDBV2Repository repCrossRef = new CrossRef_AniDB_TvDBV2Repository();
                List<CrossRef_AniDB_TvDBV2> allCrossRefs = repCrossRef.GetAll();
                Dictionary<int, List<CrossRef_AniDB_TvDBV2>> dictCrossRefsV2 = new Dictionary<int, List<CrossRef_AniDB_TvDBV2>>();
                foreach (CrossRef_AniDB_TvDBV2 xref in allCrossRefs)
                {
                    if (!dictCrossRefsV2.ContainsKey(xref.AnimeID))
                        dictCrossRefsV2[xref.AnimeID] = new List<CrossRef_AniDB_TvDBV2>();
                    dictCrossRefsV2[xref.AnimeID].Add(xref);
                }

                ts2 = DateTime.Now - start2; logger.Info("GetAllSeries:TvDB CrossRefs:RawData in {0} ms", ts2.TotalMilliseconds); start2 = DateTime.Now;

                // tvdb - series info
                TvDB_SeriesRepository repTvSeries = new TvDB_SeriesRepository();
                List<TvDB_Series> allTvSeries = repTvSeries.GetAll();
                Dictionary<int, TvDB_Series> dictTvSeries = new Dictionary<int, TvDB_Series>();
                foreach (TvDB_Series tvs in allTvSeries)
                    dictTvSeries[tvs.SeriesID] = tvs;

                ts2 = DateTime.Now - start2; logger.Info("GetAllSeries:TvDB:RawData in {0} ms", ts2.TotalMilliseconds); start2 = DateTime.Now;

                // moviedb
                CrossRef_AniDB_OtherRepository repOtherCrossRef = new CrossRef_AniDB_OtherRepository();
                List<CrossRef_AniDB_Other> allOtherCrossRefs = repOtherCrossRef.GetAll();
                Dictionary<int, CrossRef_AniDB_Other> dictMovieCrossRefs = new Dictionary<int, CrossRef_AniDB_Other>();
                foreach (CrossRef_AniDB_Other xref in allOtherCrossRefs)
                {
                    if (xref.CrossRefType == (int)CrossRefType.MovieDB)
                        dictMovieCrossRefs[xref.AnimeID] = xref;
                }
                ts2 = DateTime.Now - start2; logger.Info("GetAllSeries:MovieDB:RawData in {0} ms", ts2.TotalMilliseconds); start2 = DateTime.Now;

                // MAL
                CrossRef_AniDB_MALRepository repMALCrossRef = new CrossRef_AniDB_MALRepository();
                List<CrossRef_AniDB_MAL> allMALCrossRefs = repMALCrossRef.GetAll();
                Dictionary<int, List<CrossRef_AniDB_MAL>> dictMALCrossRefs = new Dictionary<int, List<CrossRef_AniDB_MAL>>();
                foreach (CrossRef_AniDB_MAL xref in allMALCrossRefs)
                {
                    if (!dictMALCrossRefs.ContainsKey(xref.AnimeID))
                        dictMALCrossRefs[xref.AnimeID] = new List<CrossRef_AniDB_MAL>();
                    dictMALCrossRefs[xref.AnimeID].Add(xref);
                }
                ts2 = DateTime.Now - start2; logger.Info("GetAllSeries:MAL:RawData in {0} ms", ts2.TotalMilliseconds); start2 = DateTime.Now;

                // user records
                AnimeSeries_UserRepository repSeriesUser = new AnimeSeries_UserRepository();
                List<AnimeSeries_User> userRecordList = repSeriesUser.GetByUserID(userID);
                Dictionary<int, AnimeSeries_User> dictUserRecords = new Dictionary<int, AnimeSeries_User>();
                foreach (AnimeSeries_User serUser in userRecordList)
                    dictUserRecords[serUser.AnimeSeriesID] = serUser;

                ts2 = DateTime.Now - start2; logger.Info("GetAllSeries:UserRecs:RawData in {0} ms", ts2.TotalMilliseconds); start2 = DateTime.Now;

                // default images
                AniDB_Anime_DefaultImageRepository repDefImages = new AniDB_Anime_DefaultImageRepository();
                List<AniDB_Anime_DefaultImage> allDefaultImages = repDefImages.GetAll();

                ts2 = DateTime.Now - start2; logger.Info("GetAllSeries:DefaultImages:RawData in {0} ms", ts2.TotalMilliseconds); start2 = DateTime.Now;

                // titles
                List<AniDB_Anime_Title> allTitles = repTitles.GetAllForLocalSeries();
                Dictionary<int, List<AniDB_Anime_Title>> dictTitles = new Dictionary<int, List<AniDB_Anime_Title>>();
                foreach (AniDB_Anime_Title atit in allTitles)
                {
                    if (!dictTitles.ContainsKey(atit.AnimeID))
                        dictTitles[atit.AnimeID] = new List<AniDB_Anime_Title>();

                    dictTitles[atit.AnimeID].Add(atit);
                }

                ts2 = DateTime.Now - start2; logger.Info("GetAllSeries:Titles:RawData in {0} ms", ts2.TotalMilliseconds); start2 = DateTime.Now;

                TimeSpan ts = DateTime.Now - start;
                logger.Info("GetAllSeries:RawData in {0} ms", ts.TotalMilliseconds);

                Dictionary<int, AniDB_Anime_DefaultImage> dictDefaultsPosters = new Dictionary<int, AniDB_Anime_DefaultImage>();
                Dictionary<int, AniDB_Anime_DefaultImage> dictDefaultsFanart = new Dictionary<int, AniDB_Anime_DefaultImage>();
                Dictionary<int, AniDB_Anime_DefaultImage> dictDefaultsWideBanner = new Dictionary<int, AniDB_Anime_DefaultImage>();

                start = DateTime.Now;

                foreach (AniDB_Anime_DefaultImage defaultImage in allDefaultImages)
                {
                    ImageSizeType sizeType = (ImageSizeType)defaultImage.ImageType;

                    if (sizeType == ImageSizeType.Fanart)
                        dictDefaultsFanart[defaultImage.AnimeID] = defaultImage;

                    if (sizeType == ImageSizeType.Poster)
                        dictDefaultsPosters[defaultImage.AnimeID] = defaultImage;

                    if (sizeType == ImageSizeType.WideBanner)
                        dictDefaultsWideBanner[defaultImage.AnimeID] = defaultImage;
                }

                foreach (AnimeSeries aser in series)
                {
                    if (!dictAnimes.ContainsKey(aser.AniDB_ID)) continue;

                    List<CrossRef_AniDB_TvDBV2> xrefs = new List<CrossRef_AniDB_TvDBV2>();
                    if (dictCrossRefsV2.ContainsKey(aser.AniDB_ID)) xrefs = dictCrossRefsV2[aser.AniDB_ID];

                    List<TvDB_Series> tvseriesV2 = new List<TvDB_Series>();
                    if (xrefs != null)
                    {
                        foreach (CrossRef_AniDB_TvDBV2 xref in xrefs)
                        {
                            if (dictTvSeries.ContainsKey(xref.TvDBID))
                                tvseriesV2.Add(dictTvSeries[xref.TvDBID]);
                        }
                    }

                    CrossRef_AniDB_Other xrefMovie = null;
                    if (dictMovieCrossRefs.ContainsKey(aser.AniDB_ID)) xrefMovie = dictMovieCrossRefs[aser.AniDB_ID];

                    List<CrossRef_AniDB_MAL> xrefMAL = null;
                    if (dictMALCrossRefs.ContainsKey(aser.AniDB_ID))
                        xrefMAL = dictMALCrossRefs[aser.AniDB_ID];

                    MovieDB_Movie movie = null;
                    if (xrefMovie != null)
                        movie = xrefMovie.GetMovieDB_Movie();

                    AnimeSeries_User userRec = null;
                    if (dictUserRecords.ContainsKey(aser.AnimeSeriesID))
                        userRec = dictUserRecords[aser.AnimeSeriesID];

                    List<AniDB_Anime_Title> titles = null;
                    if (dictTitles.ContainsKey(aser.AniDB_ID))
                        titles = dictTitles[aser.AniDB_ID];

                    AniDB_Anime_DefaultImage defPoster = null;
                    AniDB_Anime_DefaultImage defFanart = null;
                    AniDB_Anime_DefaultImage defWideBanner = null;

                    if (dictDefaultsPosters.ContainsKey(aser.AniDB_ID)) defPoster = dictDefaultsPosters[aser.AniDB_ID];
                    if (dictDefaultsFanart.ContainsKey(aser.AniDB_ID)) defFanart = dictDefaultsFanart[aser.AniDB_ID];
                    if (dictDefaultsWideBanner.ContainsKey(aser.AniDB_ID)) defWideBanner = dictDefaultsWideBanner[aser.AniDB_ID];

                    seriesContractList.Add(aser.ToContract(dictAnimes[aser.AniDB_ID], xrefs, xrefMovie, userRec, tvseriesV2, xrefMAL, true, defPoster, defFanart, defWideBanner, titles, movie));
                }

                ts = DateTime.Now - start;
                logger.Info("GetAllSeries:ProcessedData in {0} ms", ts.TotalMilliseconds);
            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
            }
            return seriesContractList;
        }
Example #6
0
		public TvDB_Series GetTvDBSeries(ISession session)
		{
			TvDB_SeriesRepository repTvSeries = new TvDB_SeriesRepository();
			return repTvSeries.GetByTvDBID(session, TvDBID);
		}
Example #7
0
        public List<TvDB_Series> GetTvDBSeries(ISession session)
        {
            TvDB_SeriesRepository repSeries = new TvDB_SeriesRepository();

            List<TvDB_Series> ret = new List<TvDB_Series>();
            List<CrossRef_AniDB_TvDBV2> xrefs = GetCrossRefTvDBV2(session);
            if (xrefs.Count == 0) return ret;

            foreach (CrossRef_AniDB_TvDBV2 xref in xrefs)
            {
                TvDB_Series ser = repSeries.GetByTvDBID(session, xref.TvDBID);
                if (ser != null) ret.Add(ser);
            }

            return ret;
        }