示例#1
0
        public IEnumerable <KeyValuePair <int, string> > EnumChapters()
        {
            int          ID          = ChapterLinks.Count;
            HtmlDocument Page        = Document;
            string       CurrentPage = CurrentUrl;

            bool Empty;

            do
            {
                Empty = true;
                var Nodes = Page.DocumentNode.SelectNodes("//h2[@class=\"chap\"]/a");
                if (Nodes == null)
                {
                    break;
                }
                foreach (var Node in Nodes)
                {
                    Empty = false;

                    var Name = HttpUtility.HtmlDecode(Node.InnerText).ToLower();
                    var Link = HttpUtility.HtmlDecode(Node.GetAttributeValue("href", ""));

                    if (Name.Contains("ch. "))
                    {
                        Name = Name.Substring("ch. ");
                    }
                    else if (Name.Contains("chap "))
                    {
                        Name = Name.Substring("chap ");
                    }

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

                    Name = DataTools.GetRawName(Name.Trim());

                    ChapterNames[ID] = Name;
                    ChapterLinks[ID] = Link;

                    yield return(new KeyValuePair <int, string>(ID++, Name));
                }

                if (!Empty)
                {
                    CurrentPage = GetNextPage(CurrentPage);
                    Page        = new HtmlDocument();
                    Page.LoadUrl(CurrentPage);
                }
            } while (!Empty);
        }
示例#2
0
        public IEnumerable <KeyValuePair <int, string> > EnumChapters()
        {
            int ID = ChapterLinks.Count;

            foreach (var Node in Document.SelectNodes("//table[@class=\"listing\"]//a"))
            {
                ChapterLinks[ID] = Node.GetAttributeValue("href", string.Empty).EnsureAbsoluteUrl("https://kissmanga.com");
                ChapterNames[ID] = DataTools.GetRawName(GetChapterName(ChapterLinks[ID]));

                yield return(new KeyValuePair <int, string>(ID, ChapterNames[ID++]));
            }
        }
示例#3
0
        public IEnumerable <KeyValuePair <int, string> > EnumChapters()
        {
            int ID = ChapterLinks.Count;

            foreach (var Node in Document.SelectNodes("//div[@class=\"row lancamento-linha\"]/div[1]/a"))
            {
                string Name = HttpUtility.HtmlDecode(Node.InnerText);
                Name             = Name.Substring("Cap.").Trim();
                ChapterNames[ID] = DataTools.GetRawName(Name);
                ChapterLinks[ID] = Node.GetAttributeValue("href", string.Empty);
                yield return(new KeyValuePair <int, string>(ID, ChapterNames[ID++]));
            }
        }
示例#4
0
        public IEnumerable <KeyValuePair <int, string> > EnumChapters()
        {
            int ID = ChapterLinks.Count;

            foreach (var Node in Document.SelectNodes("//table//a"))
            {
                string Name = HttpUtility.HtmlDecode(Node.InnerText).ToLower();
                Name = Name.Substring("chapter").Trim();

                ChapterNames[ID] = DataTools.GetRawName(Name);
                ChapterLinks[ID] = Node.GetAttributeValue("href", string.Empty).EnsureAbsoluteUrl(CurrentDomain);
                yield return(new KeyValuePair <int, string>(ID, ChapterNames[ID++]));
            }
        }
示例#5
0
        public IEnumerable <KeyValuePair <int, string> > EnumChapters()
        {
            int ID = ChapterNames.Count;

            foreach (var Node in Document.SelectNodes("//ul[@class='capitulos']//a[starts-with(@href, '/manga')]"))
            {
                string URL  = HttpUtility.HtmlDecode(Node.GetAttributeValue("href", "")).EnsureAbsoluteUrl(CurrentDomain);
                string Name = URL.Substring(URL.LastIndexOf("/") + 1);
                Name = DataTools.GetRawName(Name);

                ChapterNames[ID] = Name;
                ChapterLinks[ID] = URL;

                yield return(new KeyValuePair <int, string>(ID++, Name));
            }
        }
