Exemple #1
0
 private void PopulateCrossRefs()
 {
     try
     {
         CrossRef_AniDB_TvDBV2Repository repCrossRef = new CrossRef_AniDB_TvDBV2Repository();
         crossRefTvDBV2 = repCrossRef.GetByAnimeID(AnimeID);
       
     }
     catch (Exception ex)
     {
         logger.ErrorException(ex.ToString(), ex);
     }
 }
		public override void ProcessCommand()
		{
			logger.Info("Processing CommandRequest_TraktSearchAnime: {0}", AnimeID);

			try
			{
				using (var session = JMMService.SessionFactory.OpenSession())
				{
					// first check if the user wants to use the web cache
					if (ServerSettings.WebCache_TvDB_Get)
					{
						try
						{
							CrossRef_AniDB_TraktResult crossRef = XMLService.Get_CrossRef_AniDB_Trakt(AnimeID);
							if (crossRef != null)
							{
								TraktTVShow showInfo = TraktTVHelper.GetShowInfo(crossRef.TraktID);
								if (showInfo != null)
								{
									logger.Trace("Found trakt match on web cache for {0} - id = {1}", AnimeID, showInfo.title);
									TraktTVHelper.LinkAniDBTrakt(AnimeID, crossRef.TraktID, crossRef.TraktSeasonNumber, true);
									return;
								}
							}
						}
						catch (Exception ex)
						{
							logger.ErrorException(ex.ToString(), ex);
						}
					}


					// lets try to see locally if we have a tvDB link for this anime
					// Trakt allows the use of TvDB ID's or their own Trakt ID's
					CrossRef_AniDB_TvDBV2Repository repCrossRefTvDB = new CrossRef_AniDB_TvDBV2Repository();
					List<CrossRef_AniDB_TvDBV2> xrefTvDBs = repCrossRefTvDB.GetByAnimeID(session, AnimeID);
					if (xrefTvDBs != null && xrefTvDBs.Count == 1)  //TODO this is temporary code, until trakt also allows multiple links
					{
						TraktTVShow showInfo = TraktTVHelper.GetShowInfo(xrefTvDBs[0].TvDBID);
						if (showInfo != null)
						{
							// make sure the season specified by TvDB also exists on Trakt
							Trakt_ShowRepository repShow = new Trakt_ShowRepository();
							Trakt_Show traktShow = repShow.GetByTraktID(session, showInfo.TraktID);
							if (traktShow != null)
							{
								Trakt_SeasonRepository repSeasons = new Trakt_SeasonRepository();
								Trakt_Season traktSeason = repSeasons.GetByShowIDAndSeason(session, traktShow.Trakt_ShowID, xrefTvDBs[0].TvDBSeasonNumber);
								if (traktSeason != null)
								{
									logger.Trace("Found trakt match using TvDBID locally {0} - id = {1}", AnimeID, showInfo.title);
									TraktTVHelper.LinkAniDBTrakt(AnimeID, showInfo.TraktID, traktSeason.Season, true);
									return;
								}
							}
						}
					}

					// if not lets try the tvdb web cache based on the same reasoning
					if (ServerSettings.WebCache_TvDB_Get)
					{
						List<JMMServer.Providers.Azure.CrossRef_AniDB_TvDB> cacheResults = JMMServer.Providers.Azure.AzureWebAPI.Get_CrossRefAniDBTvDB(AnimeID);
						if (cacheResults != null && cacheResults.Count > 0)
						{
							TraktTVShow showInfo = TraktTVHelper.GetShowInfo(cacheResults[0].TvDBID);
							if (showInfo != null)
							{
								// make sure the season specified by TvDB also exists on Trakt
								Trakt_ShowRepository repShow = new Trakt_ShowRepository();
								Trakt_Show traktShow = repShow.GetByTraktID(session, showInfo.TraktID);
								if (traktShow != null)
								{
									Trakt_SeasonRepository repSeasons = new Trakt_SeasonRepository();
									Trakt_Season traktSeason = repSeasons.GetByShowIDAndSeason(session, traktShow.Trakt_ShowID, cacheResults[0].TvDBSeasonNumber);
									if (traktSeason != null)
									{
										logger.Trace("Found trakt match on web cache by using TvDBID {0} - id = {1}", AnimeID, showInfo.title);
										TraktTVHelper.LinkAniDBTrakt(AnimeID, showInfo.TraktID, traktSeason.Season, true);
										return;
									}
								}
							}
						}
					}

					// finally lets try searching Trakt directly
					string searchCriteria = "";
					AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository();
					AniDB_Anime anime = repAnime.GetByAnimeID(session, AnimeID);
					if (anime == null) return;

					searchCriteria = anime.MainTitle;

					// if not wanting to use web cache, or no match found on the web cache go to TvDB directly
					List<TraktTVShow> results = TraktTVHelper.SearchShow(searchCriteria);
					logger.Trace("Found {0} trakt results for {1} ", results.Count, searchCriteria);
					if (ProcessSearchResults(session, results, searchCriteria)) return;


					if (results.Count == 0)
					{
						foreach (AniDB_Anime_Title title in anime.GetTitles(session))
						{
							if (title.TitleType.ToUpper() != Constants.AnimeTitleType.Official.ToUpper()) continue;

							if (searchCriteria.ToUpper() == title.Title.ToUpper()) continue;

							results = TraktTVHelper.SearchShow(searchCriteria);
							logger.Trace("Found {0} trakt results for search on {1}", results.Count, title.Title);
							if (ProcessSearchResults(session, results, title.Title)) return;
						}
					}
				}

			}
			catch (Exception ex)
			{
				logger.Error("Error processing CommandRequest_TvDBSearchAnime: {0} - {1}", AnimeID, ex.ToString());
				return;
			}
		}
		public override void ProcessCommand()
		{
			logger.Info("Processing CommandRequest_TraktSearchAnime: {0}", AnimeID);

			try
			{
				using (var session = JMMService.SessionFactory.OpenSession())
				{
					// first check if the user wants to use the web cache
					if (ServerSettings.WebCache_Trakt_Get)
					{
						try
						{
                            List<Contract_Azure_CrossRef_AniDB_Trakt> contracts = new List<Contract_Azure_CrossRef_AniDB_Trakt>();

                            List<JMMServer.Providers.Azure.CrossRef_AniDB_Trakt> resultsCache = JMMServer.Providers.Azure.AzureWebAPI.Get_CrossRefAniDBTrakt(AnimeID);
                            if (resultsCache != null && resultsCache.Count > 0)
                            {
                                foreach (JMMServer.Providers.Azure.CrossRef_AniDB_Trakt xref in resultsCache)
                                {

                                    TraktV2ShowExtended showInfo = TraktTVHelper.GetShowInfoV2(xref.TraktID);
                                    if (showInfo != null)
                                    {
                                        logger.Trace("Found trakt match on web cache for {0} - id = {1}", AnimeID, showInfo.title);
                                        TraktTVHelper.LinkAniDBTrakt(AnimeID, (enEpisodeType)xref.AniDBStartEpisodeType, xref.AniDBStartEpisodeNumber, 
                                            xref.TraktID, xref.TraktSeasonNumber, xref.TraktStartEpisodeNumber, true);
                                        return;
                                    }
                                }
                                
                            }
						}
						catch (Exception ex)
						{
							logger.ErrorException(ex.ToString(), ex);
						}
					}


					// lets try to see locally if we have a tvDB link for this anime
					// Trakt allows the use of TvDB ID's or their own Trakt ID's
					CrossRef_AniDB_TvDBV2Repository repCrossRefTvDB = new CrossRef_AniDB_TvDBV2Repository();
					List<CrossRef_AniDB_TvDBV2> xrefTvDBs = repCrossRefTvDB.GetByAnimeID(session, AnimeID);
					if (xrefTvDBs != null && xrefTvDBs.Count > 0) 
					{
                        foreach (CrossRef_AniDB_TvDBV2 tvXRef in xrefTvDBs)
                        {
                            // first search for this show by the TvDB ID
                            List<TraktV2SearchTvDBIDShowResult> searchResults = TraktTVHelper.SearchShowByIDV2(TraktSearchIDType.tvdb, tvXRef.TvDBID.ToString());
                            if (searchResults != null && searchResults.Count > 0)
                            {
                                // since we are searching by ID, there will only be one 'show' result
                                TraktV2Show resShow = null;
                                foreach (TraktV2SearchTvDBIDShowResult res in searchResults)
                                {
                                    if (res.ResultType == SearchIDType.Show)
                                    {
                                        resShow = res.show;
                                        break;
                                    }
                                }

                                if (resShow != null)
                                {
                                    TraktV2ShowExtended showInfo = TraktTVHelper.GetShowInfoV2(resShow.ids.slug);
                                    if (showInfo != null && showInfo.ids != null)
                                    {
                                        // make sure the season specified by TvDB also exists on Trakt
                                        Trakt_ShowRepository repShow = new Trakt_ShowRepository();
                                        Trakt_Show traktShow = repShow.GetByTraktSlug(session, showInfo.ids.slug);
                                        if (traktShow != null)
                                        {
                                            Trakt_SeasonRepository repSeasons = new Trakt_SeasonRepository();
                                            Trakt_Season traktSeason = repSeasons.GetByShowIDAndSeason(session, traktShow.Trakt_ShowID, xrefTvDBs[0].TvDBSeasonNumber);
                                            if (traktSeason != null)
                                            {
                                                logger.Trace("Found trakt match using TvDBID locally {0} - id = {1}", AnimeID, showInfo.title);
                                                TraktTVHelper.LinkAniDBTrakt(AnimeID, (AniDBAPI.enEpisodeType)tvXRef.AniDBStartEpisodeType,
                                                    tvXRef.AniDBStartEpisodeNumber, showInfo.ids.slug, tvXRef.TvDBSeasonNumber, tvXRef.TvDBStartEpisodeNumber, true);
                                                return;
                                            }
                                        }
                                    }
                                }
                            }
                        }
					}

					// finally lets try searching Trakt directly
					string searchCriteria = "";
					AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository();
					AniDB_Anime anime = repAnime.GetByAnimeID(session, AnimeID);
					if (anime == null) return;

					searchCriteria = anime.MainTitle;

					// if not wanting to use web cache, or no match found on the web cache go to TvDB directly
                    List<TraktV2SearchShowResult> results = TraktTVHelper.SearchShowV2(searchCriteria);
					logger.Trace("Found {0} trakt results for {1} ", results.Count, searchCriteria);
					if (ProcessSearchResults(session, results, searchCriteria)) return;


					if (results.Count == 0)
					{
						foreach (AniDB_Anime_Title title in anime.GetTitles(session))
						{
							if (title.TitleType.ToUpper() != Constants.AnimeTitleType.Official.ToUpper()) continue;

							if (searchCriteria.ToUpper() == title.Title.ToUpper()) continue;

                            results = TraktTVHelper.SearchShowV2(searchCriteria);
							logger.Trace("Found {0} trakt results for search on {1}", results.Count, title.Title);
							if (ProcessSearchResults(session, results, title.Title)) return;
						}
					}
				}

			}
			catch (Exception ex)
			{
				logger.Error("Error processing CommandRequest_TvDBSearchAnime: {0} - {1}", AnimeID, ex.ToString());
				return;
			}
		}
