public ComicInfo LoadUri(Uri Uri) { CurrentHost = Uri.Host; string CurrentHtml = Encoding.UTF8.GetString(TryDownload(Uri)); if (CurrentHtml.IsCloudflareTriggered()) { Cloudflare = JSTools.BypassCloudflare(Uri.AbsoluteUri); CurrentHtml = Encoding.UTF8.GetString(TryDownload(Uri)); } Document = new HtmlDocument(); Document.LoadHtml(CurrentHtml); ComicInfo Info = new ComicInfo(); Info.Title = Document.Descendants("title").First().InnerText; Info.Title = HttpUtility.HtmlDecode(Info.Title); Info.Title = Info.Title.Substring(0, Info.Title.LastIndexOf("-")).Trim(); Info.Cover = TryDownload(new Uri(Document .SelectSingleNode("//img[@class=\"img-thumbnail\"]") .GetAttributeValue("src", ""))); Info.ContentType = ContentType.Comic; return(Info); }
public ComicInfo LoadUri(Uri Uri) { string CurrentHtml = Encoding.UTF8.GetString(TryDownload(Uri)); if (CurrentHtml.IsCloudflareTriggered()) { Cloudflare = JSTools.BypassCloudflare(Uri.AbsoluteUri); CurrentHtml = Encoding.UTF8.GetString(TryDownload(Uri)); } Document = new HtmlDocument(); Document.LoadHtml(CurrentHtml); ComicInfo Info = new ComicInfo(); Info.Title = Document.SelectSingleNode("//div[@class=\"info-title\"]/h1").InnerText; Info.Title = HttpUtility.HtmlDecode(Info.Title); Info.Cover = TryDownload(new Uri(Document .SelectSingleNode("//div[contains(@class, \"info-img\")]/img") .GetAttributeValue("src", ""))); Info.ContentType = ContentType.Comic; return(Info); }
public ComicInfo LoadUri(Uri Uri) { Cookies = new CookieContainer(); CurrentUrl = Uri; ReverseChapters = Uri.Host.ToLower().Contains("manga47.com"); Document.LoadUrl(Uri, Cookies: Cookies); if (string.IsNullOrWhiteSpace(Document.ToHTML()) || Document.IsCloudflareTriggered()) { CFData = JSTools.BypassCloudflare(Uri.AbsoluteUri); Document.LoadHtml(CFData?.HTML); } ComicInfo Info = new ComicInfo(); var TitleNode = Document.SelectSingleNode("//div[@class='post-title']/*[self::h3 or self::h2 or self::h1]"); try { TitleNode.RemoveChild(TitleNode.ChildNodes.Where(x => x.Name == "span").Single()); } catch { } Info.Title = TitleNode.InnerText.Trim(); if (Info.Title.ToUpper().StartsWith("HOT")) { Info.Title = Info.Title.Substring(3); } Info.Title = HttpUtility.HtmlDecode(Info.Title).Trim(); var ImgNode = Document.SelectSingleNode("//div[@class='summary_image']/a/img"); var ImgUrl = ImgNode.GetAttributeValue("data-lazy-srcset", ""); if (string.IsNullOrWhiteSpace(ImgUrl)) { ImgUrl = ImgNode.GetAttributeValue("data-src", ""); } else { ImgUrl = ImgUrl.Trim().Split(',', ' ').First(); } if (string.IsNullOrWhiteSpace(ImgUrl)) { ImgUrl = ImgNode.GetAttributeValue("src", ""); } if (string.IsNullOrWhiteSpace(ImgUrl)) { ImgUrl = ImgNode.GetAttributeValue("data-cfsrc", ""); } if (ImgUrl.StartsWith("//")) { ImgUrl = "http:" + ImgUrl; } Info.Cover = ImgUrl.TryDownload(CFData); Info.ContentType = ContentType.Comic; return(Info); }
public int GetChapterPageCount(int ID) { var Page = GetChapterHtml(ID); string ChpScript = Page.SelectSingleNode("//script[contains(., \"chapterid\")]").InnerHtml; string CntScript = $"{ChpScript}imagecount;"; return((int)JSTools.EvaluateScript(CntScript)); }
private HtmlDocument GetChapterHtml(int ID) { HtmlDocument Document = new HtmlDocument(); string HTML = Encoding.UTF8.GetString(TryDownload(new Uri(ChapterLinks[ID]))); while (HTML.IsCloudflareTriggered()) { Cloudflare = JSTools.BypassCloudflare(ChapterLinks[ID]); HTML = Encoding.UTF8.GetString(TryDownload(new Uri(ChapterLinks[ID]))); } Document.LoadHtml(HTML); return(Document); }
public ComicInfo LoadUri(Uri Uri) { Cookies = new CookieContainer(); CurrentUrl = Uri; Document.LoadUrl(Uri, Cookies: Cookies); if (string.IsNullOrWhiteSpace(Document.ToHTML()) || Document.IsCloudflareTriggered()) { CFData = JSTools.BypassCloudflare(Uri.AbsoluteUri); Document.LoadHtml(CFData?.HTML); } ComicInfo Info = new ComicInfo(); Info.Title = HttpUtility.HtmlDecode(Document.SelectSingleNode("//*[(self::h1 or self::h2 or self::h3) and @class='entry-title']").InnerText.Trim()); var ImgNode = Document.SelectSingleNode("//div[@class='thumb']/img"); var ImgUrl = ImgNode.GetAttributeValue("data-lazy-srcset", ""); if (string.IsNullOrWhiteSpace(ImgUrl)) { ImgUrl = ImgNode.GetAttributeValue("data-src", ""); } else { ImgUrl = ImgUrl.Trim().Split(',', ' ').First(); } if (string.IsNullOrWhiteSpace(ImgUrl)) { ImgUrl = ImgNode.GetAttributeValue("src", ""); } if (string.IsNullOrWhiteSpace(ImgUrl)) { ImgUrl = ImgNode.GetAttributeValue("data-cfsrc", ""); } if (ImgUrl.StartsWith("//")) { ImgUrl = "http:" + ImgUrl; } Info.Cover = ImgUrl.TryDownload(CFData); Info.ContentType = ContentType.Comic; return(Info); }
private string[] GetChapterPages(int ID) { var Page = GetChapterHtml(ID); string KeyScript = Page.SelectSingleNode("//script[contains(., \"eval\")]").InnerHtml; string ChpScript = Page.SelectSingleNode("//script[contains(., \"chapterid\")]").InnerHtml; KeyScript = $"function $(a) {{var a = []; a.val = function(b){{return b}}; return a}}\r\n{KeyScript}"; string CntScript = $"{ChpScript}imagecount;"; string CidScript = $"{ChpScript}chapterid;"; int Count = (int)JSTools.EvaluateScript(CntScript); int ChpId = (int)JSTools.EvaluateScript(CidScript); string Key = (string)JSTools.EvaluateScript(KeyScript); string Link = ChapterLinks[ID]; Link = Link.Substring(0, Link.LastIndexOf("/")); List <string> Pages = new List <string>(); for (int i = 1; i <= Count;) { string URL = $"{Link}/chapterfun.ashx?cid={ChpId}&page={i}&key={Key}"; string JS = Encoding.UTF8.GetString(TryDownload(new Uri(URL), ChapterLinks[ID])); JS += "\r\nd.join('|');"; string Result = (string)JSTools.EvaluateScript(JS); if (Result == null) { break; } string[] cPages = Result.Split('|'); for (int x = 0; x < cPages.Length; x++, i++) { string cPage = cPages[x]; if (cPage.StartsWith("//")) { cPage = "https:" + cPage; } Pages.Add(cPage); } } return(Pages.ToArray()); }
private string[] GetChapterPages(int ID) { var Doc = new HtmlDocument(); Doc.LoadUrl(new Uri(LinkMap[ID])); var Script = Doc.SelectSingleNode("//script[contains(., \"var pages\")]").InnerHtml; Script = Script.Substring(0, Script.IndexOf("var next_chapter")); Script += "\r\nvar rst = []; for (var i = 0; i < pages.length; i++) rst.push(pages[i].url); rst;"; var Rst = (List <object>)JSTools.EvaluateScript(Script); return((from x in Rst select(string) x).ToArray()); }
private byte[] TryDownload(Uri Url, string Referer = "https://mangadex.org") { if (CFData != null) { return(Url.TryDownload(Referer, CFData?.UserAgent, Cookie: CFData?.Cookies)); } try { return(Url.TryDownload(Referer)); } catch { CFData = JSTools.BypassCloudflare(Url.AbsoluteUri); return(TryDownload(Url, Referer)); } }
private byte[] TryDownload(Uri Url, string Referer = "https://goldenmangas.top") { if (CFData != null) { return(Url.TryDownload(Referer, CFData?.UserAgent, Cookie: CFData?.Cookies)); } try { return(Url.TryDownload(Referer) ?? throw new Exception()); } catch { CFData = JSTools.BypassCloudflare(Url.AbsoluteUri); return(TryDownload(Url, Referer)); } }
public IEnumerable <byte[]> DownloadPages(int ID) { foreach (var PageUrl in GetChapterPages(ID)) { var Page = PageUrl.TryDownload(Referer: CurrentUrl); if (Page == null && CFData != null) { Page = PageUrl.TryDownload(CFData, Referer: CurrentUrl); } if (Page == null) { CFData = JSTools.BypassCloudflare(PageUrl); Page = PageUrl.TryDownload(CFData, Referer: CurrentUrl); } yield return(Page); } }
private string[] GetChapterPages(int ID) { var Page = GetChapterHtml(ID); List <string> Pages = new List <string>(); var Scripts = Page.SelectNodes("//body//script[@type=\"text/javascript\"]"); bool Found = false; foreach (var Node in Scripts) { if (!Node.InnerHtml.Contains("var images")) { continue; } Found = true; string JS = Node.InnerHtml.Substring("var images = ", "\"];") + "\"]"; var Result = (from x in JSTools.EvaluateScript <List <object> >(JS) select(string) x).ToArray(); foreach (string PageHtml in Result) { var PageUrl = PageHtml.Substring("src=", " ").Trim(' ', '\'', '"'); Pages.Add(PageUrl); } } if (!Found) { foreach (var Img in Page.SelectNodes("//section[@id='imageWrapper']//img")) { Pages.Add(Img.GetAttributeValue("src", string.Empty)); } } var Links = (from x in Pages select x.Replace(".webp", "").Replace("/images", "/mangas_files")).ToArray(); if (Links.Where(x => string.IsNullOrEmpty(System.IO.Path.GetExtension(x))).Any()) { return(Links.Select(x => x + ".webp").ToArray()); } return(Links); }
public IEnumerable <KeyValuePair <int, string> > EnumChapters() { int ID = ChapterLinks.Count; var Nodes = Document.SelectNodes("//div[@class=\"chapter-list\"]/div/span/a"); if (Nodes == null || Nodes.Count <= 0) { var SafeDoc = new HtmlDocument(); if (Document.IsCloudflareTriggered()) { CFData = JSTools.BypassCloudflare(CurrentUrl); SafeDoc.LoadHtml(CFData?.HTML); } else { SafeDoc = Document; } Nodes = SafeDoc.SelectNodes("//div[@class=\"chapter-list\"]/div/span/a"); if (Nodes == null || Nodes.Count <= 0) { Nodes = SafeDoc.SelectNodes("//a[@class=\"chapter-name text-nowrap\"]"); } if (Nodes == null || Nodes.Count <= 0) { Nodes = SafeDoc.SelectNodes("//div[@class=\"chapter-list\"]//a"); } } foreach (var Node in Nodes) { string Name = HttpUtility.HtmlDecode(Node.InnerText).ToLower(); string Link = Node.GetAttributeValue("href", string.Empty); if (!Name.ToLower().Contains("chapter")) { if (Link.ToLower().Contains("chapter")) { Name = Link.Substring("chapter"); } Name = (from x in Name.Split(' ', '-', '_') where double.TryParse(x, out _) select x).First(); } else { Name = Name.Substring("chapter").Trim(); } if (Name.Contains(":")) { Name = Name.Substring(0, Name.IndexOf(":")); } Link = Link.EnsureAbsoluteUrl(CurrentUrl); ChapterNames[ID] = DataTools.GetRawName(Name); ChapterLinks[ID] = Link; yield return(new KeyValuePair <int, string>(ID, ChapterNames[ID++])); } }