示例#6
0
        public IEnumerable <KeyValuePair <int, string> > EnumChapters()
        {
            int ID = LinkMap.Count;

            foreach (var Chap in Document.SelectNodes("//div[@id='chapterlist']//a"))
            {
                string Name = HttpUtility.HtmlDecode(Chap.ChildNodes.Where(x => x.HasClass("chapternum")).First().InnerHtml.ToLowerInvariant().Trim());
                string URL  = Chap.GetAttributeValue("href", "");


                if (Name.StartsWith("chapter"))
                {
                    Name = Name.Substring("chapter").Trim();
                }

                if (Name.StartsWith("chap"))
                {
                    Name = Name.Substring("chap").Trim(' ', '\t', '.');
                }

                if (Name.StartsWith("cap"))
                {
                    Name = Name.Substring("cap").Trim(' ', '\t', '.');
                }

                if (Name.StartsWith("ch."))
                {
                    Name = Name.Substring("ch.", " ", IgnoreMissmatch: true);
                }

                if (Name.StartsWith("capítulo"))
                {
                    Name = Name.Substring("capítulo").Trim(' ', '\t', '.');
                }

                if (Name.Contains("-"))
                {
                    Name = Name.Split('-').First().Trim();
                }

                Name = DataTools.GetRawName(Name);

                LinkMap[ID] = URL;

                yield return(new KeyValuePair <int, string>(ID++, Name));
            }
        }
示例#7
0
        public IEnumerable <KeyValuePair <int, string> > EnumChapters()
        {
            int ID = ChapterLinks.Count;

            foreach (var Node in Document.SelectNodes("//div[@class=\"list-chapter\"]/table/tbody/tr/td[1]/a"))
            {
                string Name = HttpUtility.HtmlDecode(Node.InnerText);
                Name = Name.Substring("chapter").Trim();

                if (Name.Contains(":"))
                {
                    Name = Name.Split(':').First();
                }

                ChapterNames[ID] = DataTools.GetRawName(Name);
                ChapterLinks[ID] = Node.GetAttributeValue("href", string.Empty);
                yield return(new KeyValuePair <int, string>(ID, ChapterNames[ID++]));
            }
        }
示例#8
0
        public IEnumerable <KeyValuePair <int, string> > EnumChapters()
        {
            int    ID          = ChapterLinks.Count;
            var    Page        = Document;
            string CurrentPage = CurrentUrl;

            bool Empty;

            do
            {
                Empty = true;
                foreach (var Node in Page.SelectNodes("//ul[@id=\"_listUl\"]/li"))
                {
                    var LinkNode = Node.SelectSingleNode(Node.XPath + "/a");

                    var Name = HttpUtility.HtmlDecode(Node.GetAttributeValue("data-episode-no", "")).ToLower();
                    Name = DataTools.GetRawName(Name.Trim());

                    var Link = HttpUtility.HtmlDecode(LinkNode.GetAttributeValue("href", ""));

                    if (ChapterLinks.ContainsValue(Link))
                    {
                        continue;
                    }

                    Empty = false;

                    ChapterNames[ID] = Name;
                    ChapterLinks[ID] = Link;

                    yield return(new KeyValuePair <int, string>(ID, ChapterNames[ID++]));
                }

                if (!Empty)
                {
                    CurrentPage = GetNextPage(CurrentPage);
                    Page        = new HtmlDocument();
                    Page.LoadUrl(CurrentPage, Referer: Referer);
                }
            } while (!Empty);
        }
示例#9
0
        public IEnumerable <KeyValuePair <int, string> > EnumChapters()
        {
            int ID = ChapterLinks.Count;

            foreach (var Node in Document.SelectNodes("//ul[@class=\"detail-main-list\"]/li/a"))
            {
                var NameNode = Document.SelectSingleNode(Node.XPath + "/div/p[@class=\"title3\"]");

                string Name = NameNode.InnerText;
                Name = Name.Substring("ch.");

                if (Name.Contains("-"))
                {
                    Name = Name.Split('-')[0];
                }

                ChapterNames[ID] = DataTools.GetRawName(Name.Trim());
                ChapterLinks[ID] = Node.GetAttributeValue("href", string.Empty).EnsureAbsoluteUrl("https://www.mangahere.cc/");

                yield return(new KeyValuePair <int, string>(ID, ChapterNames[ID++]));
            }
        }
