コード例 #1
0
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="img">图片</param>
        /// <param name="index">位置索引</param>
        /// <param name="isRed">是否已经浏览过</param>
        /// <param name="needReferer">是否需要伪造Referer</param>
        public ImgControl(Img img, int index, string referer, bool supportScore)
        {
            this.needReferer = referer;
            this.InitializeComponent();
            this.img = img;
            this.index = index;

            if (img.IsViewed)
                //statusBorder.Background = new SolidColorBrush(Color.FromArgb(0xCC, 0xFE, 0xE2, 0xE2));
                statusBorder.Background = new SolidColorBrush(Color.FromArgb(0xEE, 0xE9, 0x93, 0xAA));

            //try
            //{
                //string s = .Substring(img.Score.IndexOf(' '), img.Score.Length - img.Score.IndexOf(' '));
            //score.Text = img.Score.ToString();
            //}
            //catch { }

            if (!supportScore)
            {
                //brdScr.Visibility = System.Windows.Visibility.Hidden;
            }
            
            //chk.Text = img.Dimension;

            //RenderOptions.SetBitmapScalingMode(preview, BitmapScalingMode.Fant);
            preview.DataContext = img;

            preview.SizeChanged += new SizeChangedEventHandler(preview_SizeChanged);
            preview.ImageFailed += new EventHandler<ExceptionRoutedEventArgs>(preview_ImageFailed);
            preview.MouseUp += new MouseButtonEventHandler(preview_MouseUp);
            statusBorder.MouseUp += new MouseButtonEventHandler(preview_MouseUp);
            chk.MouseUp += new MouseButtonEventHandler(preview_MouseUp);
            txtDesc.MouseUp += new MouseButtonEventHandler(preview_MouseUp);

            downBtn.MouseUp += new MouseButtonEventHandler(Border_MouseUp);
            magBtn.MouseUp += new MouseButtonEventHandler(preview_Click);

            //chk.Click += chk_Checked;

            //ToolTip tip = preview.ToolTip as ToolTip;
            //tip.PlacementTarget = preview.Parent as UIElement;
            //TextBlock desc = (tip.Content as Border).Child as TextBlock;

            //下载缩略图
            //DownloadImg();

            if (img.DownloadDetail != null)
            {
                //need detail
                LayoutRoot.IsEnabled = false;
                //isRetrievingDetail = true;
                chk.Text = "信息尚未加载";
            }
            else
            {
                ShowImgDetail();
            }
        }
コード例 #2
0
ファイル: SiteEshuu.cs プロジェクト: istobran/moe-loader
        private Img GenerateImg(string file_url, string preview_url, string dimension, string created_at, string tags, string file_size, string id)
        {
            int intId = int.Parse(id.Substring(1));

            int width = 0, height = 0;
            try
            {
                //706x1000 (0.706 MPixel)
                dimension = dimension.Substring(0, dimension.IndexOf('(')).Trim();
                width = int.Parse(dimension.Substring(0, dimension.IndexOf('x')));
                height = int.Parse(dimension.Substring(dimension.IndexOf('x') + 1));
            }
            catch { }

            //convert relative url to absolute
            if (file_url.StartsWith("/"))
                file_url = SiteUrl + file_url;
            if (preview_url.StartsWith("/"))
                preview_url = SiteUrl + preview_url;

            Img img = new Img()
            {
                Date = created_at.Replace("\t", "").Replace("\n", ""),
                FileSize = file_size.Replace("\t", "").Replace("\n", "").ToUpper(),
                Desc = tags.Replace("\t", "").Replace("\n", ""),
                Id = intId,
                JpegUrl = file_url,
                OriginalUrl = file_url,
                PreviewUrl = preview_url,
                SampleUrl = file_url,
                Width = width,
                Height = height,
                Tags = tags.Replace("\t", "").Replace("\n", ""),
                DetailUrl = SiteUrl + "/image/" + intId,
            };
            return img;
        }
コード例 #3
0
        /// <summary>
        /// 生成 Img 对象
        /// </summary>
        /// <param name="file_url"></param>
        /// <param name="preview_url"></param>
        /// <param name="sample"></param>
        /// <param name="created_at"></param>
        /// <param name="tags"></param>
        /// <param name="file_size"></param>
        /// <param name="id"></param>
        /// <param name="score"></param>
        /// <param name="jpeg_url"></param>
        /// <returns></returns>
        private Img GenerateImg(string file_url, string preview_url, int width, int height, string sample
                                , string created_at, string tags, int file_size, string id, string score, string jpeg_url, string src, string url)
        {
            int scoreInt = 0, intId = 0;

            try
            {
                intId = int.Parse(id);
            }
            catch { }
            try
            {
                scoreInt = Int32.Parse(score.Substring(score.IndexOf(' '), score.Length - score.IndexOf(' ')));
            }
            catch { }

            #region DateTime Convert
            //eg. Fri Aug 28 20:05:57 -0600 2009 or 1291280246
            try
            {
                //1291280246   ==   2010/12/2 16:57
                long     sec       = long.Parse(created_at);
                DateTime startDate = new DateTime(1970, 1, 1, 8, 0, 0, 0);
                created_at = startDate.AddSeconds(sec).ToString();
            }
            catch
            {
                //Thu Dec 31 06:54:54 +0000 2009
                //2012/01/28 01:59:10 -0500
                //1323123123
                //Dec Nov Oct Sep Aug Jul Jun May Apr Mar Feb Jan
                try
                {
                    created_at = DateTime.Parse(created_at).ToString();
                }
                catch { }
            }
            #endregion

            string host      = url.Substring(0, url.IndexOf('/', 8));
            string detailUrl = host + "/post/show/" + id;
            if (url.Contains("index.php"))
            {
                detailUrl = host + "/index.php?page=post&s=view&id=" + id;
            }

            Img img = new Img()
            {
                Date        = created_at,
                Desc        = tags,
                FileSize    = file_size > 1048576 ? (file_size / 1048576.0).ToString("0.00MB") : (file_size / 1024.0).ToString("0.00KB"),
                Height      = height,
                Id          = intId,
                IsExplicit  = score.StartsWith("E"),
                JpegUrl     = jpeg_url,
                OriginalUrl = file_url,
                PreviewUrl  = preview_url,
                SampleUrl   = sample,
                Score       = scoreInt,
                Source      = src,
                Tags        = tags,
                Width       = width,
                DetailUrl   = detailUrl
            };
            return(img);
        }
