/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="args"></param> /// <param name="site"></param> /// <param name="options"></param> private void FourChanBrowserOnDocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs args, Website site, WebsiteOptions options) { if (options.Url.Contains("boards.4chan.org") == false || options.Url.Contains("/thread/") == false) { MessageBox.Show("Invalid web url.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); CanDownload = true; return; } var browser = (WebBrowser)sender; if (browser.Document?.Body == null) { return; } int count = 0; int total = 0; var title = _formatters[site].Invoke(browser.DocumentTitle); //create subfolder for thread Directory.CreateDirectory(Path.Combine(options.Folder, title)); foreach (var element in browser.Document.Body.GetElementsByTagName("div").OfType <HtmlElement>()) { try { var child = element.Children.OfType <HtmlElement>().FirstOrDefault(e => e.GetAttribute("className") == "fileText"); if (child == null) { continue; } total++; if (((FourChanOptionsContext)options).ParseInnerHtmlAndDownload(child.OuterHtml, title, Client)) { count++; } } catch (Exception ex) { Debug.WriteLine(ex.Message); } } MessageBox.Show( string.Format("Successfully downloaded {0} images out of {2} to \"{1}\".", count, options.Folder, total), "Success", MessageBoxButton.OK, MessageBoxImage.Information); browser.Dispose(); CanDownload = true; }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="args"></param> /// <param name="site"></param> /// <param name="options"></param> private void EHentaiBrowserOnDocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs args, Website site, WebsiteOptions options) { var browser = (WebBrowser)sender; if (browser.Document?.Body == null) { return; } var title = _formatters[site].Invoke(browser.DocumentTitle); Debug.WriteLine(title); var folder = Path.Combine(options.Folder, title); Directory.CreateDirectory(folder); var links = browser.Document.GetElementsByTagName("a") .OfType <HtmlElement>() .Where(e => { var href = e.GetAttribute("href"); if (string.IsNullOrEmpty(href) || href.Length <= 2) { return(false); } return ((href[href.Length - 2] == '-' || href[href.Length - 3] == '-' || href[href.Length - 4] == '-') && href.StartsWith("https://e-hentai.org/s/")); }) .Select(e => e.GetAttribute("href")) .ToList(); foreach (var link in links) { var browser1 = new WebBrowser { ScriptErrorsSuppressed = true, AllowNavigation = true }; WebBrowserDocumentCompletedEventHandler handler = null; var link1 = link; handler = (s, a) => { browser1.DocumentCompleted -= handler; ProcessEHentaiPage(s, folder, link1.Substring(link1.LastIndexOf('-') + 1), links.Count); }; browser1.DocumentCompleted += handler; browser1.Url = new Uri(link); } }
public EmailSender(IOptions <WebsiteOptions> optionsAccessor) { _options = optionsAccessor.Value; }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="args"></param> /// <param name="site"></param> /// <param name="options"></param> private void NHentaiBrowserOnDocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs args, Website site, WebsiteOptions options) { var browser = (WebBrowser)sender; if (browser.Document?.Body == null) { return; } var title = _formatters[site].Invoke(browser.DocumentTitle); //create subfolder for thread Directory.CreateDirectory(Path.Combine(options.Folder, title)); const string thumbStart = "t.nhentai.net/galleries/"; string id = browser.Document.Body.OuterHtml .Substring(browser.Document.Body.OuterHtml.IndexOf(thumbStart, StringComparison.Ordinal) + thumbStart.Length) .TakeWhile(char.IsDigit).Aggregate("", (current, c) => current + c); int fails = 0; int image = 1; while (true) { try { var fileName = image + ".jpg"; var url = string.Format("https://i.nhentai.net/galleries/{0}/{1}", id, fileName); Client.DownloadFile(url, Path.Combine(options.Folder, title, fileName)); image++; } catch (WebException) { try { var fileName = image + ".png"; var url = string.Format("https://i.nhentai.net/galleries/{0}/{1}", id, fileName); Client.DownloadFile(url, Path.Combine(options.Folder, title, fileName)); image++; } catch (WebException ex) { Debug.WriteLine(ex); fails++; if (fails == 3) { browser.Dispose(); CanDownload = true; return; } } } } }
/// <summary> /// /// </summary> /// <param name="env"></param> /// <param name="websiteOption"></param> public BlazorBackgroundServices(IWebHostEnvironment env, WebsiteOptions websiteOption) { _env = env; websiteOption.WebRootPath = env.WebRootPath; }