示例#10
0
        public IEnumerable <KeyValuePair <int, string> > EnumChapters()
        {
            int ID = LinkMap.Count;

            var XPATH = "//li[starts-with(@class, 'wp-manga-chapter')]/a";
            var Nodes = Document.SelectNodes(XPATH);


            if (Nodes == null || Nodes.Count == 0)
            {
                var Browser = JSTools.DefaultBrowser;
                Browser.WaitForLoad(CurrentUrl.AbsoluteUri);

                var Begin = DateTime.Now;
                while (Nodes == null || Nodes.Count == 0)
                {
                    if ((DateTime.Now - Begin).TotalSeconds > 20)
                    {
                        break;
                    }
                    Document = Browser.GetDocument();
                    Nodes    = Document.SelectNodes(XPATH);
                }
            }

            foreach (var Node in ReverseChapters ? Nodes.Reverse() : Nodes)
            {
                string URL    = Node.GetAttributeValue("href", "");
                string Name   = Node.InnerText.Trim().ToLower();
                string Prefix = string.Empty;

                char[] GeneralTrim = new char[] { ' ', '-', '\t', '.' };

                if (Name.StartsWith("vol"))
                {
                    Name   = Name.Substring(" ").Trim();
                    Prefix = "Vol. " + Name.Substring(null, " ") + " Ch. ";
                    Name   = Name.Substring(" ").Trim(GeneralTrim);
                }

                if (Name.StartsWith("chapter"))
                {
                    Name = Name.Substring("chapter").Trim(GeneralTrim);
                }

                if (Name.StartsWith("chap"))
                {
                    Name = Name.Substring("chap").Trim(GeneralTrim);
                }

                if (Name.StartsWith("capítulo"))
                {
                    Name = Name.Substring("capítulo").Trim(GeneralTrim);
                }

                if (Name.StartsWith("cap"))
                {
                    Name = Name.Substring("cap").Trim(GeneralTrim);
                }

                if (Name.StartsWith("ch."))
                {
                    Name = Name.Substring("ch.", " ", IgnoreMissmatch: true);
                }

                if (Name.Contains("-"))
                {
                    Name = Name.Split('-').First().Trim(GeneralTrim);
                }

                Name = Prefix + DataTools.GetRawName(Name);

                LinkMap[ID] = URL;

                yield return(new KeyValuePair <int, string>(ID++, Name));
            }
        }
示例#11
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]));
        }