Exemple #4
0
        /// <summary>
        /// Sends the current user's TvDB links to the web cache, and then admin approves them
        /// </summary>
        /// <returns></returns>
        public string UseMyTvDBLinksWebCache(int animeID)
        {
            try
            {
                // Get all the links for this user and anime
                CrossRef_AniDB_TvDBV2Repository repCrossRef = new CrossRef_AniDB_TvDBV2Repository();
                List<CrossRef_AniDB_TvDBV2> xrefs = repCrossRef.GetByAnimeID(animeID);
                if (xrefs == null) return "No Links found to use";

                AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository();
                AniDB_Anime anime = repAnime.GetByAnimeID(animeID);
                if (anime == null) return "Anime not found";

                // make sure the user doesn't alreday have links
                List<JMMServer.Providers.Azure.CrossRef_AniDB_TvDB> results = JMMServer.Providers.Azure.AzureWebAPI.Admin_Get_CrossRefAniDBTvDB(animeID);
                bool foundLinks = false;
                if (results != null)
                {
                    foreach (JMMServer.Providers.Azure.CrossRef_AniDB_TvDB xref in results)
                    {
                        if (xref.Username.Equals(ServerSettings.AniDB_Username, StringComparison.InvariantCultureIgnoreCase))
                        {
                            foundLinks = true;
                            break;
                        }
                    }
                }
                if (foundLinks) return "Links already exist, please approve them instead";

                // send the links to the web cache
                foreach (CrossRef_AniDB_TvDBV2 xref in xrefs)
                {
                    Providers.Azure.AzureWebAPI.Send_CrossRefAniDBTvDB(xref, anime.MainTitle);
                }

                // now get the links back from the cache and approve them
                results = JMMServer.Providers.Azure.AzureWebAPI.Admin_Get_CrossRefAniDBTvDB(animeID);
                if (results != null)
                {
                    List<JMMServer.Providers.Azure.CrossRef_AniDB_TvDB> linksToApprove = new List<Providers.Azure.CrossRef_AniDB_TvDB>();
                    foreach (JMMServer.Providers.Azure.CrossRef_AniDB_TvDB xref in results)
                    {
                        if (xref.Username.Equals(ServerSettings.AniDB_Username, StringComparison.InvariantCultureIgnoreCase))
                            linksToApprove.Add(xref);
                    }

                    foreach (JMMServer.Providers.Azure.CrossRef_AniDB_TvDB xref in linksToApprove)
                    {
                        JMMServer.Providers.Azure.AzureWebAPI.Admin_Approve_CrossRefAniDBTvDB(xref.CrossRef_AniDB_TvDBId.Value);
                    }
                    return "Success";
                }
                else
                    return "Failure to send links to web cache";

            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
                return ex.Message;
            }
        }
