Пример #1
0
        public string RemoveLinkAniDBForAnime(int animeID, int crossRefType)
        {
            try
            {
                SVR_AniDB_Anime anime = Repo.Instance.AniDB_Anime.GetByID(animeID);

                if (anime == null)
                {
                    return("Could not find Anime!");
                }

                CrossRefType xrefType = (CrossRefType)crossRefType;
                switch (xrefType)
                {
                case CrossRefType.MovieDB:
                    Repo.Instance.AniDB_Anime_DefaultImage.FindAndDelete(() => Repo.Instance.AniDB_Anime_DefaultImage.GetByAnimeID(animeID).Where(a => a.ImageParentType == (int)ImageEntityType.MovieDB_FanArt || a.ImageParentType == (int)ImageEntityType.MovieDB_Poster).ToList());
                    MovieDBHelper.RemoveLinkAniDBMovieDB(animeID);
                    break;

                case CrossRefType.TraktTV:
                    return(RemoveLinkAniDBTraktForAnime(animeID));

                case CrossRefType.TvDB:
                    return(RemoveLinkAniDBTvDBForAnime(animeID));
                }

                return(string.Empty);
            }
            catch (Exception ex)
            {
                logger.Error(ex, ex.ToString());
                return(ex.Message);
            }
        }
 public string UpdateMovieDBData(int movieD)
 {
     try
     {
         MovieDBHelper.UpdateMovieInfo(movieD, true);
     }
     catch (Exception ex)
     {
         logger.Error(ex, ex.ToString());
     }
     return(string.Empty);
 }
Пример #3
0
        private bool ProcessSearchResults(ISession session, List <MovieDB_Movie_Result> results, string searchCriteria)
        {
            if (results.Count == 1)
            {
                // since we are using this result, lets download the info
                logger.Trace("Found 1 moviedb results for search on {0} --- Linked to {1} ({2})", searchCriteria, results[0].MovieName, results[0].MovieID);

                int movieID = results[0].MovieID;
                MovieDBHelper.UpdateMovieInfo(session, movieID, true);
                MovieDBHelper.LinkAniDBMovieDB(AnimeID, movieID, false);
                return(true);
            }

            return(false);
        }
        public List <CL_MovieDBMovieSearch_Response> SearchTheMovieDB(string criteria)
        {
            List <CL_MovieDBMovieSearch_Response> results = new List <CL_MovieDBMovieSearch_Response>();

            try
            {
                List <MovieDB_Movie_Result> movieResults = MovieDBHelper.Search(criteria);

                foreach (MovieDB_Movie_Result res in movieResults)
                {
                    results.Add(res.ToContract());
                }

                return(results);
            }
            catch (Exception ex)
            {
                logger.Error(ex, ex.ToString());
                return(results);
            }
        }
        public string LinkAniDBOther(int animeID, int id, int crossRefType)
        {
            try
            {
                CrossRefType xrefType = (CrossRefType)crossRefType;

                switch (xrefType)
                {
                case CrossRefType.MovieDB:
                    MovieDBHelper.LinkAniDBMovieDB(animeID, id, false);
                    break;
                }

                return(string.Empty);
            }
            catch (Exception ex)
            {
                logger.Error(ex, ex.ToString());
                return(ex.Message);
            }
        }
        public string RemoveLinkAniDBOther(int animeID, int crossRefType)
        {
            try
            {
                SVR_AniDB_Anime anime = RepoFactory.AniDB_Anime.GetByAnimeID(animeID);

                if (anime == null)
                {
                    return("Could not find Anime!");
                }

                CrossRefType xrefType = (CrossRefType)crossRefType;
                switch (xrefType)
                {
                case CrossRefType.MovieDB:

                    // check if there are default images used associated
                    List <AniDB_Anime_DefaultImage> images =
                        RepoFactory.AniDB_Anime_DefaultImage.GetByAnimeID(animeID);
                    foreach (AniDB_Anime_DefaultImage image in images)
                    {
                        if (image.ImageParentType == (int)ImageEntityType.MovieDB_FanArt ||
                            image.ImageParentType == (int)ImageEntityType.MovieDB_Poster)
                        {
                            RepoFactory.AniDB_Anime_DefaultImage.Delete(image.AniDB_Anime_DefaultImageID);
                        }
                    }
                    MovieDBHelper.RemoveLinkAniDBMovieDB(animeID);
                    break;
                }

                return(string.Empty);
            }
            catch (Exception ex)
            {
                logger.Error(ex, ex.ToString());
                return(ex.Message);
            }
        }
