コード例 #1
0
        override public void download()
        {
            try
            {
                if (!Directory.Exists(this.SaveTo))
                {
                    Directory.CreateDirectory(this.SaveTo);
                }

                if (General.loadHTML)
                {
                    downloadHTMLPage();
                }

                string[] URLs = getLinks();

                for (int y = 0; y < URLs.Length; y++)
                {
                    General.dlTo(URLs[y], this.SaveTo);
                }
            }
            catch (WebException webEx)
            {
                if (((int)webEx.Status) == 7)
                {
                    this.Gone = true;
                }
            }
            catch (UnauthorizedAccessException ex)
            {
                MessageBox.Show(ex.Message, "No Permission to access folder");
                throw ex;
            }
        }
コード例 #2
0
        override public void download()
        {
            string[] URLs;
            string[] thumbs;
            string   strThumbs = "";
            string   website   = "";
            string   str;

            if (General.loadHTML)                                                       // if HTML download activated get HTML, thumbnails, do some magic
            {
                try {
                    website = new WebClient().DownloadString(this.getURL());

                    string JURL = this.getURL().Replace(".html", ".json");

                    string Content = new WebClient().DownloadString(JURL);

                    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();
                    }

                    // get single images
                    XmlDocument doc = new XmlDocument();
                    doc.LoadXml(str);
                    XmlNodeList xmlTim = doc.DocumentElement.SelectNodes("/root/posts/item/tim");
                    XmlNodeList xmlExt = doc.DocumentElement.SelectNodes("/root/posts/item/ext");
                    for (int i = 0; i < xmlExt.Count; i++)
                    {
                        string ext = xmlExt[i].InnerText;
//                        if(ext == ".webm")
//                            ext = ".jpg";
                        strThumbs = strThumbs + "https://8ch.net/" + getURL().Split('/')[3] + "/thumb/" + xmlTim[i].InnerText + ext + "\n";

                        website = website.Replace("https://8ch.net/" + getURL().Split('/')[3] + "/thumb/" + xmlTim[i].InnerText + ext, "thumb/" + xmlTim[i].InnerText + ext);
                        website = website.Replace("=\"/" + getURL().Split('/')[3] + "/thumb/" + xmlTim[i].InnerText + ext, "=\"thumb/" + xmlTim[i].InnerText + ext);
                        website = website.Replace("=\"/" + getURL().Split('/')[3] + "/src/" + xmlTim[i].InnerText + ext, "=\"" + xmlTim[i].InnerText + ext);
                        website = website.Replace("https://8ch.net/" + getURL().Split('/')[3] + "/thumb/" + xmlTim[i].InnerText + ext, "thumb/" + xmlTim[i].InnerText + ext);
                        website = website.Replace("https://media.8ch.net/" + getURL().Split('/')[3] + "/thumb/" + xmlTim[i].InnerText + ext, "thumb/" + xmlTim[i].InnerText + ext);
                        website = website.Replace("https://media.8ch.net/" + getURL().Split('/')[3] + "/src/" + xmlTim[i].InnerText + ext, xmlTim[i].InnerText + ext);
                        website = website.Replace("https://8ch.net/" + getURL().Split('/')[3] + "/src/" + xmlTim[i].InnerText + ext, xmlTim[i].InnerText + ext);
                    }

                    // get images of posts with multiple images
                    xmlTim = doc.DocumentElement.SelectNodes("/root/posts/item/extra_files/item/tim");
                    xmlExt = doc.DocumentElement.SelectNodes("/root/posts/item/extra_files/item/ext");
                    for (int i = 0; i < xmlExt.Count; i++)
                    {
                        string ext = xmlExt[i].InnerText;
//                        if(ext == ".webm")
//                            ext = ".jpg";
                        strThumbs = strThumbs + "https://8ch.net/" + getURL().Split('/')[3] + "/thumb/" + xmlTim[i].InnerText + ext + "\n";

                        website = website.Replace("https://8ch.net/" + getURL().Split('/')[3] + "/thumb/" + xmlTim[i].InnerText + ext, "thumb/" + xmlTim[i].InnerText + ext);
                        website = website.Replace("=\"/" + getURL().Split('/')[3] + "/thumb/" + xmlTim[i].InnerText + ext, "=\"thumb/" + xmlTim[i].InnerText + ext);
                        website = website.Replace("=\"/" + getURL().Split('/')[3] + "/src/" + xmlTim[i].InnerText + ext, "=\"" + xmlTim[i].InnerText + ext);

                        website = website.Replace("https://8ch.net/" + getURL().Split('/')[3] + "/thumb/" + xmlTim[i].InnerText + ext, "thumb/" + xmlTim[i].InnerText + ext);
                        website = website.Replace("https://media.8ch.net/" + getURL().Split('/')[3] + "/thumb/" + xmlTim[i].InnerText + ext, "thumb/" + xmlTim[i].InnerText + ext);
                        website = website.Replace("https://media.8ch.net/" + getURL().Split('/')[3] + "/src/" + xmlTim[i].InnerText + ext, xmlTim[i].InnerText + ext);
                        website = website.Replace("https://8ch.net/" + getURL().Split('/')[3] + "/src/" + xmlTim[i].InnerText + ext, xmlTim[i].InnerText + ext);
                    }

                    website = website.Replace("=\"/", "=\"https://8ch.net/");


                    if (!Directory.Exists(this.SaveTo))
                    {
                        Directory.CreateDirectory(this.SaveTo);
                    }

                    thumbs = strThumbs.Split('\n');

                    for (int i = 0; i < thumbs.Length - 1; i++)
                    {
                        General.dlTo(thumbs[i], this.SaveTo + "\\thumb");
                    }
                } catch (WebException webEx) {
                    // I think I should handle this
                }
                if (website != "")
                {
                    if (!Directory.Exists(this.SaveTo))
                    {
                        Directory.CreateDirectory(this.SaveTo);
                    }
                    File.WriteAllText(this.SaveTo + "\\Thread.html", website); // save thread
                }
            }

            try {
                URLs = Regex.Split(getLinks(), "\n");
            } catch (WebException webEx) {
                if (((int)webEx.Status) == 7)
                {
                    this.Gone = true;
                }
                return;
            }

            for (int y = 0; y < URLs.Length - 1; y++)
            {
                General.dlTo(URLs[y], this.SaveTo);                         // download images
            }
        }
