private bool ProcessSearchResults(ISession session, List <TraktTVShow> results, string searchCriteria)
        {
            if (results.Count == 1)
            {
                // since we are using this result, lets download the info
                logger.Trace("Found 1 trakt results for search on {0} --- Linked to {1} ({2})", searchCriteria, results[0].title, results[0].TraktID);
                TraktTVShow showInfo = TraktTVHelper.GetShowInfo(results[0].TraktID);
                if (showInfo != null)
                {
                    TraktTVHelper.LinkAniDBTrakt(session, AnimeID, showInfo.TraktID, 1, false);
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 2
0
        public override void Run(IProgress <ICommand> progress = null)
        {
            logger.Info("Processing CommandRequest_LinkAniDBTrakt: {0}", AnimeID);

            try
            {
                ReportInit(progress);
                TraktTVHelper.LinkAniDBTrakt(AnimeID, TraktID, AdditiveLink);
                ReportUpdate(progress, 50);
                SVR_AniDB_Anime.UpdateStatsByAnimeID(AnimeID);
                ReportFinish(progress);
            }
            catch (Exception ex)
            {
                ReportError(progress, $"Error processing CommandRequest_LinkAniDBTrakt: {AnimeID} - {TraktID} - {ex}", ex);
            }
        }
        public string LinkAniDBTrakt(int animeID, int aniEpType, int aniEpNumber, string traktID, int seasonNumber,
                                     int traktEpNumber, int?crossRef_AniDB_TraktV2ID)
        {
            try
            {
                if (crossRef_AniDB_TraktV2ID.HasValue)
                {
                    CrossRef_AniDB_TraktV2 xrefTemp =
                        RepoFactory.CrossRef_AniDB_TraktV2.GetByID(crossRef_AniDB_TraktV2ID.Value);
                    // delete the existing one if we are updating
                    TraktTVHelper.RemoveLinkAniDBTrakt(xrefTemp.AnimeID, (EpisodeType)xrefTemp.AniDBStartEpisodeType,
                                                       xrefTemp.AniDBStartEpisodeNumber,
                                                       xrefTemp.TraktID, xrefTemp.TraktSeasonNumber, xrefTemp.TraktStartEpisodeNumber);
                }

                CrossRef_AniDB_TraktV2 xref = RepoFactory.CrossRef_AniDB_TraktV2.GetByTraktID(traktID, seasonNumber,
                                                                                              traktEpNumber, animeID,
                                                                                              aniEpType,
                                                                                              aniEpNumber);
                if (xref != null)
                {
                    string msg = string.Format("You have already linked Anime ID {0} to this Trakt show/season/ep",
                                               xref.AnimeID);
                    SVR_AniDB_Anime anime = RepoFactory.AniDB_Anime.GetByAnimeID(xref.AnimeID);
                    if (anime != null)
                    {
                        msg = string.Format("You have already linked Anime {0} ({1}) to this Trakt show/season/ep",
                                            anime.MainTitle,
                                            xref.AnimeID);
                    }
                    return(msg);
                }

                return(TraktTVHelper.LinkAniDBTrakt(animeID, (EpisodeType)aniEpType, aniEpNumber, traktID,
                                                    seasonNumber,
                                                    traktEpNumber, false));
            }
            catch (Exception ex)
            {
                logger.Error(ex, ex.ToString());
                return(ex.Message);
            }
        }
        private bool ProcessSearchResults(ISession session, List <TraktV2SearchShowResult> results, string searchCriteria)
        {
            if (results.Count == 1)
            {
                if (results[0].show != null)
                {
                    // since we are using this result, lets download the info
                    logger.Trace("Found 1 trakt results for search on {0} --- Linked to {1} ({2})", searchCriteria, results[0].show.Title, results[0].show.ids.slug);
                    TraktV2ShowExtended showInfo = TraktTVHelper.GetShowInfoV2(results[0].show.ids.slug);
                    if (showInfo != null)
                    {
                        TraktTVHelper.LinkAniDBTrakt(session, AnimeID, AniDBAPI.enEpisodeType.Episode, 1, results[0].show.ids.slug, 1, 1, true);
                        return(true);
                    }
                }
            }

            return(false);
        }
Esempio n. 5
0
        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;
            }
        }
        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 = DatabaseFactory.SessionFactory.OpenSession())
                {
                    ISessionWrapper sessionWrapper = session.Wrap();
                    bool            doReturn       = false;

                    // first check if the user wants to use the web cache
                    if (ServerSettings.WebCache_Trakt_Get)
                    {
                        try
                        {
                            List <Azure_CrossRef_AniDB_Trakt> contracts =
                                new List <Azure_CrossRef_AniDB_Trakt>();

                            List <Azure_CrossRef_AniDB_Trakt> resultsCache =
                                AzureWebAPI.Get_CrossRefAniDBTrakt(AnimeID);
                            if (resultsCache != null && resultsCache.Count > 0)
                            {
                                foreach (Azure_CrossRef_AniDB_Trakt xref in resultsCache)
                                {
                                    TraktV2ShowExtended showInfo = TraktTVHelper.GetShowInfoV2(xref.TraktID);
                                    if (showInfo == null)
                                    {
                                        continue;
                                    }

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


                    // 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
                    List <CrossRef_AniDB_TvDBV2> xrefTvDBs = RepoFactory.CrossRef_AniDB_TvDBV2.GetByAnimeID(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)
                            {
                                continue;
                            }
                            // 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)
                                {
                                    continue;
                                }
                                resShow = res.show;
                                break;
                            }

                            if (resShow == null)
                            {
                                continue;
                            }

                            TraktV2ShowExtended showInfo = TraktTVHelper.GetShowInfoV2(resShow.ids.slug);
                            if (showInfo?.ids == null)
                            {
                                continue;
                            }

                            // make sure the season specified by TvDB also exists on Trakt
                            Trakt_Show traktShow =
                                RepoFactory.Trakt_Show.GetByTraktSlug(session, showInfo.ids.slug);
                            if (traktShow == null)
                            {
                                continue;
                            }

                            Trakt_Season traktSeason = RepoFactory.Trakt_Season.GetByShowIDAndSeason(
                                session,
                                traktShow.Trakt_ShowID,
                                tvXRef.TvDBSeasonNumber);
                            if (traktSeason == null)
                            {
                                continue;
                            }

                            logger.Trace("Found trakt match using TvDBID locally {0} - id = {1}",
                                         AnimeID, showInfo.title);
                            TraktTVHelper.LinkAniDBTrakt(AnimeID,
                                                         (EpisodeType)tvXRef.AniDBStartEpisodeType,
                                                         tvXRef.AniDBStartEpisodeNumber, showInfo.ids.slug,
                                                         tvXRef.TvDBSeasonNumber, tvXRef.TvDBStartEpisodeNumber,
                                                         true);
                            doReturn = true;
                        }
                        if (doReturn)
                        {
                            return;
                        }
                    }

                    // Use TvDB setting due to similarity
                    if (!ServerSettings.TvDB_AutoLink)
                    {
                        return;
                    }

                    // finally lets try searching Trakt directly
                    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 <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)
                    {
                        return;
                    }

                    foreach (AniDB_Anime_Title title in anime.GetTitles())
                    {
                        if (!string.Equals(title.TitleType, Shoko.Models.Constants.AnimeTitleType.Official, StringComparison.InvariantCultureIgnoreCase))
                        {
                            continue;
                        }

                        if (string.Equals(searchCriteria, title.Title, StringComparison.InvariantCultureIgnoreCase))
                        {
                            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);
            }
        }