コード例 #4
0
        /// <summary>
        /// JSON format
        /// </summary>
        /// <param name="url"></param>
        /// <param name="pageString"></param>
        /// <param name="imgs"></param>
        private void ProcessJSON(string url, string pageString, List <Img> imgs)
        {
            //JSONArray array = JSONConvert.DeserializeArray(pageString);
            object[] array = (new System.Web.Script.Serialization.JavaScriptSerializer()).DeserializeObject(pageString) as object[];
            foreach (object o in array)
            {
                //JSONObject obj = o as JSONObject;
                Dictionary <string, object> obj = o as Dictionary <string, object>;

                string sample = "";
                if (obj.ContainsKey("sample_url"))
                {
                    sample = obj["sample_url"].ToString();
                }

                int file_size = 0;
                try
                {
                    if (obj.ContainsKey("file_size"))
                    {
                        file_size = Int32.Parse(obj["file_size"].ToString());
                    }
                }
                catch { }

                string created_at = "N/A";
                //if (obj["created_at"))
                //    created_at = obj["created_at");

                string preview_url = obj["preview_url"].ToString();
                string file_url    = obj["file_url"].ToString();

                string jpeg_url = file_url;
                if (obj.ContainsKey("jpeg_url"))
                {
                    jpeg_url = obj["jpeg_url"].ToString();
                }

                string tags   = obj["tags"].ToString();
                string id     = obj["id"].ToString();
                string source = obj["source"].ToString();

                int width  = 0;
                int height = 0;
                try
                {
                    width  = int.Parse(obj["width"].ToString().Trim());
                    height = int.Parse(obj["height"].ToString().Trim());
                }
                catch { }

                string score = "N/A";
                if (obj.ContainsKey("rating"))
                {
                    score = "Safe ";
                    if (obj["rating"].ToString() == "e")
                    {
                        score = "Explicit ";
                    }
                    else
                    {
                        score = "Questionable ";
                    }
                    if (obj.ContainsKey("score"))
                    {
                        score += obj["score"].ToString();
                    }
                }

                string host = url.Substring(0, url.IndexOf('/', 8));

                if (preview_url.StartsWith("/"))
                {
                    preview_url = host + preview_url;
                }
                if (file_url.StartsWith("/"))
                {
                    file_url = host + file_url;
                }
                if (sample.StartsWith("/"))
                {
                    sample = host + sample;
                }
                if (jpeg_url.StartsWith("/"))
                {
                    jpeg_url = host + jpeg_url;
                }

                //if (!UseJpeg)
                //jpeg_url = file_url;

                Img img = GenerateImg(file_url, preview_url, width, height, sample, created_at, tags, file_size, id, score, jpeg_url, source, url);
                if (img != null)
                {
                    imgs.Add(img);
                }
            }
        }
コード例 #5
0
        /// <summary>
        /// XML 格式信息
        /// </summary>
        /// <param name="url"></param>
        /// <param name="pageString"></param>
        /// <param name="imgs"></param>
        private void ProcessXML(string url, string pageString, List <Img> imgs)
        {
            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.LoadXml(pageString);

            XmlElement root = null;

            if (xmlDoc.SelectSingleNode("posts") == null)
            {
                root = (XmlElement)(xmlDoc.SelectSingleNode("IbSearch/response")); //root
            }
            else
            {
                root = (XmlElement)(xmlDoc.SelectSingleNode("posts"));  //root
            }
            foreach (XmlNode postN in root.ChildNodes)
            {
                XmlElement post = (XmlElement)postN;

                int file_size = 0;
                try
                {
                    if (post.HasAttribute("file_size"))
                    {
                        file_size = Int32.Parse(post.GetAttribute("file_size"));
                    }
                }
                catch { }

                string created_at = "N/A";
                if (post.HasAttribute("created_at"))
                {
                    created_at = post.GetAttribute("created_at");
                }

                string preview_url = post.GetAttribute("preview_url");
                string file_url    = post.GetAttribute("file_url");

                string jpeg_url = file_url;
                if (post.HasAttribute("jpeg_url"))
                {
                    jpeg_url = post.GetAttribute("jpeg_url");
                }

                string sample = file_url;
                if (post.HasAttribute("sample_url"))
                {
                    sample = post.GetAttribute("sample_url");
                }

                string tags   = post.GetAttribute("tags");
                string id     = post.GetAttribute("id");
                string source = post.GetAttribute("source");
                //string width = post.GetAttribute("width");
                //string height = post.GetAttribute("height");
                int width  = 0;
                int height = 0;
                try
                {
                    width  = int.Parse(post.GetAttribute("width").Trim());
                    height = int.Parse(post.GetAttribute("height").Trim());
                }
                catch { }

                string score = "N/A";
                if (post.HasAttribute("rating"))
                {
                    score = "Safe ";
                    if (post.GetAttribute("rating") == "e")
                    {
                        score = "Explicit ";
                    }
                    else
                    {
                        score = "Questionable ";
                    }
                    if (post.HasAttribute("score"))
                    {
                        score += post.GetAttribute("score");
                    }
                }

                string host = url.Substring(0, url.IndexOf('/', 8));

                if (preview_url.StartsWith("/"))
                {
                    preview_url = host + preview_url;
                }
                if (file_url.StartsWith("/"))
                {
                    file_url = host + file_url;
                }
                if (sample.StartsWith("/"))
                {
                    sample = host + sample;
                }
                if (jpeg_url.StartsWith("/"))
                {
                    jpeg_url = host + jpeg_url;
                }

                //if (!UseJpeg)
                //jpeg_url = file_url;

                Img img = GenerateImg(file_url, preview_url, width, height, sample, created_at, tags, file_size, id, score, jpeg_url, source, url);
                if (img != null)
                {
                    imgs.Add(img);
                }
            }
        }