コード例 #3
0
ファイル: Fchan.cs プロジェクト: kyuk0/YChan
        override public void download()
        {
            string[] URLs;
            string[] thumbs;
            string   strThumbs = "";
            string   baseURL   = "//i.4cdn.org/" + getURL().Split('/')[3] + "/";
            string   website   = "";

            if (General.loadHTML)
            {
                try {
                    website = new WebClient().DownloadString(this.getURL());

                    string JURL = "http://a.4cdn.org/" + getURL().Split('/')[3] + "/thread/" + getURL().Split('/')[5] + ".json";
                    string Res  = "";
                    string str  = "";

                    string json  = new WebClient().DownloadString(JURL);
                    byte[] bytes = Encoding.ASCII.GetBytes(json);
                    using (var stream = new MemoryStream(bytes)) {
                        var quotas     = new XmlDictionaryReaderQuotas();
                        var jsonReader = JsonReaderWriterFactory.CreateJsonReader(stream, quotas);
                        var xml        = XDocument.Load(jsonReader);
                        str = xml.ToString();
                    }

                    XmlDocument doc = new XmlDocument();
                    doc.LoadXml(str);
                    XmlNodeList xmlTim = doc.DocumentElement.SelectNodes("/root/posts/item/tim");
                    XmlNodeList xmlExt = doc.DocumentElement.SelectNodes("/root/posts/item/ext");

                    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);

/*http://i.4cdn.org/a/1431901271793s.jpg
 *                      Regex nmb = new Regex("//[0-9].t.4cdn.org/"+getURL().Split('/')[3] + "/" + xmlTim[i].InnerText +"s.jpg");
 *                      old = "//t.4cdn.org/" + getURL().Split('/')[3] + "/" + xmlTim[i].InnerText +"s.jpg";
 *                      rep = "thumb/" + xmlTim[i].InnerText +"s.jpg";
 * /*                        Regex nmb = new Regex("http://i.4cdn.org/"+getURL().Split('/')[3] + "/" + xmlTim[i].InnerText +"s.jpg");
 *                      old = "http://i.4cdn.org/" + getURL().Split('/')[3] + "/" + xmlTim[i].InnerText +"s.jpg";
 *                      rep = "thumb/" + xmlTim[i].InnerText +"s.jpg";
 *                      strThumbs = strThumbs + old +"\n";
 *
 *                      website = nmb.Replace(website, rep);*/
//                        MessageBox.Show("Replace http://i.4cdn.org/" + getURL().Split('/')[3] + "/" + xmlTim[i].InnerText +"s.jpg with thumb/" + xmlTim[i].InnerText +"s.jpg");
                        old       = "//t.4cdn.org/" + getURL().Split('/')[3] + "/" + xmlTim[i].InnerText + "s.jpg";
                        strThumbs = strThumbs + "http:" + 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);
                    }

                    thumbs = strThumbs.Split('\n');

                    for (int i = 0; i < thumbs.Length - 1; i++)
                    {
                        General.dlTo(thumbs[i], this.SaveTo + "\\thumb");
                    }
                } catch (WebException webEx) {
                    // should be handled
                }
                if (website != "")
                {
                    File.WriteAllText(this.SaveTo + "\\Thread.html", website);
                }
            }



            try {
                URLs = Regex.Split(getLinks(), "\n");
            } catch (WebException webEx) {
                if (((int)webEx.Status) == 7)
                {
                    this.Gone = true;
                }
                return;
            }

            for (int y = 0; y < URLs.Length - 1; y++)
            {
                General.dlTo(URLs[y], this.SaveTo);
            }
        }