Пример #7
0
        public override void ProcessCommand()
        {
            logger.Info("Processing CommandRequest_MovieDBSearchAnime: {0}", AnimeID);

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

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

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

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

                    string          searchCriteria = string.Empty;
                    SVR_AniDB_Anime anime          = RepoFactory.AniDB_Anime.GetByAnimeID(sessionWrapper, AnimeID);
                    if (anime == null)
                    {
                        return;
                    }

                    searchCriteria = anime.MainTitle;

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


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

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

                            results = MovieDBHelper.Search(title.Title);
                            logger.Trace("Found {0} moviedb results for search on {1}", results.Count, title.Title);
                            if (ProcessSearchResults(session, results, title.Title))
                            {
                                return;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error("Error processing CommandRequest_TvDBSearchAnime: {0} - {1}", AnimeID, ex);
            }
        }
Пример #8
0
 public ActionResult UpdateAllMovieDBInfo()
 {
     Task.Factory.StartNew(() => MovieDBHelper.UpdateAllMovieInfo(true));
     return(Ok());
 }
        public override void ProcessCommand()
        {
            logger.Info("Processing CommandRequest_MovieDBSearchAnime: {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
                        {
                            MovieDB_MovieRepository repMovies = new MovieDB_MovieRepository();

                            JMMServer.Providers.Azure.CrossRef_AniDB_Other crossRef =
                                JMMServer.Providers.Azure.AzureWebAPI.Get_CrossRefAniDBOther(AnimeID,
                                                                                             CrossRefType.MovieDB);
                            if (crossRef != null)
                            {
                                int           movieID = int.Parse(crossRef.CrossRefID);
                                MovieDB_Movie movie   = repMovies.GetByOnlineID(session, movieID);
                                if (movie == null)
                                {
                                    // update the info from online
                                    MovieDBHelper.UpdateMovieInfo(session, movieID, true);
                                    movie = repMovies.GetByOnlineID(movieID);
                                }

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

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


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

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

                            results = MovieDBHelper.Search(title.Title);
                            logger.Trace("Found {0} moviedb results for search on {1}", results.Count, title.Title);
                            if (ProcessSearchResults(session, results, title.Title))
                            {
                                return;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error("Error processing CommandRequest_TvDBSearchAnime: {0} - {1}", AnimeID, ex.ToString());
                return;
            }
        }
Пример #10
0
        public override void Run(IProgress <ICommand> progress = null)
        {
            logger.Info("Processing CommandRequest_MovieDBSearchAnime: {0}", AnimeID);

            try
            {
                {
                    ReportInit(progress);
                    // first check if the user wants to use the web cache
                    if (ServerSettings.Instance.WebCache.TvDB_Get)
                    {
                        try
                        {
                            List <WebCache_CrossRef_AniDB_Provider> resultsCache = WebCacheAPI.Instance.GetCrossRef_AniDB_Provider(AnimeID, CrossRefType.MovieDB);
                            ReportUpdate(progress, 30);
                            if (resultsCache != null && resultsCache.Count > 0)
                            {
                                List <WebCache_CrossRef_AniDB_Provider> best = resultsCache.BestProvider();
                                if (best.Count > 0)
                                {
                                    int           movieID = int.Parse(best.First().CrossRefID);
                                    MovieDB_Movie movie   = Repo.Instance.MovieDb_Movie.GetByOnlineID(movieID);
                                    if (movie == null)
                                    {
                                        // update the info from online
                                        MovieDBHelper.UpdateMovieInfo(movieID, true);
                                        movie = Repo.Instance.MovieDb_Movie.GetByOnlineID(movieID);
                                    }
                                    ReportUpdate(progress, 20);

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

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

                    ReportUpdate(progress, 40);

                    SVR_AniDB_Anime anime = Repo.Instance.AniDB_Anime.GetByAnimeID(AnimeID);
                    if (anime == null)
                    {
                        ReportFinish(progress);
                        return;
                    }

                    string searchCriteria = anime.MainTitle;

                    // if not wanting to use web cache, or no match found on the web cache go to TvDB directly
                    List <MovieDB_Movie_Result> results = MovieDBHelper.Search(searchCriteria);
                    logger.Trace("Found {0} moviedb results for {1} on TheTvDB", results.Count, searchCriteria);
                    ReportUpdate(progress, 60);
                    if (ProcessSearchResults(results, searchCriteria))
                    {
                        ReportFinish(progress);
                        return;
                    }

                    ReportUpdate(progress, 80);

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

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

                            results = MovieDBHelper.Search(title.Title);
                            logger.Trace("Found {0} moviedb 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} - {ex}", ex);
            }
        }
Пример #11
0
		public static void RunImport_ScanMovieDB()
		{
			MovieDBHelper.ScanForMatches();
		}