Ejemplo n.º 1
0
 public List <Azure_CrossRef_AniDB_TvDB> GetTVDBCrossRefWebCache(int animeID, bool isAdmin)
 {
     try
     {
         return(AzureWebAPI.Get_CrossRefAniDBTvDB(animeID));
     }
     catch (Exception ex)
     {
         logger.Error(ex, ex.ToString());
         return(new List <Azure_CrossRef_AniDB_TvDB>());
     }
 }
Ejemplo n.º 2
0
        public override void ProcessCommand()
        {
            logger.Info("Processing CommandRequest_TvDBSearchAnime: {0}", AnimeID);

            try
            {
                // first check if the user wants to use the web cache
                if (ServerSettings.Instance.WebCache.TvDB_Get)
                {
                    try
                    {
                        List <Azure_CrossRef_AniDB_TvDB> cacheResults =
                            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
                            List <CrossRef_AniDB_TvDB> xrefTemp =
                                RepoFactory.CrossRef_AniDB_TvDB.GetByAnimeID(AnimeID);
                            if (xrefTemp != null && xrefTemp.Count > 0)
                            {
                                return;
                            }

                            // Add overrides for specials
                            var specialXRefs = cacheResults.Where(a => a.TvDBSeasonNumber == 0)
                                               .OrderBy(a => a.AniDBStartEpisodeType).ThenBy(a => a.AniDBStartEpisodeNumber)
                                               .ToList();
                            if (specialXRefs.Count != 0)
                            {
                                var overrides = TvDBLinkingHelper.GetSpecialsOverridesFromLegacy(specialXRefs);
                                foreach (var episodeOverride in overrides)
                                {
                                    var exists =
                                        RepoFactory.CrossRef_AniDB_TvDB_Episode_Override.GetByAniDBAndTvDBEpisodeIDs(
                                            episodeOverride.AniDBEpisodeID, episodeOverride.TvDBEpisodeID);
                                    if (exists != null)
                                    {
                                        continue;
                                    }
                                    RepoFactory.CrossRef_AniDB_TvDB_Episode_Override.Save(episodeOverride);
                                }
                            }
                            foreach (Azure_CrossRef_AniDB_TvDB xref in cacheResults)
                            {
                                TvDB_Series tvser = TvDBApiHelper.GetSeriesInfoOnline(xref.TvDBID, false);
                                if (tvser != null)
                                {
                                    logger.Trace("Found tvdb match on web cache for {0}", AnimeID);
                                    TvDBApiHelper.LinkAniDBTvDB(AnimeID, xref.TvDBID, true);
                                }
                            }
                            return;
                        }
                    }
                    catch (Exception)
                    {
                    }
                }

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

                // try to pull a link from a prequel/sequel
                var relations = RepoFactory.AniDB_Anime_Relation.GetFullLinearRelationTree(AnimeID);
                int?tvDBID    = relations.SelectMany(a => RepoFactory.CrossRef_AniDB_TvDB.GetByAnimeID(a))
                                .FirstOrDefault(a => a != null)?.TvDBID;

                if (tvDBID != null)
                {
                    TvDBApiHelper.LinkAniDBTvDB(AnimeID, tvDBID.Value, true);
                    return;
                }

                // search TvDB
                SVR_AniDB_Anime anime = RepoFactory.AniDB_Anime.GetByAnimeID(AnimeID);
                if (anime == null)
                {
                    return;
                }

                var searchCriteria = anime.MainTitle;

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


                if (results.Count != 0)
                {
                    return;
                }

                bool foundResult = false;
                foreach (AniDB_Anime_Title title in anime.GetTitles())
                {
                    if (!title.TitleType.Equals(Shoko.Models.Constants.AnimeTitleType.Official, StringComparison.InvariantCultureIgnoreCase))
                    {
                        continue;
                    }
                    if (!title.Language.Equals(Shoko.Models.Constants.AniDBLanguageType.English,
                                               StringComparison.InvariantCultureIgnoreCase) &&
                        !title.Language.Equals(Shoko.Models.Constants.AniDBLanguageType.Romaji,
                                               StringComparison.InvariantCultureIgnoreCase))
                    {
                        continue;
                    }

                    if (searchCriteria.Equals(title.Title, StringComparison.InvariantCultureIgnoreCase))
                    {
                        continue;
                    }

                    searchCriteria = title.Title;
                    results        = TvDBApiHelper.SearchSeries(searchCriteria);
                    if (results.Count > 0)
                    {
                        foundResult = true;
                    }
                    logger.Trace("Found {0} tvdb results for search on {1}", results.Count, title.Title);
                    if (ProcessSearchResults(results, title.Title))
                    {
                        return;
                    }
                }
                if (!foundResult)
                {
                    logger.Warn("Unable to find a matching TvDB series for {0}", anime.MainTitle);
                }
            }
            catch (Exception ex)
            {
                logger.Error("Error processing CommandRequest_TvDBSearchAnime: {0} - {1}", AnimeID, ex);
            }
        }
