Exemplo n.º 1
0
		private static void SetType(HtmlDocument document, MangaDetail mangaDetail)
		{
			var type = document.DocumentNode.SelectSingleNode("//span[contains(.,'Type:')]");

			if (type != null)
				mangaDetail.Type = type.NextSibling.NextSibling.InnerText.Trim();
		}
Exemplo n.º 2
0
		private static void SetChapter(HtmlNode leftColumnNodeset, MangaDetail mangaDetail)
		{
			var chapter = leftColumnNodeset.SelectSingleNode("//span[text()='Chapters:']");

			if (chapter != null)
			{
				int chapters;
				if (Int32.TryParse(chapter.NextSibling.InnerText.Replace(",", ""), out chapters))
					mangaDetail.Chapters = chapters;
				else
				{
					mangaDetail.Chapters = null;
				}
			}
		}
Exemplo n.º 3
0
		private static void SetVolume(HtmlNode leftColumnNodeset, MangaDetail mangaDetail)
		{
			var volume = leftColumnNodeset.SelectSingleNode("//span[text()='Volumes:']");

			if (volume != null)
			{
				int volumes;
				if (Int32.TryParse(volume.NextSibling.InnerText.Replace(",", ""), out volumes))
					mangaDetail.Volumes = volumes;
				else
				{
					mangaDetail.Volumes = null;
				}
			}
		}
Exemplo n.º 4
0
		private static void SetMyScore(HtmlDocument document, MangaDetail mangaDetail)
		{
			var myScoreNode = document.DocumentNode.SelectSingleNode("//select[@id='myinfo_score']");

			if (myScoreNode != null)
			{
				var selectedOption =
					myScoreNode.ChildNodes.Where(c => c.Name.ToLowerInvariant() == "option");

				var selected = from c in selectedOption
							   from x in c.Attributes
							   where x.Name.ToLowerInvariant() == "selected"
							   select c;

				if (selected.FirstOrDefault() != null)
				{
					var scoreNode = from c in selected.FirstOrDefault().Attributes
									where c.Name.ToLowerInvariant() == "value"
									select c;

					var score = scoreNode.FirstOrDefault();

					if (score == null || score.Value == null)
						mangaDetail.Score = 0;
					else
						mangaDetail.Score = Convert.ToInt32(score.Value);
				}
			}
		}
Exemplo n.º 5
0
		private static void SetStatus(HtmlNode leftColumnNodeset, MangaDetail mangaDetail)
		{
			var status = leftColumnNodeset.SelectSingleNode("//span[text()='Status:']");

			if (status != null)
				mangaDetail.Status = status.NextSibling.InnerText;
		}
Exemplo n.º 6
0
		private static void SetTitle(HtmlDocument document, MangaDetail mangaDetail)
		{
			var titleNode = document.DocumentNode.SelectSingleNode("//span[@itemprop='name']");

			if (titleNode != null)
				mangaDetail.Title = HttpUtility.HtmlDecode(titleNode.InnerText.Trim());
		}
Exemplo n.º 7
0
		private static void SetId(HtmlDocument document, MangaDetail mangaDetail)
		{
			var mangaIdInput = document.DocumentNode.SelectSingleNode("//input[@name='mid']");

			if (mangaIdInput != null)
			{
				mangaDetail.Id = Convert.ToInt32(mangaIdInput.Attributes["value"].Value);
			}
			else
			{
				var detailLink = document.DocumentNode.SelectSingleNode("//a[text()='Details']");

				if (detailLink != null)
				{
					var regex = Regex.Match(detailLink.Attributes["href"].Value, @"\d+");
					mangaDetail.Id = Convert.ToInt32(regex.ToString());
				}
			}
		}
Exemplo n.º 8
0
		private static void SetFavorite(HtmlNode leftColumnNodeset, MangaDetail mangaDetail)
		{
			var favorite = leftColumnNodeset.SelectSingleNode("//span[text()='Favorites:']");

			if (favorite != null)
			{
				int favoritedCount;
				if (Int32.TryParse(favorite.NextSibling.InnerText.Replace(",", ""), out favoritedCount))
					mangaDetail.FavoritedCount = favoritedCount;
				else
				{
					mangaDetail.FavoritedCount = null;
				}
			}
		}
