public virtual enHelperActivityType Process(ref Socket soUDP, ref IPEndPoint remoteIpEndPoint, string sessionID, Encoding enc) { ProcessCommand(ref soUDP, ref remoteIpEndPoint, sessionID, enc); // handle 555 BANNED and 598 - UNKNOWN COMMAND if (ResponseCode == 598) return enHelperActivityType.UnknownCommand_598; if (ResponseCode == 555) return enHelperActivityType.Banned_555; if (errorOccurred) return enHelperActivityType.NoSuchAnime; //BaseConfig.MyAnimeLog.Write("AniDBCommand_GetAnimeInfo.Process: Response: {0}", socketResponse); // Process Response string sMsgType = socketResponse.Substring(0, 3); switch (sMsgType) { case "230": { // 230 FILE INFO // the first 9 characters should be "230 ANIME " // the rest of the information should be the data list animeInfo = new Raw_AniDB_Anime(socketResponse); return enHelperActivityType.GotAnimeInfo; } case "330": { return enHelperActivityType.NoSuchAnime; } case "501": { return enHelperActivityType.LoginRequired; } } return enHelperActivityType.FileDoesNotExist; }
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) { xmlResult = AzureWebAPI.Get_AnimeXML(animeID); if (string.IsNullOrEmpty(xmlResult)) { docAnime = AniDBHTTPHelper.GetAnimeXMLFromAPI(animeID, ref xmlResult); } else { docAnime = new XmlDocument(); docAnime.LoadXml(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); categories = AniDBHTTPHelper.ProcessCategories(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; } }
public static Raw_AniDB_Anime ProcessAnimeDetails(XmlDocument docAnime, int animeID) { // most of the genral anime data will be over written by the UDP command Raw_AniDB_Anime anime = new Raw_AniDB_Anime { AnimeID = animeID }; // check if there is any data if (docAnime?["anime"]?.Attributes["id"]?.Value == null) { logger.Warn("AniDB ProcessAnimeDetails - Received no or invalid info in XML"); return(null); } anime.Description = TryGetProperty(docAnime, "anime", "description")?.Replace('`', '\''); anime.AnimeTypeRAW = TryGetProperty(docAnime, "anime", "type"); string episodecount = TryGetProperty(docAnime, "anime", "episodecount"); int.TryParse(episodecount, out int epCount); anime.EpisodeCount = epCount; anime.EpisodeCountNormal = epCount; string dateString = TryGetProperty(docAnime, "anime", "startdate"); anime.AirDate = null; if (!string.IsNullOrEmpty(dateString)) { if (DateTime.TryParseExact(dateString, "yyyy-MM-dd", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out DateTime date)) { anime.AirDate = date; } else if (DateTime.TryParseExact(dateString, "yyyy-MM", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out DateTime date2)) { anime.AirDate = date2; } } dateString = TryGetProperty(docAnime, "anime", "enddate"); anime.EndDate = null; if (!string.IsNullOrEmpty(dateString)) { if (DateTime.TryParseExact(dateString, "yyyy-MM-dd", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, out DateTime date)) { anime.EndDate = date; } } anime.BeginYear = anime.AirDate?.Year ?? 0; anime.EndYear = anime.EndDate?.Year ?? 0; //string enddate = TryGetProperty(docAnime, "anime", "enddate"); string restricted = docAnime["anime"].Attributes["restricted"]?.Value; if (bool.TryParse(restricted, out bool res)) { anime.Restricted = res ? 1 : 0; } else { anime.Restricted = 0; } anime.URL = TryGetProperty(docAnime, "anime", "url"); anime.Picname = TryGetProperty(docAnime, "anime", "picture"); anime.DateTimeUpdated = DateTime.Now; anime.DateTimeDescUpdated = anime.DateTimeUpdated; anime.ImageEnabled = 1; #region Related Anime XmlNodeList raItems = docAnime["anime"]["relatedanime"]?.GetElementsByTagName("anime"); if (raItems != null) { anime.RelatedAnimeIdsRAW = string.Empty; anime.RelatedAnimeTypesRAW = string.Empty; foreach (XmlNode node in raItems) { if (node?.Attributes?["id"]?.Value == null) { continue; } if (!int.TryParse(node.Attributes["id"].Value, out int id)) { continue; } int relType = ConvertReltTypeTextToEnum(TryGetAttribute(node, "type")); if (anime.RelatedAnimeIdsRAW.Length > 0) { anime.RelatedAnimeIdsRAW += "'"; } if (anime.RelatedAnimeTypesRAW.Length > 0) { anime.RelatedAnimeTypesRAW += "'"; } anime.RelatedAnimeIdsRAW += id.ToString(); anime.RelatedAnimeTypesRAW += relType.ToString(); } } #endregion #region Titles XmlNodeList titleItems = docAnime["anime"]["titles"]?.GetElementsByTagName("title"); if (titleItems != null) { foreach (XmlNode node in titleItems) { string titleType = node?.Attributes?["type"]?.Value?.Trim().ToLower(); if (string.IsNullOrEmpty(titleType)) { continue; } string languageType = node.Attributes["xml:lang"]?.Value?.Trim().ToLower(); if (string.IsNullOrEmpty(languageType)) { continue; } string titleValue = node.InnerText.Trim(); if (string.IsNullOrEmpty(titleValue)) { continue; } if (titleType.Trim().ToUpper().Equals("MAIN")) { anime.MainTitle = titleValue.Replace('`', '\''); } } } #endregion #region Ratings // init ratings anime.VoteCount = 0; anime.TempVoteCount = 0; anime.Rating = 0; anime.TempRating = 0; anime.ReviewCount = 0; anime.AvgReviewRating = 0; NumberStyles style = NumberStyles.Number; CultureInfo culture = CultureInfo.CreateSpecificCulture("en-GB"); XmlNodeList ratingItems = docAnime["anime"]["ratings"]?.ChildNodes; if (ratingItems == null) { return(anime); } foreach (XmlNode node in ratingItems) { string name = node?.Name?.Trim().ToLower(); if (string.IsNullOrEmpty(name)) { continue; } if (!int.TryParse(TryGetAttribute(node, "count"), out int iCount)) { continue; } if (!decimal.TryParse(node.InnerText.Trim(), style, culture, out decimal iRating)) { continue; } iRating = (int)Math.Round(iRating * 100); if (name.Equals("permanent")) { anime.VoteCount = iCount; anime.Rating = (int)iRating; } else if (name.Equals("temporary")) { anime.TempVoteCount = iCount; anime.TempRating = (int)iRating; } else if (name.Equals("review")) { anime.ReviewCount = iCount; anime.AvgReviewRating = (int)iRating; } } #endregion return(anime); }
public virtual enHelperActivityType Process() { if (!CacheOnly) { ShokoService.LastAniDBMessage = DateTime.Now; ShokoService.LastAniDBHTTPMessage = DateTime.Now; } XmlDocument docAnime = null; if (CacheOnly) { // This just throws 404s //xmlResult = AzureWebAPI.Get_AnimeXML(animeID); //if (!string.IsNullOrEmpty(xmlResult)) //{ // docAnime = new XmlDocument(); // docAnime.LoadXml(xmlResult); //} //else //{ docAnime = LoadAnimeHTTPFromFile(animeID); //} } if (!ForceFromAniDB) { //logger.Info("Trying to load Anime HTTP info from cache file..."); if (docAnime == null && !CacheOnly) { //logger.Info("No Anime HTTP info found in cache file, loading from HTTP API"); docAnime = AniDBHTTPHelper.GetAnimeXMLFromAPI(animeID, ref xmlResult); } } else if (!CacheOnly) { docAnime = AniDBHTTPHelper.GetAnimeXMLFromAPI(animeID, ref xmlResult); } if (CheckForBan(xmlResult)) { return(enHelperActivityType.Banned_555); } if (xmlResult.Trim().Length > 0) { WriteAnimeHTTPToFile(animeID, xmlResult); } if (docAnime != null) { anime = AniDBHTTPHelper.ProcessAnimeDetails(docAnime, animeID); if (anime == null) { return(enHelperActivityType.NoSuchAnime); } episodes = AniDBHTTPHelper.ProcessEpisodes(docAnime, animeID); titles = AniDBHTTPHelper.ProcessTitles(docAnime, animeID); tags = AniDBHTTPHelper.ProcessTags(docAnime, animeID); characters = AniDBHTTPHelper.ProcessCharacters(docAnime, animeID); if (!CacheOnly) { relations = AniDBHTTPHelper.ProcessRelations(docAnime, animeID); similarAnime = AniDBHTTPHelper.ProcessSimilarAnime(docAnime, animeID); recommendations = AniDBHTTPHelper.ProcessRecommendations(docAnime, animeID); } else { relations = null; similarAnime = null; recommendations = null; } return(enHelperActivityType.GotAnimeInfoHTTP); } return(enHelperActivityType.NoSuchAnime); }
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); } }
public virtual enHelperActivityType Process() { 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); }*/ //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 (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; } }