コード例 #6
0
        /// <summary>
        /// HTML 格式信息
        /// </summary>
        /// <param name="url"></param>
        /// <param name="pageString"></param>
        /// <param name="imgs"></param>
        private void ProcessHTML(string url, string pageString, List <Img> imgs)
        {
            /* Post.register({"jpeg_height":1200,"sample_width":1333,"md5":"1550bb8d9fa4e1ee7903ee103459f69a","created_at":{"n":666146000,"json_class":"Time","s":1290715184},
             * "status":"active","jpeg_file_size":215756,"sample_height":1000,"score":4,"sample_url":"http://yuinyan.imouto.org/sample/1550bb8d9fa4e459f69a/moe%20163698%20sample.jpg",
             * "actual_preview_height":225,"author":"paku-paku","has_children":false,"change":758975,"height":1200,"sample_file_size":142868,
             * "preview_url":"http://mio3.imouto.org/data/preview/15/50/1550bb8d9fa4e1ee7903ee103459f69a.jpg","tags":"akiyama_mio bikini k-on! swimsuits transparent_png vector_trace",
             * "source":"","width":1600,"rating":"s","jpeg_url":"http://yuinyan.imouto.org/jpeg/1550bb8d9fa4e1ee7903ee103459f69a/moe%20163698%20msuitst_png%20vector_trace.jpg",
             * "preview_width":150,"file_size":113055,"jpeg_width":1600,"preview_height":113,"is_shown_in_index":true,
             * "file_url":"http://yuinyan.imouto.org/image/1550bb8d9fa4e1ee7903ee103459f69a/moe%20163698%20amio%20swimsctor_trace.png",
             * "id":163698,"parent_id":null,"actual_preview_width":300,"creator_id":70875}) */

            //当前字符串位置
            int index = 0;

            while (index < pageString.Length)
            {
                index = pageString.IndexOf("Post.register({", index);
                if (index == -1)
                {
                    break;
                }
                string item = pageString.Substring(index + 14, pageString.IndexOf("})", index) - index - 13);

                #region Analyze json
                //替换有可能干扰分析的 [ ] "
                //item = item.Replace('[', '1').Replace(']', '1').Replace("\\\"", "");
                //JSONObject obj = JSONConvert.DeserializeObject(item);
                Dictionary <string, object> obj = (new System.Web.Script.Serialization.JavaScriptSerializer()).DeserializeObject(item) as Dictionary <string, object>;

                string sample = "";
                if (obj.ContainsKey("sample_url"))
                {
                    sample = obj["sample_url"].ToString();
                }

                int file_size = 0;
                try
                {
                    if (obj.ContainsKey("file_size"))
                    {
                        file_size = Int32.Parse(obj["file_size"].ToString());
                    }
                }
                catch { }

                string created_at = "N/A";
                if (obj.ContainsKey("created_at"))
                {
                    created_at = obj["created_at"].ToString();
                }

                string preview_url = obj["preview_url"].ToString();
                string file_url    = obj["file_url"].ToString();

                string jpeg_url = file_url;
                if (obj.ContainsKey("jpeg_url"))
                {
                    jpeg_url = obj["jpeg_url"].ToString();
                }

                string tags   = obj["tags"].ToString();
                string id     = obj["id"].ToString();
                string source = obj["source"].ToString();
                //string width = obj["width"].ToString();
                //string height = obj["height"].ToString();
                int width  = 0;
                int height = 0;
                try
                {
                    width  = int.Parse(obj["width"].ToString().Trim());
                    height = int.Parse(obj["height"].ToString().Trim());
                }
                catch { }

                string score = "N/A";
                if (obj.ContainsKey("rating"))
                {
                    score = "Safe ";
                    if (obj["rating"].ToString() == "e")
                    {
                        score = "Explicit ";
                    }
                    else
                    {
                        score = "Questionable ";
                    }
                    if (obj.ContainsKey("score"))
                    {
                        score += obj["score"].ToString();
                    }
                }

                string host = url.Substring(0, url.IndexOf('/', 8));

                if (preview_url.StartsWith("/"))
                {
                    preview_url = host + preview_url;
                }
                if (file_url.StartsWith("/"))
                {
                    file_url = host + file_url;
                }
                if (sample.StartsWith("/"))
                {
                    sample = host + sample;
                }
                if (jpeg_url.StartsWith("/"))
                {
                    jpeg_url = host + jpeg_url;
                }

                //if (!UseJpeg)
                //jpeg_url = file_url;

                Img img = GenerateImg(file_url, preview_url, width, height, sample, created_at, tags, file_size, id, score, jpeg_url, source, url);
                if (img != null)
                {
                    imgs.Add(img);
                }
                #endregion

                index += 15;
            }
        }