Exemplo n.º 9
0
		private static void SetMember(HtmlNode leftColumnNodeset, MangaDetail mangaDetail)
		{
			var member = leftColumnNodeset.SelectSingleNode("//span[text()='Members:']");

			if (member != null)
			{
				int memberCount;
				if (Int32.TryParse(member.NextSibling.InnerText.Replace(",", ""), out memberCount))
					mangaDetail.MembersCount = memberCount;
				else
				{
					mangaDetail.MembersCount = null;
				}
			}
		}
Exemplo n.º 10
0
		private static void SetSynopsis(HtmlNode rightColumnNodeset, MangaDetail mangaDetail)
		{
			var synopsis = rightColumnNodeset.SelectSingleNode("//h2[text()='Synopsis']");

			if (synopsis != null)
			{
				mangaDetail.Synopsis = Regex.Replace(HttpUtility.HtmlDecode(synopsis.NextSibling.InnerText), "<br>", "");
			}
		}
Exemplo n.º 11
0
		private static void SetPopularTags(HtmlNode leftColumnNodeset, MangaDetail mangaDetail)
		{
			var popularTags = leftColumnNodeset.SelectSingleNode("//span[preceding-sibling::h2[text()='Popular Tags']]");

			if (popularTags != null)
			{
				mangaDetail.Tags = popularTags.ChildNodes.Where(c => c.Name == "a").Select(x => x.InnerText.Trim()).ToList();
			}
		}
Exemplo n.º 12
0
		private void SetRelatedManga(HtmlNode rightColumnNodeset, MangaDetail mangaDetail)
		{
			var relatedManga = rightColumnNodeset.SelectSingleNode("//h2[text()='Related Manga']");

			if (relatedManga != null)
			{
				//Alternative
				var alternativeVersion =
					Regex.Match(
						relatedManga.ParentNode.InnerHtml.Substring(relatedManga.ParentNode.InnerHtml.IndexOf("<h2>")),
						"Alternative versions?:+(.+?<br)");

				if (!string.IsNullOrEmpty(alternativeVersion.ToString()))
				{
					mangaDetail.AlternativeVersions = new List<MangaSummary>();

					SetMangaSummaryList(mangaDetail.AlternativeVersions, alternativeVersion.ToString());
				}

				//Adaptation
				var adaptation =
					Regex.Match(
						relatedManga.ParentNode.InnerHtml.Substring(relatedManga.ParentNode.InnerHtml.IndexOf("<h2>")),
						"Adaptation:+(.+?<br)");

				if (!string.IsNullOrEmpty(adaptation.ToString()))
				{
					mangaDetail.AnimeAdaptations = new List<AnimeSummary>();

					SetAnimeSummaryList(mangaDetail.AnimeAdaptations, adaptation.ToString());
				}


				//Related manga
				var prequel =
					Regex.Match(
						relatedManga.ParentNode.InnerHtml.Substring(relatedManga.ParentNode.InnerHtml.IndexOf("<h2>")),
						"Prequel:+(.+?<br)");

				mangaDetail.RelatedManga = new List<MangaSummary>();

				if (!string.IsNullOrEmpty(prequel.ToString()))
				{
					SetMangaSummaryList(mangaDetail.RelatedManga, prequel.ToString());
				}

				var sequel =
					Regex.Match(relatedManga.ParentNode.InnerHtml.Substring(relatedManga.ParentNode.InnerHtml.IndexOf("<h2>")),
						"Sequel:+(.+?<br)");

				if (!string.IsNullOrEmpty(sequel.ToString()))
				{
					SetMangaSummaryList(mangaDetail.RelatedManga, sequel.ToString());
				}

				var parentStory =
					Regex.Match(relatedManga.ParentNode.InnerHtml.Substring(relatedManga.ParentNode.InnerHtml.IndexOf("<h2>")),
						"Parent story:+(.+?<br)");

				if (!string.IsNullOrEmpty(parentStory.ToString()))
				{
					SetMangaSummaryList(mangaDetail.RelatedManga, parentStory.ToString());
				}

				var sideStory =
					Regex.Match(relatedManga.ParentNode.InnerHtml.Substring(relatedManga.ParentNode.InnerHtml.IndexOf("<h2>")),
						"Side story:+(.+?<br)");


				if (!string.IsNullOrEmpty(sideStory.ToString()))
				{
					SetMangaSummaryList(mangaDetail.RelatedManga, sideStory.ToString());
				}

				var character =
					Regex.Match(relatedManga.ParentNode.InnerHtml.Substring(relatedManga.ParentNode.InnerHtml.IndexOf("<h2>")),
						"Character:+(.+?<br)");

				if (!string.IsNullOrEmpty(character.ToString()))
				{
					SetMangaSummaryList(mangaDetail.RelatedManga, character.ToString());
				}

				var spinOff =
					Regex.Match(relatedManga.ParentNode.InnerHtml.Substring(relatedManga.ParentNode.InnerHtml.IndexOf("<h2>")),
						"Spin-off:+(.+?<br)");


				if (!string.IsNullOrEmpty(spinOff.ToString()))
				{
					SetMangaSummaryList(mangaDetail.RelatedManga, spinOff.ToString());
				}

				var summary =
					Regex.Match(relatedManga.ParentNode.InnerHtml.Substring(relatedManga.ParentNode.InnerHtml.IndexOf("<h2>")),
						"Summary:+(.+?<br)");

				if (!string.IsNullOrEmpty(summary.ToString()))
				{
					SetMangaSummaryList(mangaDetail.RelatedManga, summary.ToString());
				}
			}
		}