Ejemplo n.º 3
0
        public override void ProcessCommand()
        {
            logger.Info("Processing CommandRequest_TvDBSearchAnime: {0}", AnimeID);

            try
            {
                using (var session = DatabaseFactory.SessionFactory.OpenSession())
                {
                    // first check if the user wants to use the web cache
                    if (ServerSettings.WebCache_TvDB_Get)
                    {
                        try
                        {
                            List <Azure_CrossRef_AniDB_TvDB> cacheResults =
                                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
                                List <CrossRef_AniDB_TvDBV2> xrefTemp =
                                    RepoFactory.CrossRef_AniDB_TvDBV2.GetByAnimeID(AnimeID);
                                if (xrefTemp != null && xrefTemp.Count > 0)
                                {
                                    return;
                                }

                                foreach (Azure_CrossRef_AniDB_TvDB xref in cacheResults)
                                {
                                    TvDB_Series tvser = TvDBApiHelper.GetSeriesInfoOnline(xref.TvDBID, false);
                                    if (tvser != null)
                                    {
                                        logger.Trace("Found tvdb match on web cache for {0}", AnimeID);
                                        TvDBApiHelper.LinkAniDBTvDB(AnimeID,
                                                                    (EpisodeType)xref.AniDBStartEpisodeType,
                                                                    xref.AniDBStartEpisodeNumber,
                                                                    xref.TvDBID, xref.TvDBSeasonNumber,
                                                                    xref.TvDBStartEpisodeNumber, true, true);
                                    }
                                }
                                return;
                            }
                        }
                        catch (Exception)
                        {
                        }
                    }

                    if (!ServerSettings.TvDB_AutoLink)
                    {
                        return;
                    }

                    string          searchCriteria = string.Empty;
                    SVR_AniDB_Anime anime          = RepoFactory.AniDB_Anime.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 <TVDB_Series_Search_Response> results = TvDBApiHelper.SearchSeries(searchCriteria);
                    logger.Trace("Found {0} tvdb results for {1} on TheTvDB", results.Count, searchCriteria);
                    if (ProcessSearchResults(results, searchCriteria))
                    {
                        return;
                    }


                    if (results.Count == 0)
                    {
                        bool foundResult = false;
                        foreach (AniDB_Anime_Title title in anime.GetTitles())
                        {
                            if (!title.TitleType.Equals(Shoko.Models.Constants.AnimeTitleType.Official, StringComparison.InvariantCultureIgnoreCase))
                            {
                                continue;
                            }
                            if (!title.Language.Equals(Shoko.Models.Constants.AniDBLanguageType.English,
                                                       StringComparison.InvariantCultureIgnoreCase) &&
                                !title.Language.Equals(Shoko.Models.Constants.AniDBLanguageType.Romaji,
                                                       StringComparison.InvariantCultureIgnoreCase))
                            {
                                continue;
                            }

                            if (searchCriteria.Equals(title.Title, StringComparison.InvariantCultureIgnoreCase))
                            {
                                continue;
                            }

                            searchCriteria = title.Title;
                            results        = TvDBApiHelper.SearchSeries(searchCriteria);
                            if (results.Count > 0)
                            {
                                foundResult = true;
                            }
                            logger.Trace("Found {0} tvdb results for search on {1}", results.Count, title.Title);
                            if (ProcessSearchResults(results, title.Title))
                            {
                                return;
                            }
                        }
                        if (!foundResult)
                        {
                            logger.Warn("Unable to find a matching TvDB series for {0}", anime.MainTitle);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error("Error processing CommandRequest_TvDBSearchAnime: {0} - {1}", AnimeID, ex);
            }
        }
Ejemplo n.º 4
0
        public override void ProcessCommand()
        {
            logger.Info("Processing CommandRequest_TvDBSearchAnime: {0}", AnimeID);

            try
            {
                using (var session = DatabaseFactory.SessionFactory.OpenSession())
                {
                    // first check if the user wants to use the web cache
                    if (ServerSettings.WebCache_TvDB_Get)
                    {
                        try
                        {
                            List <Azure_CrossRef_AniDB_TvDB> cacheResults =
                                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
                                List <CrossRef_AniDB_TvDBV2> xrefTemp =
                                    RepoFactory.CrossRef_AniDB_TvDBV2.GetByAnimeID(AnimeID);
                                if (xrefTemp != null && xrefTemp.Count > 0)
                                {
                                    return;
                                }

                                foreach (Azure_CrossRef_AniDB_TvDB xref in cacheResults)
                                {
                                    TvDB_Series tvser = TvDBHelper.GetSeriesInfoOnline(xref.TvDBID);
                                    if (tvser != null)
                                    {
                                        logger.Trace("Found tvdb match on web cache for {0}", AnimeID);
                                        TvDBHelper.LinkAniDBTvDB(AnimeID,
                                                                 (enEpisodeType)xref.AniDBStartEpisodeType,
                                                                 xref.AniDBStartEpisodeNumber,
                                                                 xref.TvDBID, xref.TvDBSeasonNumber,
                                                                 xref.TvDBStartEpisodeNumber, true, 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 = "";
                    SVR_AniDB_Anime anime          = RepoFactory.AniDB_Anime.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 <TVDB_Series_Search_Response> results = ShokoService.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() != Shoko.Models.Constants.AnimeTitleType.Official.ToUpper())
                            {
                                continue;
                            }

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

                            results = ShokoService.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;
            }
        }