private static anime GetEmptyAnimes() { anime animes = new anime(); animeEntry[] animeEntries = new animeEntry[0]; animes.entry = animeEntries; return(animes); }
private void Anime_Expanded(object sender, RoutedEventArgs e) { Expander expander = (Expander)sender; animeEntry entry = (animeEntry)expander.DataContext; if (entry == null) { anime searchResults = Search.GetResults(entry.title, login); if (searchResults != null && searchResults.Items.Length > 0) { entry = searchResults.Items[0]; } else { entry = null; } } }
public static anime SearchAnimesByTitle(string searchTitle) { if (string.IsNullOrEmpty(ServerSettings.MAL_Username) || string.IsNullOrEmpty(ServerSettings.MAL_Password)) { logger.Warn("Won't search MAL, MAL credentials not provided"); return(GetEmptyAnimes()); } searchTitle = HttpUtility.UrlPathEncode(searchTitle); string searchResultXML = ""; try { searchResultXML = SendMALAuthenticatedRequest("https://myanimelist.net/api/anime/search.xml?q=" + searchTitle); } catch (Exception ex) { logger.Error(ex, ex.ToString()); return(GetEmptyAnimes()); } if (searchResultXML.Trim().Length == 0) { return(GetEmptyAnimes()); } searchResultXML = HttpUtility.HtmlDecode(searchResultXML); searchResultXML = HttpUtilityV2.HtmlDecode(searchResultXML); searchResultXML = searchResultXML.Replace("&", "&"); XmlDocument docSearchResult = new XmlDocument(); docSearchResult.LoadXml(searchResultXML); anime animes = GetEmptyAnimes(); List <animeEntry> entries = new List <animeEntry>(); if (docSearchResult != null && docSearchResult["anime"] != null) { XmlNodeList searchItems = docSearchResult["anime"].GetElementsByTagName("entry"); foreach (XmlNode node in searchItems) { try { animeEntry entry = new animeEntry(); // default values entry.end_date = string.Empty; entry.english = string.Empty; entry.episodes = 0; entry.id = 0; entry.image = string.Empty; entry.score = 0; entry.start_date = string.Empty; entry.status = string.Empty; entry.synonyms = string.Empty; entry.synopsis = string.Empty; entry.title = string.Empty; entry.type = string.Empty; entry.end_date = AniDBHTTPHelper.TryGetProperty(node, "end_date"); entry.english = AniDBHTTPHelper.TryGetProperty(node, "english"); entry.image = AniDBHTTPHelper.TryGetProperty(node, "image"); int eps = 0; int id = 0; decimal score = 0; int.TryParse(AniDBHTTPHelper.TryGetProperty(node, "episodes"), out eps); int.TryParse(AniDBHTTPHelper.TryGetProperty(node, "id"), out id); decimal.TryParse(AniDBHTTPHelper.TryGetProperty(node, "score"), out score); entry.episodes = eps; entry.id = id; entry.score = score; entry.start_date = AniDBHTTPHelper.TryGetProperty(node, "start_date"); entry.status = AniDBHTTPHelper.TryGetProperty(node, "status"); entry.synonyms = AniDBHTTPHelper.TryGetProperty(node, "synonyms"); entry.synopsis = AniDBHTTPHelper.TryGetProperty(node, "synopsis"); entry.title = AniDBHTTPHelper.TryGetProperty(node, "title"); entry.type = AniDBHTTPHelper.TryGetProperty(node, "type"); entries.Add(entry); } catch (Exception ex) { logger.Error(ex, ex.ToString()); } } } animes.entry = entries.ToArray(); return(animes); }
private static anime GetEmptyAnimes() { anime animes = new anime(); animeEntry[] animeEntries = new animeEntry[0]; animes.entry = animeEntries; return animes; }
public static anime SearchAnimesByTitle(string searchTitle) { if (string.IsNullOrEmpty(ServerSettings.MAL_Username) || string.IsNullOrEmpty(ServerSettings.MAL_Password)) { logger.Warn("Won't search MAL, MAL credentials not provided"); return GetEmptyAnimes(); } searchTitle = HttpUtility.UrlPathEncode(searchTitle); string searchResultXML = ""; try { searchResultXML = SendMALAuthenticatedRequest("https://myanimelist.net/api/anime/search.xml?q=" + searchTitle); } catch (Exception ex) { logger.Error( ex,ex.ToString()); return GetEmptyAnimes(); } if (searchResultXML.Trim().Length == 0) return GetEmptyAnimes(); searchResultXML = HttpUtility.HtmlDecode(searchResultXML); searchResultXML = HttpUtilityV2.HtmlDecode(searchResultXML); searchResultXML = searchResultXML.Replace("&", "&"); XmlDocument docSearchResult = new XmlDocument(); docSearchResult.LoadXml(searchResultXML); anime animes = GetEmptyAnimes(); List<animeEntry> entries = new List<animeEntry>(); if (docSearchResult != null && docSearchResult["anime"] != null) { XmlNodeList searchItems = docSearchResult["anime"].GetElementsByTagName("entry"); foreach (XmlNode node in searchItems) { try { animeEntry entry = new animeEntry(); // default values entry.end_date = string.Empty; entry.english = string.Empty; entry.episodes = 0; entry.id = 0; entry.image = string.Empty; entry.score = 0; entry.start_date = string.Empty; entry.status = string.Empty; entry.synonyms = string.Empty; entry.synopsis = string.Empty; entry.title = string.Empty; entry.type = string.Empty; entry.end_date = AniDBHTTPHelper.TryGetProperty(node, "end_date"); entry.english = AniDBHTTPHelper.TryGetProperty(node, "english"); entry.image = AniDBHTTPHelper.TryGetProperty(node, "image"); int eps = 0; int id = 0; decimal score = 0; int.TryParse(AniDBHTTPHelper.TryGetProperty(node, "episodes"), out eps); int.TryParse(AniDBHTTPHelper.TryGetProperty(node, "id"), out id); decimal.TryParse(AniDBHTTPHelper.TryGetProperty(node, "score"), out score); entry.episodes = eps; entry.id = id; entry.score = score; entry.start_date = AniDBHTTPHelper.TryGetProperty(node, "start_date"); entry.status = AniDBHTTPHelper.TryGetProperty(node, "status"); entry.synonyms = AniDBHTTPHelper.TryGetProperty(node, "synonyms"); entry.synopsis = AniDBHTTPHelper.TryGetProperty(node, "synopsis"); entry.title = AniDBHTTPHelper.TryGetProperty(node, "title"); entry.type = AniDBHTTPHelper.TryGetProperty(node, "type"); entries.Add(entry); } catch (Exception ex) { logger.Error( ex,ex.ToString()); } } } animes.entry = entries.ToArray(); return animes; }