示例#1
0
        private void websiteTypeComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            modeComboBox.Items.Clear();

            WebNovelSource selectedWebsite = (WebNovelSource)websiteTypeComboBox.SelectedItem;
            var            availableModes  = selectedWebsite.AvailableModes;

            if (availableModes.Contains(WebNovelSource.Mode.TableOfContents))
            {
                modeComboBox.Items.Add("Table of Contents");
            }

            if (availableModes.Contains(WebNovelSource.Mode.NextChapterLink))
            {
                modeComboBox.Items.Add("Next Chapter Link");
            }

            modeComboBox.SelectedIndex = 0;
        }
示例#2
0
        private async void retrieveBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            string type             = string.Empty;
            string mode             = string.Empty;
            string modeSelectedText = string.Empty;
            int    amount           = 0;

            Invoke((MethodInvoker) delegate
            {
                type             = ((string)websiteTypeComboBox.SelectedItem).ToLower();
                mode             = ((string)modeComboBox.SelectedItem).ToLower();
                modeSelectedText = modeSelectedTextBox.Text;
                amount           = (int)amountNumericUpDown.Value;
            });

            if (!(modeSelectedText.StartsWith("http://") || modeSelectedText.StartsWith("https://")))
            {
                modeSelectedText = "http://" + modeSelectedText;
            }

            WebNovelSource source = GetSource(modeSelectedText, type);

            WebNovelInfo novelInfo = await source.GetNovelInfoAsync(modeSelectedText);

            if (mode == "table of contents")
            {
                ChapterLink[] links = (await source.GetChapterLinksAsync(modeSelectedText)).ToArray();

                Invoke((MethodInvoker) delegate
                {
                    foreach (ChapterLink link in links)
                    {
                        if (link.Unknown)
                        {
                            unknownListBox.Items.Add(link);
                        }
                        else
                        {
                            chaptersListBox.Items.Add(link);
                        }
                    }

                    if (novelInfo != null)
                    {
                        if (!string.IsNullOrEmpty(novelInfo.CoverUrl))
                        {
                            try
                            {
                                string coverUrl   = novelInfo.CoverUrl;
                                coverUrl          = coverUrl.StartsWith("//") ? coverUrl.Substring(2) : coverUrl;
                                coverTextBox.Text = new UriBuilder(coverUrl).Uri.AbsoluteUri;
                            }
                            catch (UriFormatException) { }
                        }

                        if (!string.IsNullOrEmpty(novelInfo.Title))
                        {
                            titleTextBox.Text = novelInfo.Title;
                        }
                    }

                    progressBar.Visible    = false;
                    retrieveButton.Enabled = true;
                });
            }
            else if (mode == "next chapter link")
            {
                ChapterLink firstChapter = new ChapterLink {
                    Url = modeSelectedText
                };
                ChapterLink current = firstChapter;

                int ctr      = 1;
                var chapters = new List <WebNovelChapter>();
                while (true)
                {
                    WebNovelChapter chapter;
                    try
                    {
                        chapter = await source.GetChapterAsync(current);
                    }
                    catch (HttpRequestException)
                    {
                        break;
                    }

                    if (chapter == null)
                    {
                        break;
                    }

                    if (string.IsNullOrEmpty(chapter.ChapterName))
                    {
                        chapter.ChapterName = current.Url;
                    }

                    chapters.Add(chapter);

                    WriteText($"Found Chapter {chapter.ChapterName}", Color.Green);

                    if (string.IsNullOrEmpty(chapter.NextChapterUrl) || chapter.Url == chapter.NextChapterUrl)
                    {
                        break;
                    }

                    current = new ChapterLink {
                        Url = chapter.NextChapterUrl
                    };

                    if (ctr == amount)
                    {
                        break;
                    }

                    ctr++;
                }

                Invoke((MethodInvoker) delegate
                {
                    chaptersListBox.Items.AddRange(chapters.Cast <object>().ToArray());

                    progressBar.Visible    = false;
                    retrieveButton.Enabled = true;
                });
            }
        }
示例#3
0
        private async void convertBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            var    items = new List <object>();
            string type  = string.Empty;
            string mode  = string.Empty;

            Invoke((MethodInvoker) delegate
            {
                type = ((string)websiteTypeComboBox.SelectedItem).ToLower();
                mode = ((string)modeComboBox.SelectedItem).ToLower();
                items.AddRange(chaptersListBox.Items.Cast <object>());
            });

            EBook book = new EBook
            {
                Title      = titleTextBox.Text,
                CoverImage = coverTextBox.Text
            };

            foreach (object obj in items)
            {
                if (obj is ChapterLink)
                {
                    ChapterLink link = (ChapterLink)obj;

                    try
                    {
                        WebNovelSource  source  = GetSource(link.Url, type);
                        WebNovelChapter chapter = await source.GetChapterAsync(link);

                        if (chapter == null)
                        {
                            WriteText($"Failed to process {link.Name}!", Color.Red);
                        }
                        else
                        {
                            book.Chapters.Add(new Chapter {
                                Name = link.Name, Content = chapter.Content
                            });

                            WriteText($"{link.Name} has been processed.", Color.Green);
                        }
                    }
                    catch (Exception ex)
                    {
                        WriteText($"Failed to process {link.Name}!", Color.Red);
                        WriteText($"ERROR: {ex}", Color.Red);
                    }

                    if (Settings.Default.DelayPerChapter > 0)
                    {
                        await Task.Delay(TimeSpan.FromSeconds(Settings.Default.DelayPerChapter));
                    }
                }
                else if (obj is WebNovelChapter)
                {
                    WebNovelChapter wn = (WebNovelChapter)obj;

                    book.Chapters.Add(new Chapter {
                        Name = wn.ChapterName, Content = wn.Content
                    });
                }
            }

            WriteText("Generating epub...");

            try
            {
                await book.GenerateEpubAsync(e.Argument.ToString());
            }
            catch (Exception ex)
            {
                WriteText("Error generating Epub", Color.Red);
                WriteText($"ERROR: {ex}", Color.Red);
            }

            WriteText("Done!", Color.Green);

            Invoke((MethodInvoker) delegate
            {
                progressBar.Visible   = false;
                convertButton.Enabled = true;
            });
        }
示例#4
0
 private WebNovelSource GetSource(string url, WebNovelSource fallback)
 {
     return(_sources.Get(url) ?? fallback);
 }