コード例 #7
0
ファイル: SiteSankaku.cs プロジェクト: istobran/moe-loader
        private Img GenerateImg(string detailUrl, string preview_url, string tags, string id)
        {
            int intId = int.Parse(id);

            //convert relative url to absolute
            if (detailUrl.StartsWith("/"))
                detailUrl = SiteUrl + detailUrl;

            preview_url = FixUrl(preview_url);

            Img img = new Img()
            {
                //Date = "N/A",
                //FileSize = file_size.ToUpper(),
                Desc = tags,
                Id = intId,
                //JpegUrl = preview_url,
                //OriginalUrl = preview_url,
                PreviewUrl = preview_url,
                //SampleUrl = preview_url,
                //Score = 0,
                Tags = tags,
                DetailUrl = detailUrl
            };

            img.DownloadDetail = (i, p) =>
            {
                //retrieve details
                MyWebClient web = new MyWebClient();
                web.Proxy = p;
                web.Encoding = Encoding.UTF8;
                string page = web.DownloadString(i.DetailUrl);

                HtmlDocument doc = new HtmlDocument();
                doc.LoadHtml(page);
                //retrieve img node
                HtmlNodeCollection nodes = doc.DocumentNode.SelectSingleNode("//div[@id='stats']").SelectNodes(".//li");
                foreach (var node in nodes)
                {
                    if (node.InnerText.Contains("Posted"))
                    {
                        i.Date = node.SelectSingleNode("a").Attributes["title"].Value;
                    }
                    else if (node.InnerText.Contains("Resized"))
                    {
                        i.SampleUrl = node.SelectSingleNode("a").Attributes["href"].Value;
                        i.SampleUrl = FixUrl(i.SampleUrl);
                    }
                    else if (node.InnerText.Contains("Original"))
                    {
                        i.OriginalUrl = node.SelectSingleNode("a").Attributes["href"].Value;
                        i.OriginalUrl = FixUrl(i.OriginalUrl);
                        i.JpegUrl = i.OriginalUrl;
                        //1368x1000 (197.4 KB)
                        string size = node.SelectSingleNode("a").InnerText;
                        i.Dimension = size.Substring(0, size.IndexOf(' '));
                        i.FileSize = size.Substring(size.IndexOf('(') + 1);
                        i.FileSize = i.FileSize.Substring(0, i.FileSize.Length -  1);
                    }
                }
            };

            return img;
        }
コード例 #8
0
ファイル: SiteMiniTokyo.cs プロジェクト: istobran/moe-loader
        private Img GenerateImg(string file_url, string preview_url, string dimension, string tags, string sample_url, string scorestr, string id, string detailUrl)
        {
            int intId = int.Parse(id);

            int width = 0, height = 0, score = 0;
            try
            {
                //706x1000
                width = int.Parse(dimension.Substring(0, dimension.IndexOf('x')));
                height = int.Parse(dimension.Substring(dimension.IndexOf('x') + 1));
                score = int.Parse(scorestr);
            }
            catch { }

            Img img = new Img()
            {
                Date = "",
                FileSize = "",
                Desc = tags,
                Id = intId,
                //IsViewed = isViewed,
                JpegUrl = file_url,
                OriginalUrl = file_url,
                PreviewUrl = preview_url,
                SampleUrl = sample_url,
                Score = score,
                //Size = width + " x " + height,
                Width = width,
                Height = height,
                //Source = "",
                Tags = tags,
                DetailUrl = detailUrl
            };
            return img;
        }
コード例 #9
0
        /// <summary>
        /// 添加预览
        /// </summary>
        /// <param name="img"></param>
        /// <param name="parentIndex"></param>
        /// <param name="needReferer"></param>
        public void AddPreview(Img img, int parentIndex, string needReferer)
        {
            if (!imgs.ContainsKey(img.Id))
            {
                imgs.Add(img.Id, index++);
                oriIndex.Add(img.Id, parentIndex);
                descs.Add(img.Id, img);
                ToggleButton btn = new ToggleButton
                {
                    Content = img.Id
                };
                btn.Checked += new RoutedEventHandler(btn_Click);
                btns.Children.Add(btn);

                Image iiii = new Image()
                {
                    Source = new BitmapImage(new Uri("/Images/loading.png", UriKind.Relative))
                };
                iiii.MouseLeftButtonUp += new MouseButtonEventHandler(delegate(object s1, MouseButtonEventArgs ea)
                {
                    preMX = 0; preMY = 0;
                });
                iiii.MouseLeftButtonDown += new MouseButtonEventHandler(delegate(object s1, MouseButtonEventArgs ea)
                {
                    preMX = 0; preMY = 0;
                });
                iiii.MouseDown += new MouseButtonEventHandler(delegate(object s1, MouseButtonEventArgs ea)
                {
                    if (ea.MiddleButton == MouseButtonState.Pressed)
                    {
                        Button_Click_2(null, null);
                    }
                });
                iiii.MouseMove += new MouseEventHandler(delegate(object s1, MouseEventArgs ea)
                {
                    //拖动
                    if (ea.LeftButton == MouseButtonState.Pressed)
                    {
                        if (preMY != 0 && preMX != 0)
                        {
                            int offX        = (int)(ea.GetPosition(LayoutRoot).X) - preMX;
                            int offY        = (int)(ea.GetPosition(LayoutRoot).Y) - preMY;
                            ScrollViewer sc = (imgGrid.Children[imgs[selectedId]] as ScrollViewer);
                            sc.ScrollToHorizontalOffset(sc.HorizontalOffset - offX);
                            sc.ScrollToVerticalOffset(sc.VerticalOffset - offY);
                        }
                        preMX = (int)(ea.GetPosition(LayoutRoot).X);
                        preMY = (int)(ea.GetPosition(LayoutRoot).Y);
                    }
                });
                iiii.ImageFailed += new EventHandler <ExceptionRoutedEventArgs>(iiii_ImageFailed);

                imgGrid.Children.Add(new ScrollViewer()
                {
                    Content    = iiii,
                    Visibility = System.Windows.Visibility.Hidden,
                    HorizontalScrollBarVisibility = ScrollBarVisibility.Auto,
                    VerticalScrollBarVisibility   = ScrollBarVisibility.Auto,
                });
                DownloadImg(img.Id, img.SampleUrl, needReferer);

                if (selectedId == 0)
                {
                    (btns.Children[btns.Children.Count - 1] as ToggleButton).IsChecked = true;
                }
            }
        }
