Esempio n. 1
0
        public static void FixAniDB_EpisodesWithMissingTitles()
        {
            logger.Info("Checking for Episodes with Missing Titles");
            var episodes = RepoFactory.AniDB_Episode.GetAll()
                           .Where(a => !RepoFactory.AniDB_Episode_Title.GetByEpisodeID(a.EpisodeID).Any() &&
                                  RepoFactory.AnimeSeries.GetByAnimeID(a.AnimeID) != null).ToList();
            var animeIDs = episodes.Select(a => a.AnimeID).Distinct().OrderBy(a => a).ToList();
            int count    = 0;

            logger.Info($"There are {episodes.Count} episodes in {animeIDs.Count} anime with missing titles. Attempting to fill them from HTTP cache");
            foreach (int animeID in animeIDs)
            {
                count++;
                try
                {
                    var anime = RepoFactory.AniDB_Anime.GetByAnimeID(animeID);
                    if (anime == null)
                    {
                        logger.Info($"Anime {animeID} is missing it's AniDB_Anime record. That's a problem. Try importing a file for the anime.");
                        continue;
                    }

                    ServerState.Instance.CurrentSetupStatus = string.Format(
                        Commons.Properties.Resources.Database_Validating,
                        $"Generating Episode Info for {anime.MainTitle}",
                        $" {count}/{animeIDs.Count}");
                    XmlDocument docAnime = APIUtils.LoadAnimeHTTPFromFile(animeID);
                    if (docAnime == null)
                    {
                        continue;
                    }
                    logger.Info($"{anime.MainTitle} has a proper HTTP cache. Attempting to regenerate info from it.");

                    var rawEpisodes = AniDBHTTPHelper.ProcessEpisodes(docAnime, animeID);
                    anime.CreateEpisodes(rawEpisodes);
                    logger.Info($"Recreating Episodes for {anime.MainTitle}");
                    SVR_AnimeSeries series = RepoFactory.AnimeSeries.GetByAnimeID(anime.AnimeID);
                    if (series == null)
                    {
                        continue;
                    }
                    series.CreateAnimeEpisodes();
                }
                catch (Exception e)
                {
                    logger.Error($"Error Populating Episode Titles for Anime ({animeID}): {e}");
                }
            }
            logger.Info("Finished Filling Episode Titles from Cache.");
        }
        public static void FixAniDB_EpisodesWithMissingTitles()
        {
            var specials = RepoFactory.AniDB_Episode.GetAll().Where(a => string.IsNullOrEmpty(a.GetEnglishTitle()))
                           .Select(a => a.AnimeID).Distinct().OrderBy(a => a).ToList();
            int count = 0;

            foreach (int animeID in specials)
            {
                count++;
                try
                {
                    var anime = RepoFactory.AniDB_Anime.GetByAnimeID(animeID);
                    if (anime == null)
                    {
                        continue;
                    }

                    ServerState.Instance.CurrentSetupStatus = string.Format(
                        Commons.Properties.Resources.Database_Validating,
                        $"Generating Episode Info for {anime.MainTitle}",
                        $" {count}/{specials.Count}");
                    XmlDocument docAnime = APIUtils.LoadAnimeHTTPFromFile(animeID);
                    if (docAnime == null)
                    {
                        continue;
                    }

                    var episodes = AniDBHTTPHelper.ProcessEpisodes(docAnime, animeID);
                    anime.CreateEpisodes(episodes);
                    // we don't need to save the AniDB_Anime, since nothing has changed in it
                }
                catch (Exception e)
                {
                    logger.Error($"Error Populating Episode Titles for Anime ({animeID}): {e}");
                }
            }
        }
        public virtual enHelperActivityType Process()
        {
            string appPath  = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
            string filePath = Path.Combine(appPath, "Anime_HTTP");

            if (!Directory.Exists(filePath))
            {
                Directory.CreateDirectory(filePath);
            }

            string fileName         = string.Format("AnimeDoc_{0}.xml", animeID);
            string fileNameWithPath = Path.Combine(filePath, fileName);

            if (!CacheOnly)
            {
                JMMService.LastAniDBMessage     = DateTime.Now;
                JMMService.LastAniDBHTTPMessage = DateTime.Now;
            }

            XmlDocument docAnime = null;

            if (CacheOnly)
            {
                xmlResult = AzureWebAPI.Get_AnimeXML(animeID);
                if (!string.IsNullOrEmpty(xmlResult))
                {
                    docAnime = new XmlDocument();
                    docAnime.LoadXml(xmlResult);
                }
            }
            else
            {
                if (!ForceFromAniDB)
                {
                    //Disable usage of Azure API for this type of data

                    /*xmlResult = AzureWebAPI.Get_AnimeXML(animeID);
                     *                  if (string.IsNullOrEmpty(xmlResult))
                     *                  {
                     *                          docAnime = AniDBHTTPHelper.GetAnimeXMLFromAPI(animeID, ref xmlResult);
                     *                  }
                     *                  else
                     *                  {
                     *                          docAnime = new XmlDocument();
                     *                          docAnime.LoadXml(xmlResult);
                     *                  }*/

                    docAnime = AniDBHTTPHelper.GetAnimeXMLFromAPI(animeID, ref xmlResult);
                }
                else
                {
                    docAnime = AniDBHTTPHelper.GetAnimeXMLFromAPI(animeID, ref xmlResult);
                    //XmlDocument docAnime = LoadAnimeHTTPFromFile(animeID);
                }
            }

            if (xmlResult.Trim().Length > 0)
            {
                WriteAnimeHTTPToFile(animeID, xmlResult);
            }

            if (CheckForBan(xmlResult))
            {
                return(enHelperActivityType.NoSuchAnime);
            }

            if (docAnime != null)
            {
                anime           = AniDBHTTPHelper.ProcessAnimeDetails(docAnime, animeID);
                episodes        = AniDBHTTPHelper.ProcessEpisodes(docAnime, animeID);
                titles          = AniDBHTTPHelper.ProcessTitles(docAnime, animeID);
                tags            = AniDBHTTPHelper.ProcessTags(docAnime, animeID);
                characters      = AniDBHTTPHelper.ProcessCharacters(docAnime, animeID);
                relations       = AniDBHTTPHelper.ProcessRelations(docAnime, animeID);
                similarAnime    = AniDBHTTPHelper.ProcessSimilarAnime(docAnime, animeID);
                recommendations = AniDBHTTPHelper.ProcessRecommendations(docAnime, animeID);
                return(enHelperActivityType.GotAnimeInfoHTTP);
            }
            else
            {
                return(enHelperActivityType.NoSuchAnime);
            }
        }