Exemplo n.º 13
0
		private static void SetReadStatus(HtmlDocument document, MangaDetail mangaDetail)
		{
			var readStatusNode = document.DocumentNode.SelectSingleNode("//select[@id='myinfo_status']");

			if (readStatusNode != null)
			{
				var selectedOption =
					readStatusNode.ChildNodes.Where(c => c.Name.ToLowerInvariant() == "option");

				var selected = from c in selectedOption
							   from x in c.Attributes
							   where x.Name.ToLowerInvariant() == "selected"
							   select c;

				if (selected.FirstOrDefault() != null)
					mangaDetail.ReadStatus = selected.FirstOrDefault().NextSibling.InnerText;
			}
		}
Exemplo n.º 14
0
		private static void SetChaptersRead(HtmlDocument document, MangaDetail mangaDetail)
		{
			var chapthersReadNode = document.DocumentNode.SelectSingleNode("//input[@id='myinfo_chapters']");

			if (chapthersReadNode != null)
			{
				var value =
					chapthersReadNode.Attributes.FirstOrDefault(c => c.Name.ToLowerInvariant() == "value");

				if (value != null)
				{
					int chaptersRead;

					if (Int32.TryParse(value.Value, out chaptersRead))
						mangaDetail.ChaptersRead = chaptersRead;
					else
					{
						mangaDetail.ChaptersRead = 0;
					}
				}
			}
		}
Exemplo n.º 15
0
		private static void SetAlternativeTitles(HtmlNode leftColumnNodeset, MangaDetail mangaDetail)
		{
			var englishAlternative = leftColumnNodeset.SelectSingleNode("//span[text()='English:']");

			mangaDetail.OtherTitles = new OtherTitles();

			if (englishAlternative != null)
			{
				mangaDetail.OtherTitles.English = englishAlternative.NextSibling.InnerText.Split(',').Select(p => p.Trim()).ToList();
			}

			var japaneseAlternative = leftColumnNodeset.SelectSingleNode("//span[text()='Japanese:']");

			if (japaneseAlternative != null)
			{
				mangaDetail.OtherTitles.Japanese = japaneseAlternative.NextSibling.InnerText.Split(',').Select(p => p.Trim()).ToList();
			}
		}
Exemplo n.º 16
0
		private static void SetPopularityRank(HtmlNode leftColumnNodeset, MangaDetail mangaDetail)
		{
			var popularity = leftColumnNodeset.SelectSingleNode("//span[text()='Popularity:']");

			if (popularity != null)
			{
				int popularityRank;

				if (Int32.TryParse(popularity.NextSibling.InnerText.Replace("#", "").Replace(",", ""), out popularityRank))
					mangaDetail.PopularityRank = popularityRank;
				else
				{
					mangaDetail.PopularityRank = null;
				}
			}
		}
Exemplo n.º 17
0
		private static void SetImageUrl(HtmlDocument document, MangaDetail mangaDetail)
		{
			var imageNode = document.DocumentNode.SelectSingleNode("//div[@id='content']//tr//td//div//img");

			if (imageNode != null)
				mangaDetail.ImageUrl = imageNode.Attributes["src"].Value;
		}