コード例 #10
0
ファイル: SitePixiv.cs プロジェクト: istobran/moe-loader
        // DO NOT SUPPORT TAG HINT
        //public override List<TagItem> GetTags(string word, System.Net.IWebProxy proxy)
        //{
        //    List<TagItem> re = new List<TagItem>();
        //    return re;
        //}

        private Img GenerateImg(string detailUrl, string preview_url, string id)
        {
            int intId = int.Parse(id);

            if (!detailUrl.StartsWith("http") && !detailUrl.StartsWith("/"))
                detailUrl = "/" + detailUrl;

            //convert relative url to absolute
            if (detailUrl.StartsWith("/"))
                detailUrl = SiteUrl + detailUrl;
            if (preview_url.StartsWith("/"))
                preview_url = SiteUrl + preview_url;

            //string fileUrl = preview_url.Replace("_s.", ".");
            //string sampleUrl = preview_url.Replace("_s.", "_m.");

            //http://i1.pixiv.net/img-inf/img/2013/04/10/00/11/37/34912478_s.png
            //http://i1.pixiv.net/img03/img/tukumo/34912478_m.png
            //http://i1.pixiv.net/img03/img/tukumo/34912478.png

            Img img = new Img()
            {
                //Date = "N/A",
                //FileSize = file_size.ToUpper(),
                //Desc = intId + " ",
                Id = intId,
                //JpegUrl = fileUrl,
                //OriginalUrl = fileUrl,
                PreviewUrl = preview_url,
                //SampleUrl = sampleUrl,
                //Score = 0,
                //Width = width,
                //Height = height,
                //Tags = tags,
                DetailUrl = detailUrl
            };

            img.DownloadDetail = new DetailHandler((i, p) =>
            {
                //retrieve details
                MyWebClient web = new MyWebClient();
                web.Proxy = p;
                web.Encoding = Encoding.UTF8;
                web.Headers["Cookie"] = cookie;
                web.Headers["Referer"] = Referer;
                string page = web.DownloadString(i.DetailUrl);

                HtmlDocument doc = new HtmlDocument();
                doc.LoadHtml(page);

                //04/16/2012 17:44|600×800|SAI  or 04/16/2012 17:44|600×800 or 04/19/2012 22:57|漫画 6P|SAI
                i.Date = doc.DocumentNode.SelectSingleNode("//ul[@class='meta']/li[1]").InnerText;
                //总点数
                i.Score = int.Parse(doc.DocumentNode.SelectSingleNode("//dd[@class='score-count']").InnerText);
                //「カルタ&わたぬき」/「えれっと」のイラスト [pixiv]
                i.Desc += doc.DocumentNode.SelectSingleNode("//title").InnerText.Replace("のイラスト [pixiv]", "").Replace("の漫画 [pixiv]", "").Replace("「", "").Replace("」", "").Replace("/", "_");
                //URLS
                //http://i2.pixiv.net/c/600x600/img-master/img/2014/10/08/06/13/30/46422743_p0_master1200.jpg
                //http://i2.pixiv.net/img-original/img/2014/10/08/06/13/30/46422743_p0.png
                i.SampleUrl = doc.DocumentNode.SelectSingleNode("//div[@class='works_display']").SelectSingleNode(".//img").Attributes["src"].Value;
                i.OriginalUrl = i.SampleUrl.Replace("600x600", "1200x1200");
                i.JpegUrl = i.OriginalUrl;
                
                //600×800 or 漫画 6P
                string dimension = doc.DocumentNode.SelectSingleNode("//ul[@class='meta']/li[2]").InnerText;
                try
                {
                    //706×1000
                    i.Width = int.Parse(dimension.Substring(0, dimension.IndexOf('×')));
                    i.Height = int.Parse(System.Text.RegularExpressions.Regex.Match(dimension.Substring(dimension.IndexOf('×') + 1), @"\d+").Value);
                }
                catch { }
                try
                {
                    if (i.Width == 0 && i.Height == 0)
                    {
                        //i.OriginalUrl = i.SampleUrl.Replace("600x600", "1200x1200");
                        i.JpegUrl = i.OriginalUrl;
                        //manga list
                        //漫画 6P
                        int index = dimension.IndexOf(' ') + 1;
                        string mangaPart = dimension.Substring(index, dimension.IndexOf('P') - index);
                        int mangaCount = int.Parse(mangaPart);
                        i.Dimension = "Manga " + mangaCount + "P";
                        for (int j = 0; j < mangaCount; j++)
                        {
                            //oriUrl = "http://img" + imgsvr + ".pixiv.net/img/" + items[6].Split('/')[4] + "/" + id + "_p0." + ext;
                            img.OrignalUrlList.Add(i.OriginalUrl.Replace("_p0", "_p" + j));
                        }
                    }
                }
                catch { }
            });

            return img;
        }
