示例#1
0
        public async Task <ImageItems> GetRealPageImagesAsyncFromJson(SearchPara para, CancellationToken token)
        {
            var client  = new NetSwap(Settings).Client;
            var query   = GetPageQuery(para);
            var jsonRes = await client.GetAsync(query, token);

            var jsonStr = await jsonRes.Content.ReadAsStringAsync();

            return(await Task.Run(() =>
            {
                token.ThrowIfCancellationRequested();
                var imageitems = new ImageItems();
                dynamic list = JsonConvert.DeserializeObject(jsonStr);
                if (list == null)
                {
                    return imageitems;
                }
                foreach (var item in list)
                {
                    token.ThrowIfCancellationRequested();
                    var img = new ImageItem(this, para);

                    img.Width = (int)item.image_width;
                    img.Height = (int)item.image_height;
                    img.Id = (int)item.id;
                    img.Score = (int)item.score;
                    img.Author = $"{item.uploader_name}";
                    var tagsstr = $"{item.tag_string}";
                    foreach (var tag in tagsstr.Split(' '))
                    {
                        if (!string.IsNullOrWhiteSpace(tag))
                        {
                            img.Tags.Add(tag.Trim());
                        }
                    }

                    img.IsExplicit = $"{item.rating}" == "e";
                    img.DetailUrl = GetDetailPageUrl(img);
                    img.Urls.Add(new UrlInfo("缩略图", 1, $"{item.preview_file_url}", GetThumbnailReferer(img)));
                    img.Urls.Add(new UrlInfo("预览图", 2, $"{item.large_file_url}", GetThumbnailReferer(img)));
                    img.Urls.Add(new UrlInfo("原图", 4, $"{item.file_url}", img.DetailUrl));
                    //img.Net = Net;
                    imageitems.Add(img);
                }

                return imageitems;
            }, token));
        }
示例#2
0
        public async Task <ImageItems> GetRealPageImagesAsyncFromXml(SearchPara para, CancellationToken token)
        {
            var client = new NetSwap(Settings).Client;
            var query  = GetPageQuery(para);
            var xmlres = await client.GetAsync(query, token);

            var xmlstr = await xmlres.Content.ReadAsStreamAsync();

            return(await Task.Run(() =>
            {
                var xml = XDocument.Load(xmlstr);
                var imageitems = new ImageItems();
                if (xml.Root == null)
                {
                    return imageitems;
                }
                foreach (var post in xml.Root.Elements())
                {
                    token.ThrowIfCancellationRequested();
                    var img = new ImageItem(this, para);

                    int.TryParse(post.Attribute("id")?.Value, out var id);
                    img.Id = id;
                    var tags = post.Attribute("tags")?.Value ?? "";
                    foreach (var tag in tags.Split(' '))
                    {
                        if (!string.IsNullOrWhiteSpace(tag))
                        {
                            img.Tags.Add(tag.Trim());
                        }
                    }
                    int.TryParse(post.Attribute("width")?.Value, out var width);
                    img.Width = width;
                    int.TryParse(post.Attribute("height")?.Value, out var height);
                    img.Height = height;
                    img.Author = post.Attribute("author")?.Value;
                    img.Source = post.Attribute("source")?.Value;
                    img.IsExplicit = post.Attribute("rating")?.Value.ToLower() != "s";
                    img.DetailUrl = GetDetailPageUrl(img);
                    img.Site = this;
                    double.TryParse(post.Attribute("created_at")?.Value, out var creatat);
                    if (creatat > 0)
                    {
                        img.CreatTime = new DateTime(1970, 1, 1, 0, 0, 0, 0) + TimeSpan.FromSeconds(creatat);
                    }
                    int.TryParse(post.Attribute("score")?.Value, out var score);
                    img.Score = score;
                    ulong.TryParse(post.Attribute("file_size")?.Value, out var filesize);

                    img.Urls.Add(new UrlInfo("缩略图", 1, UrlPre + post.Attribute("preview_url")?.Value, GetThumbnailReferer(img)));
                    img.Urls.Add(new UrlInfo("预览图", 2, UrlPre + post.Attribute("sample_url")?.Value, GetThumbnailReferer(img)));
                    img.Urls.Add(new UrlInfo("Jpeg图", 3, UrlPre + post.Attribute("jpeg_url")?.Value, GetThumbnailReferer(img)));
                    img.Urls.Add(new UrlInfo("原图", 4, UrlPre + post.Attribute("file_url")?.Value, img.DetailUrl)
                    {
                        Md5 = post.Attribute("md5")?.Value,
                        BiteSize = filesize,
                    });

                    imageitems.Add(img);
                }
                return imageitems;
            }, token));
        }