コード例 #4
0
        private void downloadHTMLPage()
        {
            List <string> thumbs   = new List <string>();
            string        htmlPage = "";
            string        str;

            try
            {
                htmlPage = new WebClient().DownloadString(this.getURL());

                string JURL = this.getURL().Replace(".html", ".json");

                string Content = new WebClient().DownloadString(JURL);

                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();
                }

                // get single images
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(str);
                XmlNodeList xmlTim = doc.DocumentElement.SelectNodes("/root/posts/item/tim");
                XmlNodeList xmlExt = doc.DocumentElement.SelectNodes("/root/posts/item/ext");
                for (int i = 0; i < xmlExt.Count; i++)
                {
                    string ext = xmlExt[i].InnerText;
                    //                        if(ext == ".webm")
                    //                            ext = ".jpg";
                    thumbs.Add("https://8ch.net/file_store/thumb/" + xmlTim[i].InnerText + ext);

                    htmlPage = htmlPage.Replace("https://8ch.net/file_store/thumb/" + xmlTim[i].InnerText + ext, "thumb/" + xmlTim[i].InnerText + ext);
                    htmlPage = htmlPage.Replace("=\"/file_store/thumb/" + xmlTim[i].InnerText + ext, "=\"thumb/" + xmlTim[i].InnerText + ext);
                    htmlPage = htmlPage.Replace("=\"/file_store/" + xmlTim[i].InnerText + ext, "=\"" + xmlTim[i].InnerText + ext);
                    htmlPage = htmlPage.Replace("https://media.8ch.net/file_store/thumb/" + xmlTim[i].InnerText + ext, "thumb/" + xmlTim[i].InnerText + ext);
                    htmlPage = htmlPage.Replace("https://media.8ch.net/file_store/" + xmlTim[i].InnerText + ext, xmlTim[i].InnerText + ext);
                    htmlPage = htmlPage.Replace("https://8ch.net/file_store/" + xmlTim[i].InnerText + ext, xmlTim[i].InnerText + ext);
                }

                // get images of posts with multiple images
                xmlTim = doc.DocumentElement.SelectNodes("/root/posts/item/extra_files/item/tim");
                xmlExt = doc.DocumentElement.SelectNodes("/root/posts/item/extra_files/item/ext");
                for (int i = 0; i < xmlExt.Count; i++)
                {
                    string ext = xmlExt[i].InnerText;
                    //                        if(ext == ".webm")
                    //                            ext = ".jpg";
                    thumbs.Add("https://8ch.net/file_store/thumb/" + xmlTim[i].InnerText + ext);

                    htmlPage = htmlPage.Replace("https://8ch.net/file_store/thumb/" + xmlTim[i].InnerText + ext, "thumb/" + xmlTim[i].InnerText + ext);
                    htmlPage = htmlPage.Replace("=\"/file_store/thumb/" + xmlTim[i].InnerText + ext, "=\"thumb/" + xmlTim[i].InnerText + ext);
                    htmlPage = htmlPage.Replace("=\"/file_store/" + xmlTim[i].InnerText + ext, "=\"" + xmlTim[i].InnerText + ext);
                    htmlPage = htmlPage.Replace("https://media.8ch.net/file_store/thumb/" + xmlTim[i].InnerText + ext, "thumb/" + xmlTim[i].InnerText + ext);
                    htmlPage = htmlPage.Replace("https://media.8ch.net/file_store/" + xmlTim[i].InnerText + ext, xmlTim[i].InnerText + ext);
                    htmlPage = htmlPage.Replace("https://8ch.net/file_store/" + xmlTim[i].InnerText + ext, xmlTim[i].InnerText + ext);
                }

                htmlPage = htmlPage.Replace("=\"/", "=\"https://8ch.net/");

                for (int i = 0; i < thumbs.Count; i++)
                {
                    General.dlTo(thumbs[i], this.SaveTo + "\\thumb");
                }

                if (!String.IsNullOrWhiteSpace(htmlPage))
                {
                    File.WriteAllText(this.SaveTo + "\\Thread.html", htmlPage); // save thread
                }
            }
            catch (WebException webEx)
            {
                throw webEx;
            }
            catch (UnauthorizedAccessException ex)
            {
                throw ex;
            }
        }
