Pastebin PRO Accounts EASTER SPECIAL! For a limited time only get 40% discount on a LIFETIME PRO account! Offer Ends Soon!
- // MIND THAT I'M USING AN OPEN SOURCE SOLUTION TO ACCESS AND ANALYZE THE WEBCONTENT (HTMLAGILITYPACK)
- // I AM NOT GOING TO PASTE IT'S CODE IN HERE, GOOGLE IT YOURSELF
- //CLASS CONTENTACCESS
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Net;
- using HtmlAgilityPack;
- using System.IO;
- using System.Text.RegularExpressions;
- using System.Diagnostics;
- using System.Threading;
- namespace GetFromN
- {
- static class ContentAccess
- {
- static List<ImageInfo> iiList = new List<ImageInfo>();
- private static string LocalPath;
- public static double Progress = 0;
- public static string Status = "";
- private static double OnePercent = 0;
- //public static string RemoveSpecialCharacters(string str)
- //{
- // StringBuilder sb = new StringBuilder();
- // foreach (char c in str)
- // {
- // if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == '.' || c == '_' || c == '[' || c ==']')
- // {
- // sb.Append(c);
- // }
- // }
- // return sb.ToString();
- //}
- public static void Initialize(string ComicURI, string LocalePath)
- {
- //using (var stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("GetFromN.HtmlAgilityPack.dll"))
- //{
- // byte[] assemblyData = new byte[stream.Length];
- // stream.Read(assemblyData, 0, assemblyData.Length);
- // System.Reflection.Assembly.Load(assemblyData);
- //}
- Status = "Initializing...";
- LocalPath = LocalePath;
- HtmlWeb hatweb = new HtmlWeb();
- HtmlDocument htdocs = hatweb.Load(ComicURI);
- Status = "loaded baseUri";
- //INFO
- HtmlNode n1 = htdocs.DocumentNode.SelectSingleNode("//h1");
- Status = "FILE " + n1.InnerText;
- Thread.Sleep(500);
- LocalPath += @"\" + CleanInput(n1.InnerText);
- if (!Directory.Exists(LocalPath))
- {
- Directory.CreateDirectory(LocalPath);
- }
- Status = "checking Nodes";
- //
- HtmlNode n = htdocs.DocumentNode.SelectSingleNode("//div[@class='ncontainer']");
- string ThumbnailContainer = n.InnerHtml;
- htdocs.LoadHtml(ThumbnailContainer);
- HtmlNodeCollection HatNodes = htdocs.DocumentNode.SelectNodes(".//img");
- double onePerTempt = (double)50 / (double)HatNodes.Count;
- bool toggle = false;
- foreach (HtmlNode hn in HatNodes)
- {
- Thread.Sleep(50);
- Progress += onePerTempt;
- Status = "Creating virtual File ";
- if (toggle == true)
- {
- HtmlAttribute attr = hn.Attributes["src"];
- ImageInfo ii = new ImageInfo(attr.Value, LocalPath);
- Status += ii.FileName;
- iiList.Add(ii);
- toggle = false;
- continue;
- }
- toggle = true;
- }
- OnePercent = 50 / iiList.Count;
- }
- public static void Clear()
- {
- Progress = 0;
- Status = "";
- LocalPath = "";
- iiList.Clear();
- }
- static string CleanInput(string inp)
- {
- inp = inp.Replace(@"\","|");
- inp = inp.Replace(@"/", "|");
- inp = inp.Replace(@"[", "-");
- inp = inp.Replace(@"]", "-");
- inp = inp.Replace(@"|", "#");
- return inp;
- }
- //static string CleanInput(string strIn)
- //{
- // // Replace invalid characters with empty strings.
- // try
- // {
- // return Regex.Replace(strIn, @"[^\w\.@-]", "",// return Regex.Replace(strIn, @"[^\w\.@-]", "",
- // RegexOptions.None, TimeSpan.FromSeconds(1.5));
- // }
- // // If we timeout when replacing invalid characters,
- // // we should return Empty.
- // catch (RegexMatchTimeoutException)
- // {
- // return String.Empty;
- // }
- //}
- public static void ProcessImages()
- {
- foreach (ImageInfo ii in iiList)
- {
- Status = "Writing File " + ii.FileName;
- ii.SaveFile();
- Progress += OnePercent;
- }
- Status = "Finished!";
- }
- }
- }
- // CLASS IMAGEINFO
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.IO;
- using HtmlAgilityPack;
- using System.Net;
- using System.Text.RegularExpressions;
- namespace GetFromN
- {
- class ImageInfo
- {
- public ImageInfo(string ThumbNailPath, string LocalPath)
- {
- this.ThumbNailPath = ThumbNailPath;
- this.LocalPath = LocalPath;
- string Ext = Path.GetExtension(ThumbNailPath);
- string FNL = Path.GetFileNameWithoutExtension(ThumbNailPath);
- int RemovableNameLength = Path.GetFileName(ThumbNailPath).Length;
- OverDir = Path.GetDirectoryName(ThumbNailPath).Remove(0,2);
- OverDirNum = Path.GetFileName(OverDir);
- Number = Convert.ToInt32(FNL.Remove(FNL.Length - 1,1));
- FileName = Number + Ext;
- Level1Path = @"http://i.nhentai.net/galleries/" + OverDirNum +@"/"+ FileName;
- }
- public void SaveFile()
- {
- using (WebClient client = new WebClient())
- {
- try
- {
- client.DownloadFile(Level1Path, LocalPath + @"\" + FileName);
- }
- catch (Exception)
- {
- }
- }
- }
- public string ThumbNailPath { get; set; }
- public string LocalPath { get; set; }
- public string Level1Path { get; set; }
- public string FileName { get; set; }
- private string OverDir { get; set; }
- private string OverDirNum { get; set; }
- public int Number { get; set; }
- }
- }
- //CLASS MAINWINDOW
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- using System.Text.RegularExpressions;
- using HtmlAgilityPack;
- using System.Net;
- using System.IO;
- using System.ComponentModel;
- namespace GetFromN
- {
- /// <summary>
- /// Interaktionslogik für MainWindow.xaml
- /// </summary>
- public partial class MainWindow : Window
- {
- BackgroundWorker bw = new BackgroundWorker();
- BackgroundWorker bw2 = new BackgroundWorker();
- public MainWindow()
- {
- InitializeComponent();
- //using (var stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("GetFromN.HtmlAgilityPack.dll"))
- //{
- // byte[] assemblyData = new byte[stream.Length];
- // stream.Read(assemblyData, 0, assemblyData.Length);
- // //System.Reflection.Assembly.Load(assemblyData);
- // AppDomain.CurrentDomain.Load(assemblyData);
- //}
- bw.WorkerSupportsCancellation = true;
- bw.DoWork += new DoWorkEventHandler(bw_DoWork);
- bw2.WorkerSupportsCancellation = true;
- bw2.DoWork += new DoWorkEventHandler(bw2_DoWork);
- // bw.WorkerReportsProgress = true;
- }
- public string DestDir;
- public string DestURI;
- private void brwsBtn_Click(object sender, RoutedEventArgs e)
- {
- using (System.Windows.Forms.FolderBrowserDialog fbd = new System.Windows.Forms.FolderBrowserDialog())
- {
- DestURI = srcBox.Text;
- fbd.Description = "Select the Directory to Save your Images in, a subdirectory will be created automagically.";
- System.Windows.Forms.DialogResult objResult = fbd.ShowDialog();
- if (objResult == System.Windows.Forms.DialogResult.OK)
- {
- DestDir = fbd.SelectedPath;
- pthBox.Text = System.IO.Path.GetFileName(DestDir);
- }
- else
- {
- pthBox.Text = "cancelled";
- }
- }
- }
- private void dwnButton_Click(object sender, RoutedEventArgs e)
- {
- if (pthBox.Text != "cancelled")
- {
- bw2.RunWorkerAsync();
- bw.RunWorkerAsync();
- }
- if (dwnButton.Content.ToString() =="Start over")
- {
- System.Diagnostics.Process.Start(Application.ResourceAssembly.Location);
- Application.Current.Shutdown();
- }
- }
- private void bw_DoWork(object sender, DoWorkEventArgs e)
- {
- BackgroundWorker worker = sender as BackgroundWorker;
- if (uribox.Items.Count > 0)
- {
- foreach (string s in uribox.Items)
- {
- ContentAccess.Initialize(s, DestDir);
- ContentAccess.ProcessImages();
- ContentAccess.Clear();
- pbStatus.Value = 100;
- StatusLabel.Content = "Finished";
- dwnButton.Content = "Start over";
- bw.CancelAsync();
- }
- }
- if (uribox.Items.Count == 0)
- {
- ContentAccess.Initialize(DestURI, DestDir);
- ContentAccess.ProcessImages();
- pbStatus.Value = 100;
- StatusLabel.Content = "Finished";
- dwnButton.Content = "Start over";
- bw.CancelAsync();
- }
- }
- private void bw2_DoWork(object sender, DoWorkEventArgs e)
- {
- while (ContentAccess.Progress <= 100)
- {
- double Progress = 0.0;
- string Status ="";
- Dispatcher.Invoke(new Action(() => Progress = ContentAccess.Progress));
- Dispatcher.Invoke(new Action(() => Status = ContentAccess.Status));
- Dispatcher.Invoke(new Action(() => pbStatus.Value = Progress));
- Dispatcher.Invoke(new Action(() => StatusLabel.Content = Status));
- }
- Dispatcher.Invoke(new Action(() => dwnButton.Content = "Start over"));
- bw2.CancelAsync();
- }
- private void button_Click(object sender, RoutedEventArgs e)
- {
- if (srcBox.Text != "")
- {
- uribox.Items.Add(srcBox.Text);
- srcBox.Text = "";
- }
- }
- private void pstBTN_Click(object sender, RoutedEventArgs e)
- {
- srcBox.Text = Clipboard.GetText();
- }
- private void pstaddBTN_Click(object sender, RoutedEventArgs e)
- {
- srcBox.Text = "";
- uribox.Items.Add(Clipboard.GetText());
- }
- private void rmbtn_Click(object sender, RoutedEventArgs e)
- {
- uribox.Items.RemoveAt(uribox.SelectedIndex);
- }
- }
- }
RAW Paste Data

