private void Download(ItemDown _ItemDown) { //ItemDown _ItemDown = (ItemDown)ItemDown; try { HttpWebRequest httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(_ItemDown.linkdown); HttpWebResponse httpWebReponse = (HttpWebResponse)httpWebRequest.GetResponse(); Stream stream = httpWebReponse.GetResponseStream(); Image image = Image.FromStream(stream); if (image != null) { //lets save image to disk image.Save(_ItemDown.savepath); _ItemDown.status = "Completed"; _ItemDown.percentage = 1; DataGridListDownload.Dispatcher.Invoke(DispatcherPriority.Background, new Action(delegate { DataGridListDownload.DataContext = null; DataGridListDownload.DataContext = MainQueueItemDownload; })); } } catch (Exception _ex) { _ItemDown.percentage = 2; _ItemDown.status = "Error";// + _ex.ToString(); } }
public void AddReturn() { ButtonAdd.IsEnabled = false; //Task taskCreateList = //Task.Factory.StartNew(() => //{ DataGridListDownload.DataContext = null; StreamReader sr = new StreamReader("data.txt"); string input = null; while ((input = sr.ReadLine()) != null) { string[] itemSplit = input.Split('#'); ItemDown item = new ItemDown(int.Parse(itemSplit[0]), itemSplit[1], itemSplit[2], int.Parse(itemSplit[3]), itemSplit[4]); if (!"".Equals(item.linkdown)) { MainQueueItemDownload.Add(item); } //MainQueueDownload.Enqueue(item); } sr.Close(); // }).ContinueWith(ant => //{ DataGridListDownload.DataContext = MainQueueItemDownload;// MainListItemsDownload; ButtonAdd.IsEnabled = true; //}, TaskScheduler.FromCurrentSynchronizationContext()); }
public override List <ItemDown> GetImagesLinkFromUrl() { List <ItemDown> listDown = new List <ItemDown>(); //create a new folder string targetfolder = ""; string directory; string foldername = CreateFolderName(this.url); targetfolder = savepath + "\\" + foldername;; System.IO.Directory.CreateDirectory(targetfolder); //lay link galery tu link chung List <string> listtemp = new List <string>(); StreamReader inStream; WebRequest webRequest; WebResponse webresponse; webRequest = WebRequest.Create(url); webresponse = webRequest.GetResponse(); inStream = new StreamReader(webresponse.GetResponseStream()); String htmlstring = inStream.ReadToEnd(); Document doc = NSoupClient.ParseBodyFragment(htmlstring); Elements Links = doc.Select("img"); foreach (Element link in Links) { string imagelink = link.Parent.Attr("href"); if (!(imagelink == "") && !(imagelink == "/")) { listtemp.Add("https://fuskator.com" + imagelink); //listtemp.Add(imagelink); } } foreach (string galerylink in listtemp) { //lay link anh tu cac link galery try { WebRequest webRequest2 = WebRequest.Create(galerylink); WebResponse webresponse2 = webRequest2.GetResponse(); StreamReader inStream2 = new StreamReader(webresponse.GetResponseStream()); String htmlstring2 = inStream2.ReadToEnd(); Document doc2 = NSoupClient.ParseBodyFragment(htmlstring2); Elements Links2 = doc2.Select("img"); int i = 0; //tach lay cai link image va down ve foreach (Element link in Links2) { string imagelink = "https:" + link.Parent.Attr("src"); string savename = imagelink.Substring(imagelink.LastIndexOf("/") + 1); directory = targetfolder + "\\" + savename; //if (i < 10) //directory = targetfolder + "\\" + savename + "00" + i + ".jpg"; //else if (i >= 10 && i < 100) //directory = targetfolder + "\\" + savename + "0" + i + ".jpg"; //else directory = targetfolder + "\\" + savename + i + ".jpg"; ItemDown temp = new ItemDown(i, directory, imagelink, 0, "waiting"); listDown.Add(temp); i++; } } catch (Exception ex) { } } return(listDown); }
public override List <ItemDown> GetImagesLinkFromUrl() { List <ItemDown> listDown = new List <ItemDown>(); //create a new folder string targetfolder = ""; string directory; //lay ten truyen -> tao duong dan cho gon string mangaName = url.Substring(url.LastIndexOf("/") + 1).Replace(".html", ""); StreamReader inStream; WebRequest webRequest; WebResponse webresponse; webRequest = WebRequest.Create(url); webresponse = webRequest.GetResponse(); inStream = new StreamReader(webresponse.GetResponseStream()); String htmlstring = inStream.ReadToEnd(); Document doc = NSoupClient.ParseBodyFragment(htmlstring); List <string> listTemp = new List <string>(); //Buoc 1: tu link ten truyen lay ra duong link cua tung chap Elements Links = doc.Select("a"); foreach (Element link in Links) { if ("item-even".Equals(link.Parent.Parent.ClassName()) || "item-odd".Equals(link.Parent.Parent.ClassName())) { string imagelink = link.SiblingElements.Text + "###" + "http://manga24h.com/" + link.Attr("href"); listTemp.Add(imagelink); } } //Buoc 2: tu link moi chap truyen dua ra cac link anh cua tung chap truyen foreach (string item in listTemp) { //tạo vị trí lưu string linkChap = item.Substring(item.LastIndexOf("###") + 3); string countChap = item.Substring(0, item.IndexOf("###")).Replace(@"\", "").Replace(@"/", "").Replace(@":", "") .Replace(@"*", "").Replace(@"?", "").Replace("\"", "").Replace(@"<", "").Replace(@">", "").Replace(@"|", ""); string foldername = CreateFolderName(linkChap); targetfolder = savepath + "\\" + mangaName + "\\" + countChap;// +"_" + foldername; System.IO.Directory.CreateDirectory(targetfolder); //down WebRequest webRequest2 = WebRequest.Create(linkChap); WebResponse webresponse2 = webRequest2.GetResponse(); StreamReader inStream2 = new StreamReader(webresponse2.GetResponseStream()); String htmlstring2 = inStream2.ReadToEnd(); int Start = htmlstring2.IndexOf("data='") + 6; int Stop = htmlstring2.IndexOf("images = new Array();"); string datacontent = htmlstring2.Substring(Start, Stop - Start); datacontent = datacontent.Substring(0, datacontent.LastIndexOf("';")); string[] linkdown = datacontent.Split('|'); //Document doc2 = NSoupClient.ParseBodyFragment(htmlstring2); //Elements linkdown = doc2.Select("img"); int i = 0; //foreach (Element link in linkdown) foreach (string link in linkdown) { //if (link.Parent.ClassName().Equals("view2")) //{ string imagelink = link.Replace(";", "").Replace("\r", "").Replace("\n", "").Replace("\t", ""); // link.Attr("src"); if (i < 10) { directory = targetfolder + "\\" + savename + "00" + i + ".jpg"; } else if (i >= 10 && i < 100) { directory = targetfolder + "\\" + savename + "0" + i + ".jpg"; } else { directory = targetfolder + "\\" + savename + i + ".jpg"; } ItemDown temp = new ItemDown(i, directory, imagelink, 0, "waiting"); listDown.Add(temp); i++; //} } } return(listDown); }
public virtual List <ItemDown> GetImagesLinkFromUrl() { List <ItemDown> listImage = new List <ItemDown>(); //create a new folder string targetfolder = ""; string directory; string foldername = CreateFolderName(this.url); try { targetfolder = savepath + "\\" + foldername; System.IO.Directory.CreateDirectory(targetfolder); } catch (Exception ex) { targetfolder = savepath + "\\Test"; System.IO.Directory.CreateDirectory(targetfolder); } try { HttpWebRequest myWebRequest = (HttpWebRequest)HttpWebRequest.Create(url); myWebRequest.Method = "GET"; myWebRequest.UserAgent = "Foo"; myWebRequest.Accept = "text/html"; HttpWebResponse myWebResponse = (HttpWebResponse)myWebRequest.GetResponse(); StreamReader myWebSource = new StreamReader(myWebResponse.GetResponseStream()); string htmlstring = string.Empty; htmlstring = myWebSource.ReadToEnd(); myWebResponse.Close(); Document doc = NSoupClient.ParseBodyFragment(htmlstring); Elements Links = doc.Select("img"); int i = 0; //tach lay cai link image va down ve foreach (Element link in Links) { string imagelink = link.Attr("abs:src"); if (i < 10) { directory = targetfolder + "\\" + savename + "00" + i + ".jpg"; } else if (i >= 10 && i < 100) { directory = targetfolder + "\\" + savename + "0" + i + ".jpg"; } else { directory = targetfolder + "\\" + savename + i + ".jpg"; } ItemDown temp = new ItemDown(i, directory, imagelink, 0, "waiting"); listImage.Add(temp); i++; } return(listImage); } catch (Exception _ex) { StreamWriter sw = new StreamWriter(Directory.GetCurrentDirectory() + "log.txt", true); sw.WriteLine("Lỗi khi lấy link ảnh:"); sw.Write(_ex.ToString()); sw.Close(); return(null); } }
public override List <ItemDown> GetImagesLinkFromUrl() { List <ItemDown> listDown = new List <ItemDown>(); //create a new folder string targetfolder = ""; string directory; //lay ten truyen -> tao duong dan cho gon string mangaName = url.Substring(0, url.Length - 1); mangaName = mangaName.Substring(mangaName.LastIndexOf("/") + 1); StreamReader inStream; WebRequest webRequest; WebResponse webresponse; webRequest = WebRequest.Create(url); webresponse = webRequest.GetResponse(); inStream = new StreamReader(webresponse.GetResponseStream()); String htmlstring = inStream.ReadToEnd(); Document doc = NSoupClient.ParseBodyFragment(htmlstring); List <string> listTemp = new List <string>(); //Buoc 1: tu link ten truyen lay ra duong link cua tung chap Elements Links = doc.Select("a"); foreach (Element link in Links) { if ("chapter-name".Equals(link.Parent.ClassName())) { string imagelink = link.SiblingElements.Text + "###" + link.Attr("href"); listTemp.Add(imagelink); } } //Buoc 2: tu link moi chap truyen dua ra cac link anh cua tung chap truyen foreach (string item in listTemp) { //tạo vị trí lưu string linkChap = item.Substring(item.LastIndexOf("###") + 3); string countChap = item.Substring(0, item.IndexOf("###")).Replace(@"\", "").Replace(@"/", "").Replace(@":", "") .Replace(@"*", "").Replace(@"?", "").Replace("\"", "").Replace(@"<", "").Replace(@">", "").Replace(@"|", ""); string foldername = CreateFolderName(linkChap); targetfolder = savepath + "\\" + mangaName + "\\" + countChap;// +"_" + foldername; System.IO.Directory.CreateDirectory(targetfolder); //down System.Windows.Forms.WebBrowser wb = new System.Windows.Forms.WebBrowser(); //WebClient wc = new WebClient(); wb.Navigate(url); string htmlstring2 = wb.DocumentText; //WebRequest webRequest2 = WebRequest.Create(linkChap); //WebResponse webresponse2 = webRequest2.GetResponse(); //StreamReader inStream2 = new StreamReader(webresponse2.GetResponseStream()); //String htmlstring2 = inStream2.ReadToEnd(); Document doc2 = NSoupClient.ParseBodyFragment(htmlstring2); Elements linkdown = doc2.Select("img"); int i = 0; foreach (Element link in linkdown) //foreach (string link in linkdown) { if (link.Parent.ClassName().Equals("viewer")) { //string imagelink = link.Replace(";", "").Replace(";", "").Replace("\r", "").Replace("\n", "").Replace("\t", ""); // link.Attr("src"); string imagelink = link.Attr("src"); if (i < 10) { directory = targetfolder + "\\" + savename + "00" + i + ".jpg"; } else if (i >= 10 && i < 100) { directory = targetfolder + "\\" + savename + "0" + i + ".jpg"; } else { directory = targetfolder + "\\" + savename + i + ".jpg"; } ItemDown temp = new ItemDown(i, directory, imagelink, 0, "waiting"); listDown.Add(temp); i++; } } } return(listDown); }
public override List <ItemDown> GetImagesLinkFromUrl() { List <ItemDown> listDown = new List <ItemDown>(); //create a new folder string targetfolder = ""; string directory; //tạo vị trí lưu string foldername = CreateFolderName(url); foldername = foldername.Replace("\\", "").Replace("/", "").Replace(":", "").Replace("*", "").Replace("?", ""). Replace("\"", "").Replace("~", "").Replace("<", "").Replace(">", "").Replace("|", "").Replace(".", "").Replace("+", ""); targetfolder = savepath + "\\" + foldername; System.IO.Directory.CreateDirectory(targetfolder); StreamReader inStream; WebRequest webRequest; WebResponse webresponse; webRequest = WebRequest.Create(url); webresponse = webRequest.GetResponse(); inStream = new StreamReader(webresponse.GetResponseStream()); String htmlstring = inStream.ReadToEnd(); Document doc = NSoupClient.ParseBodyFragment(htmlstring); List <string> listTemp = new List <string>(); Elements Links = doc.Select("a"); //string lastListLink = ""; foreach (Element link in Links) { if ("gallerybody".Equals(link.Parent.Parent.Parent.Parent.Parent.Parent.ClassName())) { string imageLink = "http://litugirls.urlgalleries.net" + link.Attr("href"); listTemp.Add(imageLink); } } foreach (string item in listTemp) { //down WebRequest webRequest2 = WebRequest.Create(item); WebResponse webresponse2 = webRequest2.GetResponse(); StreamReader inStream2 = new StreamReader(webresponse2.GetResponseStream()); String htmlstring2 = inStream2.ReadToEnd(); Document doc2 = NSoupClient.ParseBodyFragment(htmlstring2); Elements linkdown = doc2.Select("iframe"); int i = 0; //lay ra link trang chua anh, tu link nay moilay ra duoc anh, rat vai foreach (Element link in linkdown) { if (link.Id.Equals("thepic")) { i++; string imagelink = "http://img227.imagevenue.com/" + link.Attr("src"); //imagelink = imagelink.Replace("/thumbs/thumbs_", "/"); int int1 = imagelink.LastIndexOf("/") + 1; int int2 = imagelink.LastIndexOf("."); directory = targetfolder + @"\" + imagelink.Substring(int1, int2 - int1) + ".jpg"; ItemDown temp = new ItemDown(i, directory, imagelink, 0, "waiting"); listDown.Add(temp); } } } return(listDown); }
public override List <ItemDown> GetImagesLinkFromUrl() { List <ItemDown> listDown = new List <ItemDown>(); //create a new folder string targetfolder = ""; string directory; //tạo vị trí lưu string foldername = CreateFolderName(url); targetfolder = savepath + "\\" + foldername;; System.IO.Directory.CreateDirectory(targetfolder); //lay cac duong link gallery WebRequest webRequest = WebRequest.Create(url); WebResponse webresponse = webRequest.GetResponse(); StreamReader inStream = new StreamReader(webresponse.GetResponseStream()); String htmlstring = inStream.ReadToEnd(); Document doc = NSoupClient.ParseBodyFragment(htmlstring); List <string> listTemp = new List <string>(); Elements Links = doc.Select("a"); //loc ra duong link cuoi cung string lastListLink = ""; foreach (Element link in Links) { if ("page-numbers".Equals(link.ClassName())) { lastListLink = "http://www.bcfakes.com" + link.Attr("href"); //listTemp.Add(lastListLink); } } string temptest = ""; if (!lastListLink.Equals("")) { temptest = lastListLink.Substring(lastListLink.IndexOf("?nggpage=") + 9); int lastListIndex = Int32.Parse(temptest); for (int i = 1; i <= lastListIndex; i++) { string temp = lastListLink.Substring(0, lastListLink.IndexOf("?nggpage=") + 9) + i; listTemp.Add(temp); } } else { listTemp.Add(url); } int count = 0; foreach (string item in listTemp) { //down WebRequest webRequest2 = WebRequest.Create(item); WebResponse webresponse2 = webRequest2.GetResponse(); StreamReader inStream2 = new StreamReader(webresponse2.GetResponseStream()); String htmlstring2 = inStream2.ReadToEnd(); Document doc2 = NSoupClient.ParseBodyFragment(htmlstring2); Elements linkdown = doc2.Select("img"); //lay ra link trang chua anh, tu link nay moilay ra duoc anh, rat vai foreach (Element link in linkdown) { if ((link.Parent.Parent.Parent.Parent.ClassName().Equals("ngg-galleryoverview") && link.Parent.Parent.Parent.Parent.Id.Equals("ngg-gallery-43-267")) || link.Parent.Parent.ClassName().Equals("ngg-gallery-thumbnail")) { //string imagelink = link.Attr("src"); //imagelink = imagelink.Replace("/thumbs/thumbs_", "/"); string imagelink = link.Parent.Attr("href"); imagelink = "http://www.bcfakes.com" + imagelink; WebRequest webRequest3 = WebRequest.Create(imagelink); WebResponse webresponse3 = webRequest3.GetResponse(); StreamReader inStream3 = new StreamReader(webresponse3.GetResponseStream()); String htmlstring3 = inStream3.ReadToEnd(); Document doc3 = NSoupClient.ParseBodyFragment(htmlstring3); Elements linkdownFinals = doc3.Select("a"); int countItem = 0; foreach (Element linkdownFinal in linkdownFinals) { if (linkdownFinal.Parent.ClassName().Equals("pic")) { countItem++; string imagedownloadlink = linkdownFinal.Attr("href"); int int1 = imagedownloadlink.LastIndexOf("/") + 1; int int2 = imagedownloadlink.LastIndexOf("."); directory = targetfolder + @"\" + imagedownloadlink.Substring(int1, int2 - int1) + ".jpg"; ItemDown temp = new ItemDown(countItem, directory, imagedownloadlink, 0, "waiting"); listDown.Add(temp); count++; } } } } count++; } return(listDown); }