Esempio n. 8
0
        public override void Run(IProgress <ICommand> progress = null)
        {
            logger.Info("Processing CommandRequest_TraktSearchAnime: {0}", AnimeID);

            try
            {
                ReportInit(progress);
                bool doReturn = false;

                // first check if the user wants to use the web cache
                if (ServerSettings.Instance.WebCache.Trakt_Get)
                {
                    try
                    {
                        List <WebCache_CrossRef_AniDB_Provider> resultsCache = WebCacheAPI.Instance.GetCrossRef_AniDB_Provider(AnimeID, CrossRefType.TraktTV);
                        ReportUpdate(progress, 30);
                        if (resultsCache != null && resultsCache.Count > 0)
                        {
                            List <WebCache_CrossRef_AniDB_Provider> best = resultsCache.BestProvider();
                            if (best.Count > 0)
                            {
                                TraktTVHelper.RemoveAllAniDBTraktLinks(AnimeID, false);
                                ReportUpdate(progress, 70);
                                foreach (WebCache_CrossRef_AniDB_Provider xref in best)
                                {
                                    TraktTVHelper.LinkAniDBTraktFromWebCache(xref);
                                }
                                SVR_AniDB_Anime.UpdateStatsByAnimeID(AnimeID);
                                logger.Trace("Changed trakt association: {0}", AnimeID);
                                ReportFinish(progress);
                                return;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex, ex.ToString());
                    }
                }


                // 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
                List <SVR_CrossRef_AniDB_Provider>
                xrefTvDBs = Repo.Instance.CrossRef_AniDB_Provider.GetByAnimeIDAndType(AnimeID, CrossRefType.TvDB);
                if (xrefTvDBs != null && xrefTvDBs.Count > 0)
                {
                    foreach (SVR_CrossRef_AniDB_Provider tvXRef in xrefTvDBs)
                    {
                        // first search for this show by the TvDB ID
                        List <TraktV2SearchTvDBIDShowResult> searchResults = TraktTVHelper.SearchShowByIDV2(TraktSearchIDType.tvdb, tvXRef.CrossRefID);
                        if (searchResults == null || searchResults.Count <= 0)
                        {
                            continue;
                        }
                        // 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)
                            {
                                continue;
                            }
                            resShow = res.show;
                            break;
                        }

                        if (resShow == null)
                        {
                            continue;
                        }

                        TraktV2ShowExtended showInfo = TraktTVHelper.GetShowInfoV2(resShow.ids.slug);
                        if (showInfo?.ids == null)
                        {
                            continue;
                        }

                        // make sure the season specified by TvDB also exists on Trakt
                        Trakt_Show traktShow =
                            Repo.Instance.Trakt_Show.GetByTraktSlug(showInfo.ids.slug);
                        if (traktShow == null)
                        {
                            continue;
                        }

                        Trakt_Season traktSeason = Repo.Instance.Trakt_Season.GetByShowIDAndSeason(traktShow.Trakt_ShowID, tvXRef.GetEpisodesWithOverrides().FirstOrDefault()?.Season ?? 0);
                        if (traktSeason == null)
                        {
                            continue;
                        }

                        logger.Trace("Found trakt match using TvDBID locally {0} - id = {1}",
                                     AnimeID, showInfo.title);
                        TraktTVHelper.LinkAniDBTrakt(AnimeID, showInfo.ids.slug, true);
                        doReturn = true;
                        ReportUpdate(progress, 60);
                    }
                    if (doReturn)
                    {
                        ReportFinish(progress);
                        return;
                    }
                }

                // Use TvDB setting due to similarity
                if (!ServerSettings.Instance.TvDB.AutoLink)
                {
                    ReportFinish(progress);
                    return;
                }

                // finally lets try searching Trakt directly
                SVR_AniDB_Anime anime = Repo.Instance.AniDB_Anime.GetByAnimeID(AnimeID);
                if (anime == null)
                {
                    ReportFinish(progress);
                    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 <TraktV2SearchShowResult> results = TraktTVHelper.SearchShowV2(searchCriteria);
                logger.Trace("Found {0} trakt results for {1} ", results.Count, searchCriteria);
                if (ProcessSearchResults(results, searchCriteria))
                {
                    ReportFinish(progress);
                    return;
                }

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

                ReportUpdate(progress, 80);
                foreach (AniDB_Anime_Title title in anime.GetTitles())
                {
                    if (!string.Equals(title.TitleType, Shoko.Models.Constants.AnimeTitleType.Official, StringComparison.InvariantCultureIgnoreCase))
                    {
                        continue;
                    }

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

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

                ReportFinish(progress);
            }
            catch (Exception ex)
            {
                ReportError(progress, $"Error processing CommandRequest_TvDBSearchAnime: {AnimeID} - {ForceRefresh} - {ex}", ex);
            }
        }