public override void download() { string[] images; // Array that contains direct URLs to the image files string[] thumbnails; // Array that contains direct URLs to the thumbnails //var lwebsite = new List<string>(); // List that contains all the lines that start with "File: <a href=\"" for parsing var limages = new List <string>(); // List that contains all the lines that have image URLs after parsing them string website; // The string that contains the source for HTML saving. try { if (!isModified(this.getURL())) { return; } website = Controller.getHTML(this.getURL()); // Download the HTML source website = Controller.getHTML(this.getURL()); // Look for the file links using Regex Regex href = new Regex("(?<=File: <a href=\").*?(?=\" target=\"_blank\">)"); foreach (Match imageLinks in href.Matches(website)) { limages.Add(imageLinks.ToString()); } // Convert the images to an array & clear the useless lists (save RAM) images = limages.ToArray(); limages.Clear(); // Create the directory to save files in. if (!Directory.Exists(this.SaveTo)) { Directory.CreateDirectory(this.SaveTo); } // Downloads images from the lists for (int y = 0; y < images.Length; y++) { string file = images[y].Split('/')[6]; string url = images[y]; string[] badchars = new string[] { "\\", "/", ":", "*", "?", "\"", "<", ">", "|" }; string newfilename = file; limages.Add(images[y].Replace("_u18chan.", "s_u18chan.")); // Renames the _u18chan to s_u18chan for thumbnail URLs if (YCSettings.Default.originalName) { // Replace any invalid file names. newfilename = newfilename.Replace("_u18chan", ""); // This removes the _u18chan name in any files, as they use the original name. for (int z = 0; z < badchars.Length - 1; z++) { newfilename = newfilename.Replace(badchars[z], "-"); } Controller.downloadFile(images[y], this.SaveTo, true, newfilename); website = website.Replace(url, newfilename); } else { // u-18chan saves files as the original file name, just appends _u18chan to the end of the file names for (int z = 0; z < badchars.Length; z++) { newfilename = newfilename.Replace(badchars[z], "-"); } Controller.downloadFile(images[y], this.SaveTo, true, newfilename); website = website.Replace(url, this.SaveTo + "\\" + file); } } // Convert thumbnails to an array & clear the list thumbnails = limages.ToArray(); limages.Clear(); // Downloads thumbnails if (YCSettings.Default.downloadThumbnails) { if (!Directory.Exists(this.SaveTo + "\\thumb")) { Directory.CreateDirectory(this.SaveTo + "\\thumb"); } for (int y = 0; y < thumbnails.Length; y++) { string file = thumbnails[y].Split('/')[6]; string url = thumbnails[y]; Controller.downloadFile(thumbnails[y], this.SaveTo + "\\thumb"); website = website.Replace("src=\"//u18chan.com/uploads/user/lazyLoadPlaceholder_u18chan.gif\" data-original=\"" + url, "src=\"thumb\\" + file + "\" data-original=\"" + url); } } // Download HTML if (YCSettings.Default.htmlDownload == true && website != "") { Controller.saveHTML(false, website, this.SaveTo); } } catch (ThreadAbortException) { return; } catch (WebException webEx) { Debug.Print(webEx.ToString()); if (((int)webEx.Status) == 7) { this.Gone = true; } else { ErrorLog.reportWebError(webEx); } return; } catch (Exception ex) { ErrorLog.reportError(ex.ToString()); } GC.Collect(); }
public override void download() { string[] images; // image urls array string[] thumbnails; // thumbnail url array string[] original; // original file name array var lImages = new List <string>(); // List to add image links to var lThumbnails = new List <string>(); // List to add thumbnail links to var lOriginal = new List <string>(); // List to add the original name to. string website; try { if (!isModified(this.getURL())) { return; } website = Controller.getHTML(this.getURL(), true, reqCookie); string[] lines = website.Split('\n'); string foundURL; string thumbURL; string originalName; string baseURL = "http://fchan.us"; Regex href = new Regex("(?<=<a target=\"_blank\" href=\").*?(?=\" rel=\"nofollow\">)"); Regex fileName = new Regex(""); foreach (Match imageLinks in href.Matches(website)) { foundURL = imageLinks.ToString(); if (!lImages.Contains(baseURL + foundURL)) // Image { lImages.Add(baseURL + foundURL); } fileName = new Regex("(?<=File: <a target=\"_blank\" href=\"" + foundURL + "\" rel=\"nofollow\">).*?(?=</a>)"); foreach (Match origFileName in fileName.Matches(website)) { originalName = origFileName.ToString(); if (YCSettings.Default.originalName) { if (!lOriginal.Contains(originalName)) { lOriginal.Add(originalName); // Original file name } website = website.Replace(foundURL, originalName); } else { website = website.Replace(foundURL, foundURL.Split('/')[2]); } if (YCSettings.Default.downloadThumbnails) { thumbURL = foundURL.Replace("/src/", "/" + this.getURL().Split('/')[3] + "/thumb/").Replace("_" + originalName, "s_" + originalName).Replace(".png", ".jpg").Replace(".gif", ".jpg"); if (!lThumbnails.Contains(baseURL + thumbURL)) { lThumbnails.Add(baseURL + thumbURL); } website = website.Replace(thumbURL, "thumb/" + thumbURL.Split('/')[3]); } } } images = lImages.ToArray(); original = lOriginal.ToArray(); lImages.Clear(); lOriginal.Clear(); if (!Directory.Exists(this.SaveTo)) { Directory.CreateDirectory(this.SaveTo); } for (int y = 0; y < images.Length; y++) { string file = images[y].Split('/')[4]; string url = images[y]; string[] badchars = new string[] { "\\", "/", ":", "*", "?", "\"", "<", ">", "|" }; string newfilename = file; if (YCSettings.Default.originalName) { newfilename = original[y]; for (int z = 0; z < badchars.Length - 1; z++) { newfilename = newfilename.Replace(badchars[z], "-"); } Controller.downloadFile(images[y], this.SaveTo, true, newfilename, true, reqCookie); website = website.Replace(url, newfilename); } else { for (int z = 0; z < badchars.Length; z++) { newfilename = newfilename.Replace(badchars[z], "-"); } Controller.downloadFile(images[y], this.SaveTo, true, newfilename, true, reqCookie); website = website.Replace(url, newfilename); } } thumbnails = lThumbnails.ToArray(); lThumbnails.Clear(); if (YCSettings.Default.downloadThumbnails) { if (!Directory.Exists(this.SaveTo + "\\thumb")) { Directory.CreateDirectory(this.SaveTo + "\\thumb"); } for (int y = 0; y < thumbnails.Length; y++) { string file = thumbnails[y].Split('/')[3]; string url = thumbnails[y]; Controller.downloadFile(thumbnails[y], this.SaveTo + "\\thumb", false, string.Empty, true, reqCookie); website = website.Replace(url, "thumb\\" + file); } } if (YCSettings.Default.htmlDownload == true && website != "") { Controller.saveHTML(false, website.Replace("type=\"text/javascript\" src=\"", "type=\"text/javascript\" src=\"http://fchan.us").Replace("type=\"text/css\" href=\"", "type=\"text/css\" href=\"http://fchan.us"), this.SaveTo); } } catch (ThreadAbortException) { return; } catch (WebException webEx) { Debug.Print(webEx.ToString()); if (((int)webEx.Status) == 7) { this.Gone = true; } else { ErrorLog.reportWebError(webEx); } return; } catch (Exception ex) { Debug.Print(ex.ToString()); ErrorLog.reportError(ex.ToString()); } }
public override void download() { string[] images; string[] thumbnails; // .Split('.")[2] = Extension string[] original; var lwebsite = new List <string>(); var lImages = new List <string>(); var lThumbnails = new List <string>(); var lOriginal = new List <string>(); string website; try { if (!isModified(this.getURL())) { return; } website = Controller.getHTML(this.getURL()); string[] lines = website.Split('\n'); string extension; Regex href = new Regex(regImage); foreach (Match imageLinks in href.Matches(website)) { lImages.Add(imageLinks.ToString()); if (YCSettings.Default.downloadThumbnails) { extension = imageLinks.ToString().Split('.')[2]; lThumbnails.Add(imageLinks.ToString().Replace("." + extension, "s." + extension).Replace("/src/", "/thumb/")); } //if (YCSettings.Default.originalName) // lOriginal.Add(lines[Array.FindIndex(lines, x => x.Contains(imageLinks.ToString())) + 8].Replace(", ", "")); } images = lImages.ToArray(); original = lOriginal.ToArray(); lImages.Clear(); lOriginal.Clear(); lwebsite.Clear(); if (!Directory.Exists(this.SaveTo)) { Directory.CreateDirectory(this.SaveTo); } for (int y = 0; y < images.Length; y++) { string file = images[y].Split('/')[5]; string url = images[y]; string[] badchars = new string[] { "\\", "/", ":", "*", "?", "\"", "<", ">", "|" }; string newfilename = file; //if (YCSettings.Default.originalName) { // newfilename = original[y]; // for (int z = 0; z < badchars.Length - 1; z++) // newfilename = newfilename.Replace(badchars[z], "-"); // Controller.downloadFile(images[y], this.SaveTo, true, newfilename); // website = website.Replace(url, newfilename); //} //else { for (int z = 0; z < badchars.Length; z++) { newfilename = newfilename.Replace(badchars[z], "-"); } Controller.downloadFile(images[y], this.SaveTo, true, newfilename); website = website.Replace(url, newfilename); //} } thumbnails = lThumbnails.ToArray(); lThumbnails.Clear(); if (YCSettings.Default.downloadThumbnails) { if (!Directory.Exists(this.SaveTo + "\\thumb")) { Directory.CreateDirectory(this.SaveTo + "\\thumb"); } for (int y = 0; y < thumbnails.Length; y++) { string file = thumbnails[y].Split('/')[5]; string url = thumbnails[y]; Controller.downloadFile(thumbnails[y], this.SaveTo + "\\thumb"); website = website.Replace(url, "thumb\\" + file); } } if (YCSettings.Default.htmlDownload == true && website != "") { Controller.saveHTML(false, website.Replace("\"//7chan.org", "\"https://7chan.org"), this.SaveTo); } } catch (ThreadAbortException) { return; } catch (WebException webEx) { Debug.Print(webEx.ToString()); if (((int)webEx.Status) == 7) { this.Gone = true; } else { ErrorLog.reportWebError(webEx); } return; } catch (Exception ex) { Debug.Print(ex.ToString()); ErrorLog.reportError(ex.ToString()); } }
public static void CheckForUpdate(bool ForceCheck = false) { if (Program.IsDebug) { // Debug.Print("-version " + GitData.UpdateVersion + " -name " + System.AppDomain.CurrentDomain.FriendlyName); return; } if (!General.Default.EnableUpdates && !ForceCheck) { return; } if (GitData.UpdateAvailable) { using (frmUpdateAvailable Update = new frmUpdateAvailable()) { Update.BlockSkip = ForceCheck; switch (Update.ShowDialog()) { case DialogResult.Yes: try { UpdateApplication(); } catch (Exception ex) { ErrorLog.ReportException(ex); return; } break; } } } else { Thread checkUpdates = new Thread(() => { if (GitData.UpdateVersion == "-1" || ForceCheck) { decimal GitVersion = GetGitVersion(0); if (IsUpdateAvailable(GitVersion)) { GitData.UpdateAvailable = true; if (GitVersion != Properties.Settings.Default.SkippedVersion || ForceCheck) { using (frmUpdateAvailable Update = new frmUpdateAvailable()) { Update.BlockSkip = ForceCheck; switch (Update.ShowDialog()) { case DialogResult.Yes: try { UpdateApplication(); } catch (Exception ex) { ErrorLog.ReportException(ex); return; } break; case DialogResult.Ignore: Properties.Settings.Default.SkippedVersion = GitVersion; Properties.Settings.Default.Save(); break; } } } } else if (ForceCheck) { MessageBox.Show("No updates available."); } } }); checkUpdates.Name = "Check for application update"; checkUpdates.Start(); } }
override protected string getLinks() { string exed = ""; string JSONUrl = "http://a.4cdn.org/" + getURL().Split('/')[3] + "/thread/" + getURL().Split('/')[5] + ".json"; string baseURL = "http://i.4cdn.org/" + getURL().Split('/')[3] + "/"; string str = ""; XmlNodeList xmlTim; XmlNodeList xmlExt; XmlNodeList xmlFilename; try { string Content; using (WebClient wc = new WebClient()){ wc.Headers.Add("User-Agent: " + Adv.Default.UserAgent); Content = wc.DownloadString(JSONUrl); } byte[] bytes = Encoding.ASCII.GetBytes(Content); using (var stream = new MemoryStream(bytes)) { var quotas = new XmlDictionaryReaderQuotas(); var jsonReader = JsonReaderWriterFactory.CreateJsonReader(stream, quotas); var xml = XDocument.Load(jsonReader); str = xml.ToString(); stream.Flush(); stream.Close(); } XmlDocument doc = new XmlDocument(); doc.LoadXml(str); if (getURL().Split('/')[3] == "f") { xmlTim = doc.DocumentElement.SelectNodes("/root/posts/item/filename"); } else { xmlTim = doc.DocumentElement.SelectNodes("/root/posts/item/tim"); } xmlFilename = doc.DocumentElement.SelectNodes("/root/posts/item/filename"); xmlExt = doc.DocumentElement.SelectNodes("/root/posts/item/ext"); for (int i = 0; i < xmlExt.Count; i++) { exed = exed + baseURL + xmlTim[i].InnerText + xmlExt[i].InnerText + "\n"; // MessageBox.Show(exed); } return(exed); } catch (WebException webEx) { if (((int)webEx.Status) == 7) { this.Gone = true; } else { ErrorLog.reportWebError(webEx); } throw webEx; } catch (Exception ex) { ErrorLog.reportError(ex.ToString()); throw ex; } }
override public void download() { string[] URLs; // Array of the image URLs string[] thumbs; // Array of the thumbnail URLs string strThumbs = ""; // ? string baseURL = "//i.4cdn.org/" + getURL().Split('/')[3] + "/"; // Base URL used for downloading the files string website; // String that contains the source of the thread string curl = "Not defined"; try { string JURL = "https://a.4cdn.org/" + getURL().Split('/')[3] + "/thread/" + getURL().Split('/')[5] + ".json"; curl = JURL; if (!isModified(JURL)) { return; } string str = Controller.getJSON(JURL); curl = this.getURL(); website = Controller.getHTML(this.getURL()); XmlDocument doc = new XmlDocument(); doc.LoadXml(str); XmlNodeList xmlTim = doc.DocumentElement.SelectNodes("/root/posts/item/tim"); XmlNodeList xmlFilename = doc.DocumentElement.SelectNodes("/root/posts/item/filename"); XmlNodeList xmlExt = doc.DocumentElement.SelectNodes("/root/posts/item/ext"); XmlNodeList xmlMd5 = doc.DocumentElement.SelectNodes("/root/posts/item/md5"); for (int i = 0; i < xmlExt.Count; i++) { string old = baseURL + xmlTim[i].InnerText + xmlExt[i].InnerText; string rep = xmlTim[i].InnerText + xmlExt[i].InnerText; website = website.Replace(old, rep); old = "//t.4cdn.org/" + getURL().Split('/')[3] + "/" + xmlTim[i].InnerText + "s.jpg"; strThumbs = strThumbs + "https:" + old + "\n"; website = website.Replace("//i.4cdn.org/" + getURL().Split('/')[3], "thumb"); } website = website.Replace("=\"//", "=\"http://"); if (!Directory.Exists(this.SaveTo)) { Directory.CreateDirectory(this.SaveTo); } URLs = Regex.Split(getLinks(), "\n"); string newfilename = string.Empty; for (int y = 0; y < URLs.Length - 1; y++) { if (YCSettings.Default.originalName) { curl = URLs[y]; string[] badchars = new string[] { "\\", "/", ":", "*", "?", "\"", "<", ">", "|" }; newfilename = xmlFilename[y].InnerText; for (int z = 0; z < badchars.Length - 1; z++) { newfilename = newfilename.Replace(badchars[z], "-"); } if (YCSettings.Default.preventDupes) { if (File.Exists(this.SaveTo + "\\" + newfilename + xmlExt[y].InnerText)) { if (!thisFileExists(this.SaveTo + "\\" + newfilename + xmlExt[y].InnerText, xmlMd5[y].InnerText)) { if (!thisFileExists(this.SaveTo + "\\" + newfilename + " (" + y + ")" + xmlExt[y].InnerText, xmlMd5[y].InnerText)) { newfilename += " (" + y + ")" + xmlExt[y].InnerText; Controller.downloadFile(URLs[y], this.SaveTo, true, newfilename); } } } else { newfilename += xmlExt[y].InnerText; Controller.downloadFile(URLs[y], this.SaveTo, true, newfilename); } } else { newfilename += xmlExt[y].InnerText; Controller.downloadFile(URLs[y], this.SaveTo, true, newfilename); } website = website.Replace(xmlTim[y].InnerText + xmlExt[y].InnerText, newfilename + xmlExt[y].InnerText); } else { Controller.downloadFile(URLs[y], this.SaveTo); } if (YCSettings.Default.downloadThumbnails) { thumbs = strThumbs.Split('\n'); for (int i = 0; i < thumbs.Length - 1; i++) { curl = thumbs[i]; Controller.downloadFile(thumbs[i], this.SaveTo + "\\thumb"); } } Regex siteScript = new Regex(regOSS); foreach (Match script in siteScript.Matches(website)) { website = website.Replace(script.ToString(), string.Empty); } if (YCSettings.Default.htmlDownload == true && website != "") { Controller.saveHTML(false, website.Replace("class=\"fileThumb\" href=\"thumb/", "class=\"fileThumb\" href=\""), this.SaveTo); } } } catch (ThreadAbortException) { return; } catch (WebException webEx) { Debug.Print(webEx.ToString()); if (((int)webEx.Status) == 7) { this.Gone = true; } else { ErrorLog.reportWebError(webEx, curl); } GC.Collect(); return; } catch (Exception ex) { ErrorLog.reportError(ex.ToString()); GC.Collect(); return; } GC.Collect(); }
public override void download() { string[] URLs; string[] thumbs; string strThumbs = ""; string baseURL = "https://boards.420chan.org/" + getURL().Split('/')[3] + "/src/"; string thumbURL = "https://boards.420chan.org/" + getURL().Split('/')[3] + "/thumb/"; string JURL = "https://api.420chan.org/" + getURL().Split('/')[3] + "/res/" + getURL().Split('/')[5].Replace(".php", ".json"); string website; try { if (!isModified(this.getURL())) { return; } string str = Controller.getJSON(JURL); website = Controller.getHTML(this.getURL()); if (string.IsNullOrWhiteSpace(str)) { MessageBox.Show("Thread " + getURL().Split('/')[5] + " may be invald, or your requests may be timing out."); return; } else if (str == "Not modified") { return; } this.checkedAt = DateTime.Now; XmlDocument doc = new XmlDocument(); doc.LoadXml(str); XmlNodeList xmlFilename = doc.DocumentElement.SelectNodes("/root/posts/item/filename"); XmlNodeList xmlExt = doc.DocumentElement.SelectNodes("/root/posts/item/ext"); website = website.Replace("href=\"/" + this.getURL().Split('/')[3] + "/src/", ""); website = website.Replace("href=\"/" + this.getURL().Split('/')[3], ""); website = website.Replace("href=\"/static/", "href=\"https://420chan.org/static/"); for (int i = 0; i < xmlExt.Count; i++) { if (xmlExt[i].InnerText == ".gif") { website.Replace("href=\"/thumb/" + xmlFilename[i].InnerText + xmlExt[i].InnerText, xmlFilename[i].InnerText + xmlExt[i].InnerText); } else { strThumbs = strThumbs + thumbURL + xmlFilename[i].InnerText + "s.jpg\n"; } } if (!Directory.Exists(this.SaveTo)) { Directory.CreateDirectory(this.SaveTo); } var list = new List <String>(); for (int j = 0; j < xmlFilename.Count; j++) { list.Add(baseURL + xmlFilename[j].InnerText + xmlExt[j].InnerText); } URLs = list.ToArray(); list.Clear(); for (int y = 0; y < URLs.Length; y++) { // 420chan doesnt support original file names. Controller.downloadFile(URLs[y], this.SaveTo); website = website.Replace(URLs[y], ""); } if (YCSettings.Default.downloadThumbnails) { thumbs = strThumbs.Split('\n'); for (int i = 0; i < thumbs.Length - 1; i++) { Controller.downloadFile(thumbs[i], this.SaveTo + "\\thumb"); } } if (YCSettings.Default.htmlDownload) { Controller.saveHTML(false, website, this.SaveTo); } } catch (ThreadAbortException) { return; } catch (WebException webEx) { Debug.Print(webEx.ToString()); if (((int)webEx.Status) == 7) { this.Gone = true; } else { ErrorLog.reportWebError(webEx); } GC.Collect(); return; } catch (Exception ex) { ErrorLog.reportError(ex.ToString()); } }