Exemplo n.º 1
0
        public override void ProcessCommand()
        {
            try
            {
                //if (string.IsNullOrEmpty(ServerSettings.WebCacheAuthKey)) return;

                CrossRef_AniDB_TvDBV2Repository repCrossRef = new CrossRef_AniDB_TvDBV2Repository();
                CrossRef_AniDB_TvDBV2           xref        = repCrossRef.GetByID(CrossRef_AniDB_TvDBID);
                if (xref == null)
                {
                    return;
                }

                AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository();
                AniDB_Anime           anime    = repAnime.GetByAnimeID(xref.AnimeID);
                if (anime == null)
                {
                    return;
                }

                AzureWebAPI.Send_CrossRefAniDBTvDB(xref, anime.MainTitle);
            }
            catch (Exception ex)
            {
                logger.ErrorException("Error processing CommandRequest_WebCacheSendXRefAniDBTvDB: {0}" + ex.ToString(),
                                      ex);
                return;
            }
        }
Exemplo n.º 2
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);
     }
 }
Exemplo n.º 3
0
        public static void UpdateAllInfo(bool force)
        {
            CrossRef_AniDB_TvDBV2Repository repCrossRef  = new CrossRef_AniDB_TvDBV2Repository();
            List <CrossRef_AniDB_TvDBV2>    allCrossRefs = repCrossRef.GetAll();
            List <int> alreadyLinked = new List <int>();

            foreach (CrossRef_AniDB_TvDBV2 xref in allCrossRefs)
            {
                CommandRequest_TvDBUpdateSeriesAndEpisodes cmd = new CommandRequest_TvDBUpdateSeriesAndEpisodes(xref.TvDBID, force);
                cmd.Save();
            }
        }
Exemplo n.º 4
0
        public static void DownloadAllEpisodes()
        {
            CrossRef_AniDB_TvDBV2Repository repCrossRef  = new CrossRef_AniDB_TvDBV2Repository();
            List <CrossRef_AniDB_TvDBV2>    allCrossRefs = repCrossRef.GetAll();

            List <int> tvDBIDs = new List <int>();

            foreach (CrossRef_AniDB_TvDBV2 xref in allCrossRefs)
            {
                if (!tvDBIDs.Contains(xref.TvDBID))
                {
                    tvDBIDs.Add(xref.TvDBID);
                }
            }

            DownloadAllEpisodes(tvDBIDs);
        }
Exemplo n.º 5
0
        // Removes all TVDB information from a series, bringing it back to a blank state.
        public static void RemoveLinkAniDBTvDB(int animeID, enEpisodeType aniEpType, int aniEpNumber, int tvDBID, int tvSeasonNumber, int tvEpNumber)
        {
            CrossRef_AniDB_TvDBV2Repository repCrossRef = new CrossRef_AniDB_TvDBV2Repository();
            CrossRef_AniDB_TvDBV2           xref        = repCrossRef.GetByTvDBID(tvDBID, tvSeasonNumber, tvEpNumber, animeID, (int)aniEpType, aniEpNumber);

            if (xref == null)
            {
                return;
            }

            repCrossRef.Delete(xref.CrossRef_AniDB_TvDBV2ID);

            StatsCache.Instance.UpdateUsingAnime(animeID);

            CommandRequest_WebCacheDeleteXRefAniDBTvDB req = new CommandRequest_WebCacheDeleteXRefAniDBTvDB(animeID, (int)aniEpType, aniEpNumber,
                                                                                                            tvDBID, tvSeasonNumber, tvEpNumber);

            req.Save();
        }
