Ejemplo n.º 1
0
 public CL_CrossRef_AniDB_Other_Response GetOtherAnimeCrossRefWebCache(int animeID, int crossRefType)
 {
     try
     {
         return(AzureWebAPI.Get_CrossRefAniDBOther(animeID, (CrossRefType)crossRefType));
     }
     catch (Exception ex)
     {
         logger.Error(ex, ex.ToString());
         return(null);
     }
 }
 public CL_CrossRef_AniDB_Other_Response GetOtherAnimeCrossRefWebCache(int animeID, int crossRefType)
 {
     try
     {
         if (!ServerSettings.Instance.WebCache.Enabled)
         {
             return(new CL_CrossRef_AniDB_Other_Response());
         }
         return(AzureWebAPI.Get_CrossRefAniDBOther(animeID, (CrossRefType)crossRefType));
     }
     catch (Exception ex)
     {
         logger.Error(ex, ex.ToString());
         return(null);
     }
 }
Ejemplo n.º 3
0
        public override void ProcessCommand()
        {
            logger.Info("Processing CommandRequest_MovieDBSearchAnime: {0}", AnimeID);

            try
            {
                using (var session = DatabaseFactory.SessionFactory.OpenSession())
                {
                    ISessionWrapper sessionWrapper = session.Wrap();

                    // first check if the user wants to use the web cache
                    if (ServerSettings.Instance.WebCache.Enabled && ServerSettings.Instance.WebCache.TvDB_Get)
                    {
                        try
                        {
                            Azure_CrossRef_AniDB_Other crossRef =
                                AzureWebAPI.Get_CrossRefAniDBOther(AnimeID,
                                                                   CrossRefType.MovieDB);
                            if (crossRef != null)
                            {
                                int           movieID = int.Parse(crossRef.CrossRefID);
                                MovieDB_Movie movie   = RepoFactory.MovieDb_Movie.GetByOnlineID(sessionWrapper, movieID);
                                if (movie == null)
                                {
                                    // update the info from online
                                    MovieDBHelper.UpdateMovieInfo(session, movieID, true);
                                    movie = RepoFactory.MovieDb_Movie.GetByOnlineID(movieID);
                                }

                                if (movie != null)
                                {
                                    // since we are using the web cache result, let's save it
                                    MovieDBHelper.LinkAniDBMovieDB(AnimeID, movieID, true);
                                    return;
                                }
                            }
                        }
                        catch (Exception)
                        {
                        }
                    }

                    // Use TvDB setting
                    if (!ServerSettings.Instance.TvDB.AutoLink)
                    {
                        return;
                    }

                    string          searchCriteria = string.Empty;
                    SVR_AniDB_Anime anime          = RepoFactory.AniDB_Anime.GetByAnimeID(sessionWrapper, 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 <MovieDB_Movie_Result> results = MovieDBHelper.Search(searchCriteria);
                    logger.Trace("Found {0} moviedb results for {1} on TheTvDB", results.Count, searchCriteria);
                    if (ProcessSearchResults(session, results, searchCriteria))
                    {
                        return;
                    }


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

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

                            results = MovieDBHelper.Search(title.Title);
                            logger.Trace("Found {0} moviedb 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);
            }
        }