Esempio n. 4
0
        public virtual enHelperActivityType Process()
        {
            if (!CacheOnly)
            {
                ShokoService.LastAniDBMessage     = DateTime.Now;
                ShokoService.LastAniDBHTTPMessage = DateTime.Now;
            }

            XmlDocument docAnime = null;

            if (CacheOnly)
            {
                xmlResult = AzureWebAPI.Get_AnimeXML(animeID);
                if (!string.IsNullOrEmpty(xmlResult))
                {
                    docAnime = new XmlDocument();
                    docAnime.LoadXml(xmlResult);
                }
            }
            else
            {
                if (!ForceFromAniDB)
                {
                    //Disable usage of Azure API for this type of data

                    /*xmlResult = AzureWebAPI.Get_AnimeXML(animeID);
                     *                  if (string.IsNullOrEmpty(xmlResult))
                     *                  {
                     *                          docAnime = AniDBHTTPHelper.GetAnimeXMLFromAPI(animeID, ref xmlResult);
                     *                  }
                     *                  else
                     *                  {
                     *                          docAnime = new XmlDocument();
                     *                          docAnime.LoadXml(xmlResult);
                     *                  }*/

                    //logger.Info("Trying to load Anime HTTP info from cache file...");
                    docAnime = LoadAnimeHTTPFromFile(animeID);
                    if (docAnime == null)
                    {
                        //logger.Info("No Anime HTTP info found in cache file, loading from HTTP API");
                        docAnime = AniDBHTTPHelper.GetAnimeXMLFromAPI(animeID, ref xmlResult);
                    }
                }
                else
                {
                    docAnime = AniDBHTTPHelper.GetAnimeXMLFromAPI(animeID, ref xmlResult);
                }
            }

            if (CheckForBan(xmlResult))
            {
                return(enHelperActivityType.NoSuchAnime);
            }

            if (xmlResult.Trim().Length > 0)
            {
                WriteAnimeHTTPToFile(animeID, xmlResult);
            }

            if (docAnime != null)
            {
                anime           = AniDBHTTPHelper.ProcessAnimeDetails(docAnime, animeID);
                episodes        = AniDBHTTPHelper.ProcessEpisodes(docAnime, animeID);
                titles          = AniDBHTTPHelper.ProcessTitles(docAnime, animeID);
                tags            = AniDBHTTPHelper.ProcessTags(docAnime, animeID);
                characters      = AniDBHTTPHelper.ProcessCharacters(docAnime, animeID);
                relations       = AniDBHTTPHelper.ProcessRelations(docAnime, animeID);
                similarAnime    = AniDBHTTPHelper.ProcessSimilarAnime(docAnime, animeID);
                recommendations = AniDBHTTPHelper.ProcessRecommendations(docAnime, animeID);
                return(enHelperActivityType.GotAnimeInfoHTTP);
            }
            else
            {
                return(enHelperActivityType.NoSuchAnime);
            }
        }