Exemple #5
0
        /// <summary>
        /// Removes all tvdb links for one anime
        /// </summary>
        /// <param name="animeID"></param>
        /// <returns></returns>
        public string RemoveLinkAniDBTvDBForAnime(int animeID)
        {
            try
            {
                AnimeSeriesRepository repSeries = new AnimeSeriesRepository();
                AnimeSeries ser = repSeries.GetByAnimeID(animeID);

                if (ser == null) return "Could not find Series for Anime!";

                CrossRef_AniDB_TvDBV2Repository repCrossRef= new CrossRef_AniDB_TvDBV2Repository();
                List<CrossRef_AniDB_TvDBV2> xrefs = repCrossRef.GetByAnimeID(animeID);
                if (xrefs == null) return "";

                AniDB_Anime_DefaultImageRepository repDefaults = new AniDB_Anime_DefaultImageRepository();
                foreach (CrossRef_AniDB_TvDBV2 xref in xrefs)
                {
                    // check if there are default images used associated
                    List<AniDB_Anime_DefaultImage> images = repDefaults.GetByAnimeID(animeID);
                    foreach (AniDB_Anime_DefaultImage image in images)
                    {
                        if (image.ImageParentType == (int)JMMImageType.TvDB_Banner ||
                            image.ImageParentType == (int)JMMImageType.TvDB_Cover ||
                            image.ImageParentType == (int)JMMImageType.TvDB_FanArt)
                        {
                            if (image.ImageParentID == xref.TvDBID)
                                repDefaults.Delete(image.AniDB_Anime_DefaultImageID);
                        }
                    }

                    TvDBHelper.RemoveLinkAniDBTvDB(xref.AnimeID, (enEpisodeType)xref.AniDBStartEpisodeType, xref.AniDBStartEpisodeNumber,
                        xref.TvDBID, xref.TvDBSeasonNumber, xref.TvDBStartEpisodeNumber);
                }

                return "";
            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
                return ex.Message;
            }
        }