Exemplo n.º 18
0
		private static void SetScore(HtmlNode leftColumnNodeset, MangaDetail mangaDetail)
		{
			var score = leftColumnNodeset.SelectSingleNode("//span[text()='Score:']");

			if (score != null)
			{
				double memberScore;
				if (double.TryParse(score.NextSibling.NextSibling.InnerText, NumberStyles.Any, CultureInfo.InvariantCulture,
					out memberScore))
					mangaDetail.MembersScore = memberScore;
				else
				{
					mangaDetail.MembersScore = 0;
				}
			}
		}
Exemplo n.º 19
0
		private static void SetRank(HtmlDocument document, MangaDetail mangaDetail)
		{
			var rankNode = document.DocumentNode.SelectSingleNode("//span[contains(.,'Rank')]");

			if (rankNode != null)
			{
				if (rankNode.NextSibling.InnerText.ToUpper().Contains("N/A"))
					mangaDetail.Rank = 0;
				else
				{
					var regex = Regex.Match(rankNode.NextSibling.InnerText, @"\d+");
					mangaDetail.Rank = Convert.ToInt32(regex.ToString());
				}
			}
		}
Exemplo n.º 20
0
		private static void SetGenre(HtmlNode leftColumnNodeset, MangaDetail mangaDetail)
		{
			var genre = leftColumnNodeset.SelectSingleNode("//span[text()='Genres:']");

			if (genre != null)
			{
				mangaDetail.Genres = genre.ParentNode.ChildNodes.Where(c => c.Name == "a").Select(x => x.InnerText.Trim()).ToList();
			}
		}
Exemplo n.º 21
0
		public async Task<MangaDetail> GetMangaDetailAsync(string login, string password, int mangaId)
		{
			var cookies = await CookieHelper.GetCookies(login, password, UserAgent);

			RestClient.BaseUrl = new Uri(string.Format("http://myanimelist.net/manga/{0}", mangaId));

			var request = GetRestRequest(Method.GET, cookies);

			var result = await ExecuteTaskASync(request).ConfigureAwait(false);

			var mangaDetail = new MangaDetail();

			var document = new HtmlDocument();

			document.LoadHtml(result);

			SetId(document, mangaDetail);

			SetRank(document, mangaDetail);

			SetTitle(document, mangaDetail);

			SetImageUrl(document, mangaDetail);

			var leftColumnNodeset =
				document.DocumentNode.SelectSingleNode("//div[@id='content']//table//tr//td[@class='borderClass']");

			if (leftColumnNodeset != null)
			{
				SetAlternativeTitles(leftColumnNodeset, mangaDetail);

				SetType(document, mangaDetail);

				SetVolume(leftColumnNodeset, mangaDetail);

				SetChapter(leftColumnNodeset, mangaDetail);

				SetStatus(leftColumnNodeset, mangaDetail);

				SetGenre(leftColumnNodeset, mangaDetail);

				SetScore(leftColumnNodeset, mangaDetail);

				SetPopularityRank(leftColumnNodeset, mangaDetail);

				SetMember(leftColumnNodeset, mangaDetail);

				SetFavorite(leftColumnNodeset, mangaDetail);

				SetPopularTags(leftColumnNodeset, mangaDetail);
			}

			var rightColumnNodeset =
			  document.DocumentNode.SelectSingleNode("//div[@id='content']/table/tr/td/div/table");

			if (rightColumnNodeset != null)
			{
				SetSynopsis(rightColumnNodeset, mangaDetail);

				SetRelatedManga(rightColumnNodeset, mangaDetail);
			}

			SetReadStatus(document, mangaDetail);

			SetChaptersRead(document, mangaDetail);

			SetVolumesRead(document, mangaDetail);

			SetMyScore(document, mangaDetail);

			SetListedMangaId(document, mangaDetail);

			return mangaDetail;
		}
Exemplo n.º 22
0
		private static void SetListedMangaId(HtmlDocument document, MangaDetail mangaDetail)
		{
			var editDetailNode = document.DocumentNode.SelectSingleNode("//a[text()='Edit Details']");

			if (editDetailNode != null)
			{
				var hrefValue = editDetailNode.Attributes["href"].Value;

				var regex = Regex.Match(hrefValue, @"\d+");

				mangaDetail.ListedMangaId = Convert.ToInt32(regex.ToString());
			}
		}