Exemplo n.º 6
0
        /*
         *      public static void DownloadAllEpisodes()
         *      {
         *              CrossRef_AniDB_TvDBV2Repository repCrossRef = new CrossRef_AniDB_TvDBV2Repository();
         *              List<CrossRef_AniDB_TvDBV2> allCrossRefs = repCrossRef.GetAll();
         *
         *              List<int> tvDBIDs = new List<int>();
         *              foreach (CrossRef_AniDB_TvDBV2 xref in allCrossRefs)
         *              {
         *                      if (!tvDBIDs.Contains(xref.TvDBID)) tvDBIDs.Add(xref.TvDBID);
         *              }
         *
         *              DownloadAllEpisodes(tvDBIDs);
         *      }
         *
         * public static void DownloadAllEpisodes(List<int> tvDBIDs)
         *      {
         *              foreach (int tvid in tvDBIDs)
         *              {
         *                      CommandRequest_TvDBUpdateSeriesAndEpisodes cmd = new CommandRequest_TvDBUpdateSeriesAndEpisodes(tvid, false);
         *                      cmd.Save();
         *              }
         *      }
         */

        public static void ScanForMatches()
        {
            AnimeSeriesRepository repSeries = new AnimeSeriesRepository();
            List <AnimeSeries>    allSeries = repSeries.GetAll();

            CrossRef_AniDB_TvDBV2Repository repCrossRef  = new CrossRef_AniDB_TvDBV2Repository();
            List <CrossRef_AniDB_TvDBV2>    allCrossRefs = repCrossRef.GetAll();
            List <int> alreadyLinked = new List <int>();

            foreach (CrossRef_AniDB_TvDBV2 xref in allCrossRefs)
            {
                alreadyLinked.Add(xref.AnimeID);
            }

            foreach (AnimeSeries ser in allSeries)
            {
                if (alreadyLinked.Contains(ser.AniDB_ID))
                {
                    continue;
                }

                AniDB_Anime anime = ser.GetAnime();

                if (anime != null)
                {
                    logger.Trace("Found anime without tvDB association: " + anime.MainTitle);
                    if (!anime.SearchOnTvDB)
                    {
                        continue;
                    }
                    if (anime.IsTvDBLinkDisabled)
                    {
                        logger.Trace("Skipping scan tvDB link because it is disabled: " + anime.MainTitle);
                        continue;
                    }
                }

                CommandRequest_TvDBSearchAnime cmd = new CommandRequest_TvDBSearchAnime(ser.AniDB_ID, false);
                cmd.Save();
            }
        }
Exemplo n.º 7
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;
            }
        }
Exemplo n.º 9
0
        public static void MigrateTvDBLinks_V1_to_V2()
        {
            try
            {
                AniDB_AnimeRepository  repAnime = new AniDB_AnimeRepository();
                TvDB_EpisodeRepository repEps   = new TvDB_EpisodeRepository();

                CrossRef_AniDB_TvDBRepository   repCrossRefTvDB    = new CrossRef_AniDB_TvDBRepository();
                CrossRef_AniDB_TvDBV2Repository repCrossRefTvDBNew = new CrossRef_AniDB_TvDBV2Repository();

                using (var session = JMMService.SessionFactory.OpenSession())
                {
                    List <CrossRef_AniDB_TvDB> xrefsTvDB = repCrossRefTvDB.GetAll();
                    foreach (CrossRef_AniDB_TvDB xrefTvDB in xrefsTvDB)
                    {
                        CrossRef_AniDB_TvDBV2 xrefNew = new CrossRef_AniDB_TvDBV2();
                        xrefNew.AnimeID          = xrefTvDB.AnimeID;
                        xrefNew.CrossRefSource   = xrefTvDB.CrossRefSource;
                        xrefNew.TvDBID           = xrefTvDB.TvDBID;
                        xrefNew.TvDBSeasonNumber = xrefTvDB.TvDBSeasonNumber;

                        TvDB_Series ser = xrefTvDB.GetTvDBSeries(session);
                        if (ser != null)
                        {
                            xrefNew.TvDBTitle = ser.SeriesName;
                        }

                        // determine start ep type
                        if (xrefTvDB.TvDBSeasonNumber == 0)
                        {
                            xrefNew.AniDBStartEpisodeType = (int)AniDBAPI.enEpisodeType.Special;
                        }
                        else
                        {
                            xrefNew.AniDBStartEpisodeType = (int)AniDBAPI.enEpisodeType.Episode;
                        }

                        xrefNew.AniDBStartEpisodeNumber = 1;
                        xrefNew.TvDBStartEpisodeNumber  = 1;

                        repCrossRefTvDBNew.Save(xrefNew);
                    }

                    // create cross ref's for specials
                    foreach (CrossRef_AniDB_TvDB xrefTvDB in xrefsTvDB)
                    {
                        AniDB_Anime anime = repAnime.GetByAnimeID(xrefTvDB.AnimeID);
                        if (anime == null)
                        {
                            continue;
                        }

                        // this anime has specials
                        if (anime.EpisodeCountSpecial <= 0)
                        {
                            continue;
                        }

                        // this tvdb series has a season 0 (specials)
                        List <int> seasons = repEps.GetSeasonNumbersForSeries(xrefTvDB.TvDBID);
                        if (!seasons.Contains(0))
                        {
                            continue;
                        }

                        //make sure we are not doubling up
                        CrossRef_AniDB_TvDBV2 temp = repCrossRefTvDBNew.GetByTvDBID(xrefTvDB.TvDBID, 0, 1, xrefTvDB.AnimeID, (int)AniDBAPI.enEpisodeType.Special, 1);
                        if (temp != null)
                        {
                            continue;
                        }

                        CrossRef_AniDB_TvDBV2 xrefNew = new CrossRef_AniDB_TvDBV2();
                        xrefNew.AnimeID                 = xrefTvDB.AnimeID;
                        xrefNew.CrossRefSource          = xrefTvDB.CrossRefSource;
                        xrefNew.TvDBID                  = xrefTvDB.TvDBID;
                        xrefNew.TvDBSeasonNumber        = 0;
                        xrefNew.TvDBStartEpisodeNumber  = 1;
                        xrefNew.AniDBStartEpisodeType   = (int)AniDBAPI.enEpisodeType.Special;
                        xrefNew.AniDBStartEpisodeNumber = 1;

                        TvDB_Series ser = xrefTvDB.GetTvDBSeries(session);
                        if (ser != null)
                        {
                            xrefNew.TvDBTitle = ser.SeriesName;
                        }

                        repCrossRefTvDBNew.Save(xrefNew);
                    }
                }
            }
            catch (Exception ex)
            {
                logger.ErrorException("Could not MigrateTvDBLinks_V1_to_V2: " + ex.ToString(), ex);
            }
        }