コード例 #11
0
ファイル: SiteWCosplay.cs プロジェクト: istobran/moe-loader
        //public override List<TagItem> GetTags(string word, System.Net.IWebProxy proxy)
        //{
        //    List<TagItem> re = new List<TagItem>();
        //    return re;
        //}

        private Img GenerateImg(string preview_url, string chara, string member, string twidth, string theight, string date, string sscore, string id, string detailUrl)
        {
            int intId = int.Parse(id);
            int score;
            int.TryParse(sscore, out score);

            int width = 0, height = 0;
            try
            {
                //缩略图的尺寸 175级别 大图 740级别
                width = int.Parse(twidth);
                height = int.Parse(theight);
                if (width > height)
                {
                    //width 175
                    height = 740 * height / width;
                    width = 740;
                }
                else
                {
                    width = 740 * width / height;
                    height = 740;
                }
            }
            catch { }

            //convert relative url to absolute
            if (preview_url.StartsWith("/"))
                preview_url = SiteUrl + preview_url;

            //http://image.worldcosplay.net/uploads/26450/8b6438c21db2b1402f63427d0ef8983a85969d0a-175.jpg
            string fileUrl = preview_url.Replace("-175", "-740");

            Img img = new Img()
            {
                Date = date,
                FileSize = "",
                Desc = member + " | " + chara,
                Id = intId,
                JpegUrl = fileUrl,
                OriginalUrl = fileUrl,
                PreviewUrl = preview_url,
                SampleUrl = fileUrl,
                Score = score,
                Width = width,
                Height = height,
                Tags = member + " | " + chara,
                DetailUrl = detailUrl
            };

            return img;
        }
コード例 #12
0
 private string GenFileName(Img img)
 {
     //namePatter
     string file = namePatter;
     //%site 站点缩写 %id 编号 %tag 标签 %desc 描述
     file = file.Replace("%site", SiteManager.Instance.Sites[nowSelectedIndex].ShortName);
     file = file.Replace("%id", img.Id.ToString());
     file = file.Replace("%tag", img.Tags);
     file = file.Replace("%desc", img.Desc);
     return file;
 }
コード例 #13
0
 /// <summary>
 /// 获取Img的地址
 /// </summary>
 /// <param name="img"></param>
 /// <returns></returns>
 private List<string> GetImgAddress(Img img)
 {
     if (img.OrignalUrlList.Count > 0)
     {
         return img.OrignalUrlList;
     }
     else
     {
         string url = img.OriginalUrl;
         switch (addressType)
         {
             case AddressType.Jpg:
                 url = img.JpegUrl;
                 break;
             case AddressType.Pre:
                 url = img.SampleUrl;
                 break;
             case AddressType.Small:
                 url = img.PreviewUrl;
                 break;
         }
         List<string> urls = new List<string>();
         urls.Add(url);
         return urls;
     }
 }
コード例 #14
0
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="img">图片</param>
        /// <param name="index">位置索引</param>
        /// <param name="isRed">是否已经浏览过</param>
        /// <param name="needReferer">是否需要伪造Referer</param>
        public ImgControl(Img img, int index, string referer, bool supportScore)
        {
            this.needReferer = referer;
            this.InitializeComponent();
            this.img   = img;
            this.index = index;

            if (img.IsViewed)
            {
                //statusBorder.Background = new SolidColorBrush(Color.FromArgb(0xCC, 0xFE, 0xE2, 0xE2));
                statusBorder.Background = new SolidColorBrush(Color.FromArgb(0xEE, 0xE9, 0x93, 0xAA));
            }

            //try
            //{
            //string s = .Substring(img.Score.IndexOf(' '), img.Score.Length - img.Score.IndexOf(' '));
            //score.Text = img.Score.ToString();
            //}
            //catch { }

            if (!supportScore)
            {
                //brdScr.Visibility = System.Windows.Visibility.Hidden;
            }

            //chk.Text = img.Dimension;

            //RenderOptions.SetBitmapScalingMode(preview, BitmapScalingMode.Fant);
            preview.DataContext = img;

            preview.SizeChanged  += new SizeChangedEventHandler(preview_SizeChanged);
            preview.ImageFailed  += new EventHandler <ExceptionRoutedEventArgs>(preview_ImageFailed);
            preview.MouseUp      += new MouseButtonEventHandler(preview_MouseUp);
            statusBorder.MouseUp += new MouseButtonEventHandler(preview_MouseUp);
            chk.MouseUp          += new MouseButtonEventHandler(preview_MouseUp);
            txtDesc.MouseUp      += new MouseButtonEventHandler(preview_MouseUp);

            downBtn.MouseUp += new MouseButtonEventHandler(Border_MouseUp);
            magBtn.MouseUp  += new MouseButtonEventHandler(preview_Click);

            //chk.Click += chk_Checked;

            //ToolTip tip = preview.ToolTip as ToolTip;
            //tip.PlacementTarget = preview.Parent as UIElement;
            //TextBlock desc = (tip.Content as Border).Child as TextBlock;

            //下载缩略图
            //DownloadImg();

            if (img.DownloadDetail != null)
            {
                //need detail
                LayoutRoot.IsEnabled = false;
                //isRetrievingDetail = true;
                chk.Text = "信息尚未加载";
            }
            else
            {
                ShowImgDetail();
            }
        }
コード例 #15
0
ファイル: SiteZeroChan.cs プロジェクト: istobran/moe-loader
        private Img GenerateImg(string file_url, string preview_url, string sample_url, string dimension, string tags, string file_size, int id)
        {
            //int intId = int.Parse(id.Substring(1));

            int width = 0, height = 0;
            try
            {
                //706x1000
                width = int.Parse(dimension.Substring(0, dimension.IndexOf('x')));
                height = int.Parse(dimension.Substring(dimension.IndexOf('x') + 1));
            }
            catch { }

            //convert relative url to absolute
            if (file_url.StartsWith("/"))
                file_url = SiteUrl + file_url;
            if (preview_url.StartsWith("/"))
                preview_url = SiteUrl + preview_url;

            Img img = new Img()
            {
                //Date = "N/A",
                FileSize = file_size.ToUpper(),
                Desc = tags,
                Id = id,
                //IsViewed = isViewed,
                JpegUrl = file_url,
                OriginalUrl = file_url,
                PreviewUrl = preview_url,
                SampleUrl = sample_url,
                //Score = 0,
                //Size = width + " x " + height,
                Width = width,
                Height = height,
                //Source = "",
                Tags = tags,
                DetailUrl = SiteUrl + "/" + id,
            };
            return img;
        }
