Exemplo n.º 1
0
        private bool ProcessSearchResults(List <TVDBSeriesSearchResult> results, string searchCriteria)
        {
            if (results.Count == 1)
            {
                // since we are using this result, lets download the info
                logger.Trace("Found 1 tvdb results for search on {0} --- Linked to {1} ({2})", searchCriteria,
                             results[0].SeriesName,
                             results[0].SeriesID);
                TvDB_Series tvser = TvDBHelper.GetSeriesInfoOnline(results[0].SeriesID);
                TvDBHelper.LinkAniDBTvDB(AnimeID, AniDBAPI.enEpisodeType.Episode, 1, results[0].SeriesID, 1, 1, true);
                return(true);
            }
            else if (results.Count > 1)
            {
                logger.Trace("Found multiple ({0}) tvdb results for search on so checking for english results {1}",
                             results.Count,
                             searchCriteria);
                foreach (TVDBSeriesSearchResult sres in results)
                {
                    if (sres.Language.Equals("en", StringComparison.InvariantCultureIgnoreCase))
                    {
                        // since we are using this result, lets download the info
                        logger.Trace("Found english result for search on {0} --- Linked to {1} ({2})", searchCriteria,
                                     sres.SeriesName,
                                     sres.SeriesID);
                        TvDB_Series tvser = TvDBHelper.GetSeriesInfoOnline(results[0].SeriesID);
                        TvDBHelper.LinkAniDBTvDB(AnimeID, AniDBAPI.enEpisodeType.Episode, 1, sres.SeriesID, 1, 1, true);
                        return(true);
                    }
                }
                logger.Trace("No english results found, so SKIPPING: {0}", searchCriteria);
            }

            return(false);
        }
Exemplo n.º 2
0
        public override void ProcessCommand()
        {
            logger.Info("Processing CommandRequest_LinkAniDBTvDB: {0}", animeID);

            try
            {
                TvDBHelper.LinkAniDBTvDB(animeID, aniEpType, aniEpNumber, tvDBID, tvSeasonNumber, tvEpNumber, excludeFromWebCache, additiveLink);
            }
            catch (Exception ex)
            {
                logger.Error("Error processing CommandRequest_LinkAniDBTvDB: {0} - {1}", animeID,
                             ex.ToString());
                return;
            }
        }
Exemplo n.º 3
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
                                List <CrossRef_AniDB_TvDBV2> xrefTemp = RepoFactory.CrossRef_AniDB_TvDBV2.GetByAnimeID(AnimeID);
                                if (xrefTemp != null && xrefTemp.Count > 0)
                                {
                                    return;
                                }

                                foreach (JMMServer.Providers.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,
                                                                 (AniDBAPI.enEpisodeType)xref.AniDBStartEpisodeType,
                                                                 xref.AniDBStartEpisodeNumber,
                                                                 xref.TvDBID, xref.TvDBSeasonNumber,
                                                                 xref.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_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 <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;
            }
        }
        private bool ProcessSearchResults(List <TVDBSeriesSearchResult> results, string searchCriteria)
        {
            if (results.Count == 1)
            {
                // since we are using this result, lets download the info
                logger.Trace("Found 1 tvdb results for search on {0} --- Linked to {1} ({2})", searchCriteria,
                             results[0].SeriesName,
                             results[0].SeriesID);
                TvDB_Series tvser = TvDBHelper.GetSeriesInfoOnline(results[0].SeriesID);
                TvDBHelper.LinkAniDBTvDB(AnimeID, AniDBAPI.enEpisodeType.Episode, 1, results[0].SeriesID, 1, 1, true);

                // add links for multiple seasons (for long shows)
                List <int> seasons = RepoFactory.TvDB_Episode.GetSeasonNumbersForSeries(results[0].SeriesID);
                foreach (int season in seasons)
                {
                    if (season < 2)
                    {
                        continue;                     // we just linked season 1, so start after (and skip specials)
                    }
                    TvDB_Episode ep = RepoFactory.TvDB_Episode.GetBySeriesIDAndSeasonNumber(results[0].SeriesID, season).Find(a => a.EpisodeNumber == 1);
                    if (ep?.AbsoluteNumber != null)
                    {
                        AddCrossRef_AniDB_TvDBV2(AnimeID, ep.AbsoluteNumber.Value, results[0].SeriesID,
                                                 season, tvser?.SeriesName ?? "");
                    }
                }
                return(true);
            }
            else if (results.Count > 1)
            {
                logger.Trace("Found multiple ({0}) tvdb results for search on so checking for english results {1}",
                             results.Count,
                             searchCriteria);
                foreach (TVDBSeriesSearchResult sres in results)
                {
                    if (sres.Language.Equals("en", StringComparison.InvariantCultureIgnoreCase))
                    {
                        // since we are using this result, lets download the info
                        logger.Trace("Found english result for search on {0} --- Linked to {1} ({2})", searchCriteria,
                                     sres.SeriesName,
                                     sres.SeriesID);
                        TvDB_Series tvser = TvDBHelper.GetSeriesInfoOnline(results[0].SeriesID);
                        TvDBHelper.LinkAniDBTvDB(AnimeID, AniDBAPI.enEpisodeType.Episode, 1, sres.SeriesID, 1, 1, true);

                        // add links for multiple seasons (for long shows)
                        List <int> seasons = RepoFactory.TvDB_Episode.GetSeasonNumbersForSeries(results[0].SeriesID);
                        foreach (int season in seasons)
                        {
                            if (season < 2)
                            {
                                continue;                     // we just linked season 1, so start after (and skip specials)
                            }
                            TvDB_Episode ep = RepoFactory.TvDB_Episode.GetBySeriesIDAndSeasonNumber(results[0].SeriesID, season).Find(a => a.EpisodeNumber == 1);
                            if (ep?.AbsoluteNumber != null)
                            {
                                AddCrossRef_AniDB_TvDBV2(AnimeID, ep.AbsoluteNumber.Value, results[0].SeriesID,
                                                         season, tvser?.SeriesName ?? "");
                            }
                        }
                        return(true);
                    }
                }
                logger.Trace("No english results found, so SKIPPING: {0}", searchCriteria);
            }

            return(false);
        }