Exemplo n.º 10
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(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_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;
            }
        }
Exemplo n.º 11
0
        public static string LinkAniDBTvDB(int animeID, enEpisodeType aniEpType, int aniEpNumber, int tvDBID,
                                           int tvSeasonNumber, int tvEpNumber, bool excludeFromWebCache)
        {
            using (var session = JMMService.SessionFactory.OpenSession())
            {
                CrossRef_AniDB_TvDBV2Repository repCrossRef = new CrossRef_AniDB_TvDBV2Repository();
                List <CrossRef_AniDB_TvDBV2>    xrefTemps   = repCrossRef.GetByAnimeIDEpTypeEpNumber(session, animeID,
                                                                                                     (int)aniEpType,
                                                                                                     aniEpNumber);
                if (xrefTemps != null && xrefTemps.Count > 0)
                {
                    foreach (CrossRef_AniDB_TvDBV2 xrefTemp in xrefTemps)
                    {
                        // delete the existing one if we are updating
                        TvDBHelper.RemoveLinkAniDBTvDB(xrefTemp.AnimeID, (enEpisodeType)xrefTemp.AniDBStartEpisodeType,
                                                       xrefTemp.AniDBStartEpisodeNumber,
                                                       xrefTemp.TvDBID, xrefTemp.TvDBSeasonNumber, xrefTemp.TvDBStartEpisodeNumber);
                    }
                }

                // check if we have this information locally
                // if not download it now
                TvDB_SeriesRepository repSeries = new TvDB_SeriesRepository();
                TvDB_Series           tvSeries  = repSeries.GetByTvDBID(tvDBID);
                if (tvSeries == null)
                {
                    // we download the series info here just so that we have the basic info in the
                    // database before the queued task runs later
                    tvSeries = GetSeriesInfoOnline(tvDBID);
                }

                // download and update series info, episode info and episode images
                // will also download fanart, posters and wide banners
                CommandRequest_TvDBUpdateSeriesAndEpisodes cmdSeriesEps =
                    new CommandRequest_TvDBUpdateSeriesAndEpisodes(tvDBID,
                                                                   false);
                //Optimize for batch updates, if there are a lot of LinkAniDBTvDB commands queued
                //this will cause only one updateSeriesAndEpisodes command to be created
                CommandRequestRepository repCR = new CommandRequestRepository();
                if (repCR.GetByCommandID(cmdSeriesEps.CommandID) == null)
                {
                    cmdSeriesEps.Save();
                }

                CrossRef_AniDB_TvDBV2 xref = repCrossRef.GetByTvDBID(session, tvDBID, tvSeasonNumber, tvEpNumber,
                                                                     animeID,
                                                                     (int)aniEpType, aniEpNumber);
                if (xref == null)
                {
                    xref = new CrossRef_AniDB_TvDBV2();
                }

                xref.AnimeID = animeID;
                xref.AniDBStartEpisodeType   = (int)aniEpType;
                xref.AniDBStartEpisodeNumber = aniEpNumber;

                xref.TvDBID                 = tvDBID;
                xref.TvDBSeasonNumber       = tvSeasonNumber;
                xref.TvDBStartEpisodeNumber = tvEpNumber;
                if (tvSeries != null)
                {
                    xref.TvDBTitle = tvSeries.SeriesName;
                }

                if (excludeFromWebCache)
                {
                    xref.CrossRefSource = (int)CrossRefSource.WebCache;
                }
                else
                {
                    xref.CrossRefSource = (int)CrossRefSource.User;
                }

                repCrossRef.Save(xref);

                AniDB_Anime.UpdateStatsByAnimeID(animeID);

                logger.Trace("Changed tvdb association: {0}", animeID);

                if (!excludeFromWebCache)
                {
                    CommandRequest_WebCacheSendXRefAniDBTvDB req =
                        new CommandRequest_WebCacheSendXRefAniDBTvDB(xref.CrossRef_AniDB_TvDBV2ID);
                    req.Save();
                }

                if (ServerSettings.Trakt_IsEnabled && !string.IsNullOrEmpty(ServerSettings.Trakt_AuthToken))
                {
                    CrossRef_AniDB_TraktV2Repository repTraktXrefs = new CrossRef_AniDB_TraktV2Repository();
                    if (repTraktXrefs.GetByAnimeID(animeID).Count == 0)
                    {
                        // check for Trakt associations
                        CommandRequest_TraktSearchAnime cmd2 = new CommandRequest_TraktSearchAnime(animeID, false);
                        cmd2.Save(session);
                    }
                }
            }

            return("");
        }