コード例 #16
0
        /// <summary>
        /// 添加预览
        /// </summary>
        /// <param name="img"></param>
        /// <param name="parentIndex"></param>
        /// <param name="needReferer"></param>
        public void AddPreview(Img img, int parentIndex, string needReferer)
        {
            if (!imgs.ContainsKey(img.Id))
            {
                imgs.Add(img.Id, index++);
                oriIndex.Add(img.Id, parentIndex);
                descs.Add(img.Id, img);
                ToggleButton btn = new ToggleButton
                {
                    Content = img.Id
                };
                btn.Checked += new RoutedEventHandler(btn_Click);
                btns.Children.Add(btn);

                Image iiii = new Image()
                {
                    Source = new BitmapImage(new Uri("/Images/loading.png", UriKind.Relative))
                };
                iiii.MouseLeftButtonUp += new MouseButtonEventHandler(delegate(object s1, MouseButtonEventArgs ea)
                {
                    preMX = 0; preMY = 0;
                });
                iiii.MouseLeftButtonDown += new MouseButtonEventHandler(delegate(object s1, MouseButtonEventArgs ea)
                {
                    preMX = 0; preMY = 0;
                });
                iiii.MouseDown += new MouseButtonEventHandler(delegate(object s1, MouseButtonEventArgs ea)
                {
                    if (ea.MiddleButton == MouseButtonState.Pressed)
                        Button_Click_2(null, null);
                });
                iiii.MouseMove += new MouseEventHandler(delegate(object s1, MouseEventArgs ea)
                {
                    //拖动
                    if (ea.LeftButton == MouseButtonState.Pressed)
                    {
                        if (preMY != 0 && preMX != 0)
                        {
                            int offX = (int)(ea.GetPosition(LayoutRoot).X) - preMX;
                            int offY = (int)(ea.GetPosition(LayoutRoot).Y) - preMY;
                            ScrollViewer sc = (imgGrid.Children[imgs[selectedId]] as ScrollViewer);
                            sc.ScrollToHorizontalOffset(sc.HorizontalOffset - offX);
                            sc.ScrollToVerticalOffset(sc.VerticalOffset - offY);
                        }
                        preMX = (int)(ea.GetPosition(LayoutRoot).X);
                        preMY = (int)(ea.GetPosition(LayoutRoot).Y);
                    }
                });
                iiii.ImageFailed += new EventHandler<ExceptionRoutedEventArgs>(iiii_ImageFailed);

                imgGrid.Children.Add(new ScrollViewer()
                {
                    Content = iiii,
                    Visibility = System.Windows.Visibility.Hidden,
                    HorizontalScrollBarVisibility = ScrollBarVisibility.Auto,
                    VerticalScrollBarVisibility = ScrollBarVisibility.Auto,
                });
                DownloadImg(img.Id, img.SampleUrl, needReferer);

                if (selectedId == 0)
                {
                    (btns.Children[btns.Children.Count - 1] as ToggleButton).IsChecked = true;
                }
            }
        }
コード例 #17
0
ファイル: BooruProcessor.cs プロジェクト: istobran/moe-loader
        /// <summary>
        /// 生成 Img 对象
        /// </summary>
        /// <param name="file_url"></param>
        /// <param name="preview_url"></param>
        /// <param name="sample"></param>
        /// <param name="created_at"></param>
        /// <param name="tags"></param>
        /// <param name="file_size"></param>
        /// <param name="id"></param>
        /// <param name="score"></param>
        /// <param name="jpeg_url"></param>
        /// <returns></returns>
        private Img GenerateImg(string file_url, string preview_url, int width, int height, string sample
            , string created_at, string tags, int file_size, string id, string score, string jpeg_url, string src, string url)
        {
            int scoreInt = 0, intId = 0;
            try
            {
                intId = int.Parse(id);
            }
            catch { }
            try
            {
                scoreInt = Int32.Parse(score.Substring(score.IndexOf(' '), score.Length - score.IndexOf(' ')));
            }
            catch { }

            #region DateTime Convert
            //eg. Fri Aug 28 20:05:57 -0600 2009 or 1291280246
            try
            {
                //1291280246   ==   2010/12/2 16:57
                long sec = long.Parse(created_at);
                DateTime startDate = new DateTime(1970, 1, 1, 8, 0, 0, 0);
                created_at = startDate.AddSeconds(sec).ToString();
            }
            catch
            {
                //Thu Dec 31 06:54:54 +0000 2009
                //2012/01/28 01:59:10 -0500
                //1323123123
                //Dec Nov Oct Sep Aug Jul Jun May Apr Mar Feb Jan
                try
                {
                    created_at = DateTime.Parse(created_at).ToString();
                }
                catch { }
            }
            #endregion

            string host = url.Substring(0, url.IndexOf('/', 8));
            string detailUrl = host + "/post/show/" + id;
            if (url.Contains("index.php"))
                detailUrl = host + "/index.php?page=post&s=view&id=" + id;

            Img img = new Img()
            {
                Date = created_at,
                Desc = tags,
                FileSize = file_size > 1048576 ? (file_size / 1048576.0).ToString("0.00MB") : (file_size / 1024.0).ToString("0.00KB"),
                Height = height,
                Id = intId,
                IsExplicit = score.StartsWith("E"),
                JpegUrl = jpeg_url,
                OriginalUrl = file_url,
                PreviewUrl = preview_url,
                SampleUrl = sample,
                Score = scoreInt,
                Source = src,
                Tags = tags,
                Width = width,
                DetailUrl = detailUrl
            };
            return img;
        }