コード例 #5
0
        private void downloadHTMLPage()
        {
            List <string> thumbs   = new List <string>();
            string        htmlPage = "";
            string        str      = "";
            string        baseURL  = "//i.4cdn.org/" + getURL().Split('/')[3] + "/";
            string        JURL     = "http://a.4cdn.org/" + getURL().Split('/')[3] + "/thread/" + getURL().Split('/')[5] + ".json";

            try
            {
                //Add a UserAgent to prevent 403
                WebClient web = new WebClient();
                web.Headers["User-Agent"] = "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0";

                htmlPage = web.DownloadString(this.getURL());

                //Prevent the html from being destroyed by the anti adblock script
                htmlPage = htmlPage.Replace("f=\"to\"", "f=\"penis\"");

                string json  = web.DownloadString(JURL);
                byte[] bytes = Encoding.ASCII.GetBytes(json);
                using (var stream = new MemoryStream(bytes))
                {
                    var quotas     = new XmlDictionaryReaderQuotas();
                    var jsonReader = JsonReaderWriterFactory.CreateJsonReader(stream, quotas);
                    var xml        = XDocument.Load(jsonReader);
                    str = xml.ToString();
                }

                XmlDocument doc = new XmlDocument();
                doc.LoadXml(str);
                XmlNodeList xmlTim = doc.DocumentElement.SelectNodes("/root/posts/item/tim");
                XmlNodeList xmlExt = doc.DocumentElement.SelectNodes("/root/posts/item/ext");

                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;
                    htmlPage = htmlPage.Replace(old, rep);

                    //Save thumbs for files that need it
                    if (rep.Split('.')[1] == "webm" /*|| rep.Split('.')[1] == ""*/)
                    {
                        old = "//t.4cdn.org/" + getURL().Split('/')[3] + "/" + xmlTim[i].InnerText + "s.jpg";
                        thumbs.Add("http:" + old);

                        htmlPage = htmlPage.Replace("//i.4cdn.org/" + getURL().Split('/')[3] + "/" + xmlTim[i].InnerText, "thumb/" + xmlTim[i].InnerText);
                    }
                    else
                    {
                        string thumbName = rep.Split('.')[0] + "s";
                        htmlPage = htmlPage.Replace(thumbName + ".jpg", rep.Split('.')[0] + "." + rep.Split('.')[1]);
                        htmlPage = htmlPage.Replace("/" + thumbName, thumbName);

                        htmlPage = htmlPage.Replace("//i.4cdn.org/" + getURL().Split('/')[3] + "/" + xmlTim[i].InnerText, xmlTim[i].InnerText);
                    }

                    htmlPage = htmlPage.Replace("/" + rep, rep);
                }

                htmlPage = htmlPage.Replace("=\"//", "=\"http://");

                //Save thumbs for files that need it
                for (int i = 0; i < thumbs.Count; i++)
                {
                    General.dlTo(thumbs[i], this.SaveTo + "\\thumb");
                }

                if (!string.IsNullOrWhiteSpace(htmlPage))
                {
                    File.WriteAllText(this.SaveTo + "\\Thread.html", htmlPage);
                }
            }
            catch (WebException webEx)
            {
                throw webEx;
            }
            catch (UnauthorizedAccessException ex)
            {
                throw ex;
            }
        }