Exemple #6
0
        public List<Contract_CrossRef_AniDB_TvDBV2> GetTVDBCrossRefV2(int animeID)
        {
            try
            {
                List<Contract_CrossRef_AniDB_TvDBV2> ret = new List<Contract_CrossRef_AniDB_TvDBV2>();

                CrossRef_AniDB_TvDBV2Repository repCrossRef = new CrossRef_AniDB_TvDBV2Repository();
                List<CrossRef_AniDB_TvDBV2> xrefs = repCrossRef.GetByAnimeID(animeID);
                if (xrefs == null) return ret;

                foreach (CrossRef_AniDB_TvDBV2 xref in xrefs)
                    ret.Add(xref.ToContract());

                return ret;
            }
            catch (Exception ex)
            {
                logger.ErrorException(ex.ToString(), ex);
                return null;
            }
        }
Exemple #7
0
 public List<CrossRef_AniDB_TvDBV2> GetCrossRefTvDBV2(ISession session)
 {
     CrossRef_AniDB_TvDBV2Repository repCrossRef = new CrossRef_AniDB_TvDBV2Repository();
     return repCrossRef.GetByAnimeID(session, this.AnimeID);
 }
Exemple #8
0
        public override void ProcessCommand()
        {
            logger.Info("Processing CommandRequest_TvDBSearchAnime: {0}", AnimeID);

            try
            {
                using (var session = JMMService.SessionFactory.OpenSession())
                {
                    // first check if the user wants to use the web cache
                    if (ServerSettings.WebCache_TvDB_Get)
                    {
                        try
                        {
                            List<JMMServer.Providers.Azure.CrossRef_AniDB_TvDB> cacheResults = JMMServer.Providers.Azure.AzureWebAPI.Get_CrossRefAniDBTvDB(AnimeID);
                            if (cacheResults != null && cacheResults.Count > 0)
                            {
                                // check again to see if there are any links, user may have manually added links while
                                // this command was in the queue
                                CrossRef_AniDB_TvDBV2Repository repCrossRef = new CrossRef_AniDB_TvDBV2Repository();
                                List<CrossRef_AniDB_TvDBV2> xrefTemp = repCrossRef.GetByAnimeID(AnimeID);
                                if (xrefTemp != null && xrefTemp.Count > 0) return;

                                foreach (JMMServer.Providers.Azure.CrossRef_AniDB_TvDB xref in cacheResults)
                                {
                                    TvDB_Series tvser = TvDBHelper.GetSeriesInfoOnline(cacheResults[0].TvDBID);
                                    if (tvser != null)
                                    {
                                        logger.Trace("Found tvdb match on web cache for {0}", AnimeID);
                                        TvDBHelper.LinkAniDBTvDB(AnimeID, (AniDBAPI.enEpisodeType)cacheResults[0].AniDBStartEpisodeType, cacheResults[0].AniDBStartEpisodeNumber,
                                            cacheResults[0].TvDBID, cacheResults[0].TvDBSeasonNumber, cacheResults[0].TvDBStartEpisodeNumber, true);
                                    }
                                    else
                                    {
                                        //if we got a TvDB ID from the web cache, but couldn't find it on TheTvDB.com, it could mean 2 things
                                        //1. thetvdb.com is offline
                                        //2. the id is no longer valid
                                        // if the id is no longer valid we should remove it from the web cache
                                        /*if (TvDBHelper.ConfirmTvDBOnline())
                                        {

                                        }*/
                                    }
                                }
                                return;
                            }
                        }
                        catch (Exception)
                        {
                        }
                    }

                    string searchCriteria = "";
                    AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository();
                    AniDB_Anime anime = repAnime.GetByAnimeID(AnimeID);
                    if (anime == null) return;

                    searchCriteria = anime.MainTitle;

                    // if not wanting to use web cache, or no match found on the web cache go to TvDB directly
                    List<TVDBSeriesSearchResult> results = JMMService.TvdbHelper.SearchSeries(searchCriteria);
                    logger.Trace("Found {0} tvdb results for {1} on TheTvDB", results.Count, searchCriteria);
                    if (ProcessSearchResults(results, searchCriteria)) return;

                    if (results.Count == 0)
                    {
                        foreach (AniDB_Anime_Title title in anime.GetTitles())
                        {
                            if (title.TitleType.ToUpper() != Constants.AnimeTitleType.Official.ToUpper()) continue;

                            if (searchCriteria.ToUpper() == title.Title.ToUpper()) continue;

                            results = JMMService.TvdbHelper.SearchSeries(title.Title);
                            logger.Trace("Found {0} tvdb results for search on {1}", results.Count, title.Title);
                            if (ProcessSearchResults(results, title.Title)) return;
                        }
                    }
                }

            }
            catch (Exception ex)
            {
                logger.Error("Error processing CommandRequest_TvDBSearchAnime: {0} - {1}", AnimeID, ex.ToString());
                return;
            }
        }