示例#12
0
        public VSButton LoadUri(Uri Uri, IHost Host)
        {
            Status = CurrentLanguage.LoadingComic;

            CurrentHost = CreateInstance(Host);

            CurrentInfo     = CurrentHost.LoadUri(Uri);
            TitleLabel.Text = CurrentInfo.Title;
            CoverBox.Image  = CurrentHost.GetDecoder().Decode(CurrentInfo.Cover);

            if (CurrentInfo.Url == null)
            {
                CurrentInfo.Url = Uri;
            }

            CoverBox.Cursor = Cursors.Default;

            string Dir = DataTools.GetRawName(CurrentInfo.Title.Trim(), FileNameMode: true);

            ChapterTools.MatchLibraryPath(ref Dir, Settings.LibraryPath, CurrentInfo.Url, ReplaceMode.UpdateURL, CurrentLanguage);
            RefreshCoverLink(Dir);

            var OnlinePath = Path.Combine(Settings.LibraryPath, Dir, "Online.url");

            if (Directory.Exists(Dir) && !File.Exists(OnlinePath))
            {
                var OnlineData = string.Format(Properties.Resources.UrlFile, CurrentInfo.Url.AbsoluteUri);
                File.WriteAllText(OnlinePath, OnlineData);
            }

            ButtonsContainer.Controls.Clear();

            VSButton DownAll = null;

            var Chapters = new Dictionary <int, string>();

            foreach (var Chapter in CurrentHost.EnumChapters())
            {
                if (Chapters.ContainsValue(Chapter.Value))
                {
                    continue;
                }

                VSButton Button = new VSButton()
                {
                    Size        = new Size(110, 30),
                    Text        = string.Format(CurrentLanguage.ChapterName, Chapter.Value),
                    Indentifier = CurrentHost
                };

                Button.Click += (sender, args) =>
                {
                    try
                    {
                        IHost HostIsnt = (IHost)((VSButton)sender).Indentifier;
                        DownloadChapter(Chapters, Chapter.Key, HostIsnt, CurrentInfo);
                    }
                    catch (Exception ex)
                    {
                        if (Program.Debug)
                        {
                            throw;
                        }
                    }
                    StatusBar.SecondLabelText = string.Empty;
                    Status = CurrentLanguage.IDLE;
                };

                DownAll = Button;

                ButtonsContainer.Controls.Add(Button);
                Chapters.Add(Chapter.Key, Chapter.Value);
            }

            if (Chapters.Count > 1)
            {
                VSButton Button = new VSButton()
                {
                    Size        = new Size(110, 30),
                    Text        = CurrentLanguage.DownloadAll,
                    Indentifier = CurrentHost
                };

                Button.Click += (sender, args) =>
                {
                    foreach (var Chapter in Chapters.Reverse())
                    {
                        try
                        {
                            IHost HostIsnt = (IHost)((VSButton)sender).Indentifier;
                            DownloadChapter(Chapters, Chapter.Key, HostIsnt, CurrentInfo);
                        }
                        catch (Exception ex)
                        {
                            if (Program.Debug)
                            {
                                throw;
                            }
                        }

                        StatusBar.SecondLabelText = string.Empty;
                        Status = CurrentLanguage.IDLE;
                    }
                };
                DownAll = Button;
                ButtonsContainer.Controls.Add(Button);
            }

            var PActions = CurrentHost.GetPluginInfo().Actions;

            if (PActions != null)
            {
                var Actions = (from x in PActions where x.Availability.HasFlag(ActionTo.ChapterList) select x);

                if (Actions.Any())
                {
                    foreach (var Action in Actions)
                    {
                        VSButton Bnt = new VSButton()
                        {
                            Size        = new Size(110, 30),
                            Text        = Action.Name,
                            Indentifier = CurrentHost
                        };
                        Bnt.Click += (sender, args) => Action.Action();
                        ButtonsContainer.Controls.Add(Bnt);
                    }
                    ;
                }
            }

            Status = CurrentLanguage.IDLE;

            return(DownAll);
        }
