Beispiel #1
0
        public ComicInfo LoadUri(Uri Uri)
        {
            if (Uri.AbsoluteUri.Contains("/chapters/"))
            {
                Uri = new Uri(Uri.AbsoluteUri.Substring(0, Uri.AbsoluteUri.IndexOf("/chapters/")).TrimEnd('/') + "/chapters/1");
            }
            else
            {
                Uri = new Uri(Uri.AbsoluteUri.TrimEnd('/') + "/chapters/1");
            }

            if (CFData == null)
            {
                using (ChromiumWebBrowser Browser = new ChromiumWebBrowser()) {
                    Browser.WaitForLoad(Uri.AbsoluteUri);
                    do
                    {
                        CFData = Browser.BypassCloudflare();
                    } while (Browser.IsCloudflareTriggered());
                }
            }

            Document = new HtmlAgilityPack.HtmlDocument();
            Document.LoadUrl(Uri, Referer: "https://mangadex.org", UserAgent: CFData?.UserAgent ?? null, Cookies: CFData?.Cookies ?? null);

            ComicInfo Info = new ComicInfo();

            Info.Title = Document.SelectSingleNode("//*[@id=\"content\"]//h6/span[@class=\"mx-1\"]").InnerText;
            Info.Title = HttpUtility.HtmlDecode(Info.Title);

            Info.Cover = TryDownload(Document
                                     .SelectSingleNode("//*[@id=\"content\"]//img[@class=\"rounded\"]")
                                     .GetAttributeValue("src", string.Empty).EnsureAbsoluteUri("https://mangadex.org"));

            Info.ContentType = ContentType.Comic;

            CurrentUrl = Uri.AbsoluteUri;

            if (Uri.AbsolutePath.Trim('/').Split('/').Length == 4)
            {
                CurrentUrl = Document.SelectSingleNode("//link[@rel='canonical']").GetAttributeValue("href", null);
                CurrentUrl = CurrentUrl.TrimEnd() + "/chapters/1";
            }

            return(Info);
        }
Beispiel #2
0
        public IEnumerable <KeyValuePair <int, string> > EnumChapters()
        {
            int ID = ChapterLinks.Count;

            HtmlAgilityPack.HtmlDocument Page = Document;
            string CurrentPage = CurrentUrl;

            bool       Empty;
            List <int> Ids = new List <int>();

            ChapterLangs = new Dictionary <int, string>();
            ChapterLinks = new Dictionary <int, string>();
            ChapterNames = new Dictionary <int, string>();

            do
            {
                bool First = true;
                Empty = true;
                foreach (var Node in Page.SelectNodes("//*[@id=\"content\"]//div[contains(@class, \"chapter-row\")]"))
                {
                    if (First)
                    {
                        First = false;
                        continue;
                    }

                    var ChapterInfo = Node.SelectSingleNode(Node.XPath + "//a[@class=\"text-truncate\"]");
                    var ChapterLang = Node.SelectSingleNode(Node.XPath + "//span[contains(@class, \"flag\")]");

                    var Name = HttpUtility.HtmlDecode(ChapterInfo.InnerText).ToLower();
                    var Link = HttpUtility.HtmlDecode(ChapterInfo.GetAttributeValue("href", ""));
                    var Lang = HttpUtility.HtmlDecode(ChapterLang.GetAttributeValue("title", "")).Trim();

                    Link = Link.EnsureAbsoluteUrl("https://mangadex.org");

                    if (ChapterLinks.Values.Contains(Link))
                    {
                        continue;
                    }

                    Empty = false;

                    if (Name.Contains('-'))
                    {
                        Name = Name.Substring(0, Name.IndexOf("-"));
                    }

                    if (Name.Contains("vol."))
                    {
                        Name = Name.Substring("vol. ");

                        var Parts = Name.Split(' ');
                        if (Parts.Length > 2)
                        {
                            Name = Parts[2];
                        }
                        else
                        {
                            Name = char.ToUpper(Name[0]) + Name.Substring(1);
                        }
                    }
                    else if (Name.Contains("ch. "))
                    {
                        Name = Name.Substring("ch. ");
                    }

                    ChapterNames[ID] = DataTools.GetRawName(Name.Trim());
                    ChapterLinks[ID] = Link;
                    ChapterLangs[ID] = Lang;

                    Ids.Add(ID++);
                }

                if (!Empty)
                {
                    CurrentPage = GetNextPage(CurrentPage);
                    Page        = new HtmlAgilityPack.HtmlDocument();
                    Page.LoadUrl(CurrentPage, Referer: "https://mangadex.org", UserAgent: CFData?.UserAgent ?? null, Cookies: CFData?.Cookies ?? null);
                }
            } while (!Empty);

            string SelectedLang = SelectLanguage((from x in Ids select ChapterLangs[x]).Distinct().ToArray());

            return(from x in Ids
                   where ChapterLangs[x] == SelectedLang
                   select new KeyValuePair <int, string>(x, ChapterNames[x]));
        }