Exemplo n.º 12
0
        public List <CrossRef_AniDB_TvDBV2> GetCrossRefTvDBV2(ISession session)
        {
            CrossRef_AniDB_TvDBV2Repository repCrossRef = new CrossRef_AniDB_TvDBV2Repository();

            return(repCrossRef.GetByAnimeID(session, this.AniDB_ID));
        }
Exemplo n.º 13
0
        public static string LinkAniDBTvDB(int animeID, enEpisodeType aniEpType, int aniEpNumber, int tvDBID, int tvSeasonNumber, int tvEpNumber, bool excludeFromWebCache)
        {
            using (var session = JMMService.SessionFactory.OpenSession())
            {
                CrossRef_AniDB_TvDBV2Repository repCrossRef = new CrossRef_AniDB_TvDBV2Repository();
                List <CrossRef_AniDB_TvDBV2>    xrefTemps   = repCrossRef.GetByAnimeIDEpTypeEpNumber(session, animeID, (int)aniEpType, aniEpNumber);
                if (xrefTemps != null && xrefTemps.Count > 0)
                {
                    foreach (CrossRef_AniDB_TvDBV2 xrefTemp in xrefTemps)
                    {
                        // delete the existing one if we are updating
                        TvDBHelper.RemoveLinkAniDBTvDB(xrefTemp.AnimeID, (enEpisodeType)xrefTemp.AniDBStartEpisodeType, xrefTemp.AniDBStartEpisodeNumber,
                                                       xrefTemp.TvDBID, xrefTemp.TvDBSeasonNumber, xrefTemp.TvDBStartEpisodeNumber);
                    }
                }

                // check if we have this information locally
                // if not download it now
                TvDB_SeriesRepository repSeries = new TvDB_SeriesRepository();
                TvDB_Series           tvSeries  = repSeries.GetByTvDBID(tvDBID);
                if (tvSeries == null)
                {
                    // we download the series info here just so that we have the basic info in the
                    // database before the queued task runs later
                    tvSeries = GetSeriesInfoOnline(tvDBID);
                }

                // download and update series info, episode info and episode images
                // will also download fanart, posters and wide banners
                CommandRequest_TvDBUpdateSeriesAndEpisodes cmdSeriesEps = new CommandRequest_TvDBUpdateSeriesAndEpisodes(tvDBID, false);
                cmdSeriesEps.Save();

                CrossRef_AniDB_TvDBV2 xref = repCrossRef.GetByTvDBID(session, tvDBID, tvSeasonNumber, tvEpNumber, animeID, (int)aniEpType, aniEpNumber);
                if (xref == null)
                {
                    xref = new CrossRef_AniDB_TvDBV2();
                }

                xref.AnimeID = animeID;
                xref.AniDBStartEpisodeType   = (int)aniEpType;
                xref.AniDBStartEpisodeNumber = aniEpNumber;

                xref.TvDBID                 = tvDBID;
                xref.TvDBSeasonNumber       = tvSeasonNumber;
                xref.TvDBStartEpisodeNumber = tvEpNumber;
                if (tvSeries != null)
                {
                    xref.TvDBTitle = tvSeries.SeriesName;
                }

                if (excludeFromWebCache)
                {
                    xref.CrossRefSource = (int)CrossRefSource.WebCache;
                }
                else
                {
                    xref.CrossRefSource = (int)CrossRefSource.User;
                }

                repCrossRef.Save(xref);

                StatsCache.Instance.UpdateUsingAnime(animeID);

                logger.Trace("Changed tvdb association: {0}", animeID);

                if (!excludeFromWebCache)
                {
                    CommandRequest_WebCacheSendXRefAniDBTvDB req = new CommandRequest_WebCacheSendXRefAniDBTvDB(xref.CrossRef_AniDB_TvDBV2ID);
                    req.Save();
                }
            }

            return("");
        }