コード例 #18
0
ファイル: SiteDanbooru.cs プロジェクト: istobran/moe-loader
        public override List<Img> GetImages(string pageString, System.Net.IWebProxy proxy)
        {
            List<Img> list = new List<Img>();
            HtmlDocument document = new HtmlDocument();
            document.LoadHtml(pageString);
            HtmlNodeCollection nodes = document.DocumentNode.SelectNodes("//article");
            if (nodes == null)
            {
                return list;
            }

            foreach (HtmlNode node in nodes)
            {
                HtmlNode node2 = node.SelectSingleNode("a");
                HtmlNode node3 = node2.SelectSingleNode("img");

                string detailUrl = SiteUrl + node2.Attributes["href"].Value;

                Img item = new Img()
                {
                    Desc = node.Attributes["data-tags"].Value,
                    Height = Convert.ToInt32(node.Attributes["data-height"].Value),
                    Id = Convert.ToInt32(node.Attributes["data-id"].Value),
                    IsExplicit = node.Attributes["data-rating"].Value == "e",
                    Tags = node.Attributes["data-tags"].Value,
                    Width = Convert.ToInt32(node.Attributes["data-width"].Value),
                    PreviewUrl = this.SiteUrl + node3.Attributes["src"].Value,
                    DetailUrl = detailUrl
                };

                
                item.DownloadDetail = (i, p) =>
                {
                    string html = new MyWebClient { Proxy = p, Encoding = Encoding.UTF8 }.DownloadString(i.DetailUrl);
                    HtmlDocument doc = new HtmlDocument();
                    doc.LoadHtml(html);
                    HtmlNodeCollection sectionNodes = doc.DocumentNode.SelectNodes("//section");
                    foreach (HtmlNode n in sectionNodes)
                    {
                        var ns = n.SelectNodes(".//li");
                        if (ns == null) continue;
                        foreach (HtmlNode n1 in ns)
                        {
                            if (n1.InnerText.Contains("Date:"))
                            {
                                i.Date = n1.SelectSingleNode(".//time").Attributes["title"].Value;
                            }
                            if (n1.InnerText.Contains("Size:"))
                            {
                                i.OriginalUrl = this.SiteUrl + n1.SelectSingleNode(".//a").Attributes["href"].Value;
                                i.JpegUrl = i.OriginalUrl;
                                i.FileSize = n1.SelectSingleNode(".//a").InnerText;
                                i.Dimension = n1.InnerText.Substring(n1.InnerText.IndexOf('(') + 1, n1.InnerText.LastIndexOf(')') - n1.InnerText.IndexOf('(') - 1);
                            }
                            if (n1.InnerText.Contains("Score:"))
                            {
                                i.Score = Convert.ToInt32(n1.SelectSingleNode(".//span").InnerText);
                            }
                        }
                    }
                    i.SampleUrl = this.SiteUrl + doc.DocumentNode.SelectSingleNode("//img[@id='image']").Attributes["src"].Value;
                };
                list.Add(item);
            }
            
            return list;
        }
コード例 #19
0
ファイル: SiteMjvArt.cs プロジェクト: istobran/moe-loader
        private Img GenerateImg(string detailUrl, string preview_url, string dimension, string tags, string id)
        {
            int intId = int.Parse(id);

            int width = 0, height = 0;
            try
            {
                //706x1000
                width = int.Parse(dimension.Substring(0, dimension.IndexOf('x')));
                height = int.Parse(dimension.Substring(dimension.IndexOf('x') + 1));
            }
            catch { }

            //convert relative url to absolute
            if (detailUrl.StartsWith("/"))
                detailUrl = SiteUrl + detailUrl;
            if (preview_url.StartsWith("/"))
                preview_url = SiteUrl + preview_url;

            Img img = new Img()
            {
                //Date = "N/A",
                //FileSize = file_size.ToUpper(),
                //Desc = tags,
                Id = intId,
                //JpegUrl = preview_url,
                //OriginalUrl = preview_url,
                PreviewUrl = preview_url,
                //SampleUrl = preview_url,
                //Score = 0,
                Width = width,
                Height = height,
                //Tags = tags,
                DetailUrl = detailUrl,
            };

            img.DownloadDetail = new DetailHandler((i, p) =>
            {
                //retrieve details
                MyWebClient web = new MyWebClient();
                web.Proxy = p;
                web.Headers["Cookie"] = sessionId;
                web.Encoding = Encoding.UTF8;
                string page = web.DownloadString(i.DetailUrl);

                //<b>Size:</b> 326.0KB<br>
                int index = page.IndexOf("<b>Size");
                string fileSize = page.Substring(index + 12, page.IndexOf('<', index + 12) - index - 12).Trim();
                //<b>Date Published:</b> 2/24/12 4:57 PM
                index = page.IndexOf("<b>Date Published");
                string date = page.Substring(index + 22, page.IndexOf('<', index + 22) - index - 22).Trim();

                HtmlDocument doc = new HtmlDocument();
                doc.LoadHtml(page);
                //retrieve img node
                HtmlNode node = doc.DocumentNode.SelectSingleNode("//div[@id='big_preview_cont']").SelectSingleNode("a");
                string fileUrl = node.Attributes["href"].Value;
                string sampleUrl = node.SelectSingleNode("img").Attributes["src"].Value;
                i.Tags = doc.DocumentNode.SelectSingleNode("//meta[@name='description']").Attributes["content"].Value;
                i.Tags = i.Tags.Replace('\n', ' ').Replace("\t", "");
                i.Desc = i.Tags;

                if (fileUrl.StartsWith("/"))
                    fileUrl = SiteUrl + fileUrl;
                if (sampleUrl.StartsWith("/"))
                    sampleUrl = SiteUrl + sampleUrl;

                i.Date = date;
                i.FileSize = fileSize;
                i.JpegUrl = fileUrl;
                i.OriginalUrl = fileUrl;
                i.SampleUrl = sampleUrl;
            });

            return img;
        }