示例#13
0
        private void DownloadChapter(Dictionary <int, string> Chapters, int ID, IHost Host, ComicInfo Info)
        {
            string Name = DataTools.GetRawName(Chapters[ID], FileNameMode: true);

            StatusBar.SecondLabelText = $"{Info.Title} - {string.Format(CurrentLanguage.ChapterName, Name)}";
            Status = CurrentLanguage.Loading;

            int KIndex = Chapters.IndexOfKey(ID);

            string LName          = null;
            string LastChapterPah = null;

            if (KIndex + 1 < Chapters.Keys.Count)
            {
                LName = DataTools.GetRawName(Chapters.Values.ElementAt(KIndex + 1), FileNameMode: true);
            }

            string NName           = null;
            string NextChapterPath = null;

            if (KIndex > 0)
            {
                NName = DataTools.GetRawName(Chapters.Values.ElementAt(KIndex - 1), FileNameMode: true);
            }

            string Title = DataTools.GetRawName(Info.Title.Trim(), FileNameMode: true);

            ChapterTools.MatchLibraryPath(ref Title, Settings.LibraryPath, CurrentInfo.Url, (ReplaceMode)Settings.ReplaceMode, CurrentLanguage);
            RefreshCoverLink(Title);

            string TitleDir = Path.Combine(Settings.LibraryPath, Title);

            if (!Directory.Exists(TitleDir))
            {
                Directory.CreateDirectory(TitleDir);
                RefreshLibrary();
            }

            if (LName != null)
            {
                ChapterTools.GetChapterPath(Languages, CurrentLanguage, TitleDir, LName, out LastChapterPah, false);
            }

            ChapterTools.GetChapterPath(Languages, CurrentLanguage, TitleDir, Name, out string ChapterPath, false);

            if (NName != null)
            {
                ChapterTools.GetChapterPath(Languages, CurrentLanguage, TitleDir, NName, out NextChapterPath, false);
            }

            string AbsoluteChapterPath = Path.Combine(TitleDir, ChapterPath);

            if (Settings.SkipDownloaded && File.Exists(AbsoluteChapterPath.TrimEnd('\\', '/') + ".html"))
            {
                return;
            }

            int PageCount = 1;

            if (Info.ContentType == ContentType.Comic)
            {
                PageCount = Host.GetChapterPageCount(ID);

                if (Directory.Exists(AbsoluteChapterPath) && Directory.GetFiles(AbsoluteChapterPath, "*").Length < PageCount)
                {
                    Directory.Delete(AbsoluteChapterPath, true);
                }

                if (Settings.SkipDownloaded && Directory.Exists(AbsoluteChapterPath))
                {
                    var Pages = (from x in Directory.GetFiles(AbsoluteChapterPath) select Path.GetFileName(x)).ToArray();
                    ChapterTools.GenerateComicReader(CurrentLanguage, Pages, LastChapterPah, NextChapterPath, TitleDir, ChapterPath, Name);
                    string OnlineData = string.Format(Properties.Resources.UrlFile, Info.Url.AbsoluteUri);
                    File.WriteAllText(Path.Combine(TitleDir, "Online.url"), OnlineData);
                    return;
                }
            }

            if (Info.ContentType == ContentType.Novel)
            {
                ChapterPath = Path.Combine(AbsoluteChapterPath, string.Format(CurrentLanguage.ChapterName, Name) + ".epub");
                if (Settings.SkipDownloaded && File.Exists(ChapterPath))
                {
                    return;
                }
            }


            if (!Directory.Exists(AbsoluteChapterPath))
            {
                Directory.CreateDirectory(AbsoluteChapterPath);
            }

            string UrlData = string.Format(Properties.Resources.UrlFile, Info.Url.AbsoluteUri);

            File.WriteAllText(Path.Combine(TitleDir, "Online.url"), UrlData);


            switch (Info.ContentType)
            {
            case ContentType.Comic:
                var           Decoder = Host.GetDecoder();
                List <string> Pages   = new List <string>();
                foreach (var Data in Host.DownloadPages(ID).CatchExceptions())
                {
                    Status = string.Format(CurrentLanguage.Downloading, Pages.Count + 1, PageCount);
                    Application.DoEvents();

                    bool IsWebP = Data.Length > 12 && BitConverter.ToUInt32(Data, 8) == 0x50424557;

                    try
                    {
#if NOASYNCSAVE
                        string PageName = $"{Pages.Count:D3}.png";
                        string PagePath = Path.Combine(TitleDir, ChapterPath, PageName);

                        Page OutPage = new Page();
                        OutPage.Data = Data;

                        if ((SaveAs)Settings.SaveAs != SaveAs.RAW)
                        {
                            using (Bitmap Result = Decoder.Decode(Data))
                            {
                                PageName = $"{Pages.Count:D3}.{GetExtension(Result, out ImageFormat Format)}";
                                PagePath = OutPage.Path = Path.Combine(TitleDir, ChapterPath, PageName);

                                if (Result.GetImageExtension() == "png" && Settings.APNGBypass)
                                {
                                    var OutData = BypassAPNG(Data);
                                    OutPage.Data = OutData;
                                }
                                else
                                {
                                    using (MemoryStream tmp = new MemoryStream())
                                    {
                                        Result.Save(tmp, Format);
                                        OutPage.Data = tmp.ToArray();
                                    }
                                }
                            }
                        }

                        if (Settings.ImageClipping)
                        {
                            PostProcessQueue.Enqueue(OutPage);
                        }
                        else
                        {
                            File.WriteAllBytes(OutPage.Path, OutPage.Data);
                        }

                        while (PostProcessQueue.Count > 0)
                        {
                            ThreadTools.Wait(1000, true);
                        }
#else
                        string PageName = $"{Pages.Count:D3}.{(IsWebP ? "webp" : "png")}";
                        string PagePath = Path.Combine(TitleDir, ChapterPath, PageName);

                        Page OutPage = new Page();
                        OutPage.Data = Data;

                        if ((SaveAs)Settings.SaveAs != SaveAs.RAW)
                        {
                            byte[] ModData = null;

                            if (IsWebP)
                            {
                                ModData = DecodeWebP(Data);
                            }

                            using (MemoryStream Buffer = new MemoryStream())
                                using (Bitmap Result = Decoder.Decode(ModData ?? Data))
                                {
                                    PageName = $"{Pages.Count:D3}.{GetExtension(Result, out ImageFormat Format)}";
                                    PagePath = Path.Combine(TitleDir, ChapterPath, PageName);
                                    if (Result.GetImageExtension() == "png" && Settings.APNGBypass)
                                    {
                                        using (MemoryStream OutBuffer = new MemoryStream(BypassAPNG(ModData ?? Data)))
                                            using (Bitmap Img = new Bitmap(OutBuffer)) {
                                                Img.Save(Buffer, Format);
                                                OutPage.Data = Buffer.ToArray();
                                            }
                                    }
                                    else
                                    {
                                        Result.Save(Buffer, Format);
                                        OutPage.Data = Buffer.ToArray();
                                    }
                                }
                        }

                        OutPage.Path = PagePath;

                        if (PostProcessQueue.Count > 5)
                        {
                            const ulong MinMemory = 400000000;
                            while (AvailablePhysicalMemory < MinMemory && PostProcessQueue.Count > 0 || (Settings.MaxPagesBuffer != 0 && PostProcessQueue.Count >= Settings.MaxPagesBuffer))
                            {
                                ThreadTools.Wait(1000, true);
                            }
                        }

                        PostProcessQueue.Enqueue(OutPage);
#endif
                        Pages.Add(PageName);
                    }
                    catch (Exception ex)
                    {
                        if (Program.Debug)
                        {
                            throw;
                        }
                        Console.Error.WriteLine(ex.ToString());
                    }
                }

                if (Settings.ReaderGenerator)
                {
                    ChapterTools.GenerateComicReader(CurrentLanguage, Pages.ToArray(), LastChapterPah, NextChapterPath, TitleDir, ChapterPath, Name);
                    ChapterTools.GenerateReaderIndex(Languages, CurrentLanguage, Info, TitleDir, Name);
                }

                break;

            case ContentType.Novel:
                var Chapter = Host.DownloadChapter(ID);
                AsyncContext.Run(async() =>
                {
                    using (var Epub = await EPubWriter.CreateWriterAsync(File.Create(ChapterPath), Info.Title ?? "Untitled", Chapter.Author ?? "Anon", Chapter.URL ?? "None"))
                    {
                        Chapter.HTML.RemoveNodes("//script");
                        Chapter.HTML.RemoveNodes("//iframe");

                        foreach (var Node in Chapter.HTML.DocumentNode.DescendantsAndSelf())
                        {
                            if (Node.Name == "img" && Node.GetAttributeValue("src", string.Empty) != string.Empty)
                            {
                                string Src   = Node.GetAttributeValue("src", string.Empty);
                                string RName = Path.GetFileName(Src.Substring(null, "?", IgnoreMissmatch: true));
                                string Mime  = ResourceHandler.GetMimeType(Path.GetExtension(RName));

                                if (Node.GetAttributeValue("type", string.Empty) != string.Empty)
                                {
                                    Mime = Node.GetAttributeValue("type", string.Empty);
                                }

                                Uri Link = new Uri(Info.Url, Src);

                                if (string.IsNullOrWhiteSpace(RName))
                                {
                                    continue;
                                }

                                byte[] Buffer = await Link.TryDownloadAsync();

                                if (Buffer == null)
                                {
                                    continue;
                                }

                                await Epub.AddResourceAsync(RName, Mime, Buffer);
                                Node.SetAttributeValue("src", RName);
                            }

                            if (Node.Name == "link" && Node.GetAttributeValue("rel", string.Empty) == "stylesheet" && Node.GetAttributeValue("href", string.Empty) != string.Empty)
                            {
                                string Src   = Node.GetAttributeValue("href", string.Empty);
                                string RName = Path.GetFileName(Src.Substring(null, "?", IgnoreMissmatch: true));
                                string Mime  = ResourceHandler.GetMimeType(Path.GetExtension(RName));

                                if (Node.GetAttributeValue("type", string.Empty) != string.Empty)
                                {
                                    Mime = Node.GetAttributeValue("type", string.Empty);
                                }

                                Uri Link = new Uri(Info.Url, Src);

                                if (string.IsNullOrWhiteSpace(RName))
                                {
                                    continue;
                                }

                                byte[] Buffer = await Link.TryDownloadAsync();

                                if (Buffer == null)
                                {
                                    continue;
                                }

                                await Epub.AddResourceAsync(RName, Mime, Buffer);
                                Node.SetAttributeValue("href", RName);
                            }
                        }

                        Epub.Publisher = lblTitle.Text;

                        await Epub.AddChapterAsync("chapter.xhtml", Chapter.Title, Chapter.HTML.ToHTML());


                        await Epub.WriteEndOfPackageAsync();
                    }
                });
                break;

            default:
                throw new Exception("Invalid Content Type");
            }
        }
示例#14
0
        public IEnumerable <KeyValuePair <int, string> > EnumChapters()
        {
            int ID = ChapterLinks.Count;

            var Nodes = Document.SelectNodes("//div[@class=\"chapters\"]//div[@class=\"tags\"]/a");

            string Link = null;

            if (Nodes?.Count > 0)
            {
                Link = Nodes.First().GetAttributeValue("href", string.Empty);
            }

            if (string.IsNullOrEmpty(Link))
            {
                Link = OriUrl + "1";
            }

            bool Found = true;

            List <int> IDs = new List <int>();
            Dictionary <int, string> Founds = new Dictionary <int, string>();

            Dictionary <int, string> SortedFounds = new Dictionary <int, string>();

            while (Found)
            {
                var Doc = LoadDocument(Link);

                Link = Link.Substring(0, Link.LastIndexOf('/') + 1);
                var Options = Doc.SelectNodes("//header[@class=\"navigation\"]//select[@name=\"Chapters\"]/option");

                int BID = ID;

                Found = false;

                foreach (var Option in Options)
                {
                    var Value = Option.GetAttributeValue("value", string.Empty);
                    var URL   = Link + Value;

                    if (ChapterLinks.ContainsValue(URL))
                    {
                        continue;
                    }

                    Found = true;

                    ChapterLinks[ID] = URL;
                    ChapterNames[ID] = DataTools.GetRawName(Value);

                    Founds.Add(ID, ChapterNames[ID++].Trim());
                }

                for (int i = 0; i < ID - BID; i++)
                {
                    IDs.Insert(i, Founds.Keys.ElementAt(BID + i));
                }

                if (Found)
                {
                    Link = ChapterLinks[BID];
                }
            }

            foreach (var CID in IDs)
            {
                yield return(new KeyValuePair <int, string>(CID, ChapterNames[CID]));
            }
        }
示例#15
0
        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++]));
            }
        }