コード例 #1
0
 public void AddRange(MoeItems items)
 {
     foreach (var moeItem in items)
     {
         Add(moeItem);
     }
 }
コード例 #2
0
        public async Task <MoeItems> GetRealPageImagesAsyncFromXml(SearchPara para, CancellationToken token)
        {
            var client = new NetOperator(Settings).Client;
            var query  = GetPageQuery(para);
            var xmlRes = await client.GetAsync(query, token);

            var xmlStr = await xmlRes.Content.ReadAsStreamAsync();

            var xml        = XDocument.Load(xmlStr);
            var imageItems = new MoeItems();

            if (xml.Root == null)
            {
                return(imageItems);
            }
            foreach (var post in xml.Root.Elements())
            {
                token.ThrowIfCancellationRequested();
                var img  = new MoeItem(this, para);
                var tags = post.Attribute("tags")?.Value ?? "";
                foreach (var tag in tags.Split(' '))
                {
                    if (!tag.IsEmpty())
                    {
                        img.Tags.Add(tag.Trim());
                    }
                }

                img.Id         = post.Attribute("id")?.Value.ToInt() ?? 0;
                img.Width      = post.Attribute("width")?.Value.ToInt() ?? 0;
                img.Height     = post.Attribute("height")?.Value.ToInt() ?? 0;
                img.Uploader   = post.Attribute("author")?.Value;
                img.Source     = post.Attribute("source")?.Value;
                img.IsExplicit = post.Attribute("rating")?.Value.ToLower() != "s";
                img.DetailUrl  = GetDetailPageUrl(img);
                img.Date       = post.Attribute("created_at")?.Value.ToDateTime();
                if (img.Date == null)
                {
                    img.DateString = post.Attribute("created_at")?.Value;
                }
                img.Score = post.Attribute("score")?.Value.ToInt() ?? 0;
                img.Urls.Add(1, $"{UrlPre}{post.Attribute("preview_url")?.Value}", GetThumbnailReferer(img));
                img.Urls.Add(2, $"{UrlPre}{post.Attribute("sample_url")?.Value}", GetThumbnailReferer(img));
                img.Urls.Add(3, $"{UrlPre}{post.Attribute("jpeg_url")?.Value}", GetThumbnailReferer(img));
                img.Urls.Add(4, $"{UrlPre}{post.Attribute("file_url")?.Value}", img.DetailUrl);
                img.OriginString = $"{post}";
                if (GetDetailTaskFunc != null)
                {
                    img.GetDetailTaskFunc = async() => await GetDetailTaskFunc(img, para, token);
                }
                imageItems.Add(img);
            }

            var count  = xml.Root.Attribute("count")?.Value.ToInt();
            var offset = xml.Root.Attribute("offset")?.Value.ToInt();

            Extend.ShowMessage($"共搜索到{count}张图片,当前第{offset+1}张,第{para.PageIndex}页,共{count / para.Count}页", null, Extend.MessagePos.InfoBar);
            return(imageItems);
        }
コード例 #3
0
ファイル: PixivSite.cs プロジェクト: N0best1rn/MoeLoaderP
        public override async Task <MoeItems> GetRealPageImagesAsync(SearchPara para, CancellationToken token)
        {
            if (Net?.HttpClientHandler?.CookieContainer == null)
            {
                Net = new NetOperator(Settings, HomeUrl);
                Net.HttpClientHandler.AllowAutoRedirect = true;
                Net.HttpClientHandler.UseCookies        = true;
                var cc = GetCookies();
                if (cc == null)
                {
                    Extend.ShowMessage("需要重新登录Pixiv站点", null, Extend.MessagePos.Window);
                    Net = null;
                    return(null);
                }
                Net.HttpClientHandler.CookieContainer = cc;
                Net.SetTimeOut(40);
            }
            else
            {
                Net = Net.CloneWithOldCookie();
            }

            var imgs = new MoeItems();

            switch ((SearchTypeEnum)para.SubMenuIndex)
            {
            case SearchTypeEnum.TagOrNew:
                await SearchByNewOrTag(imgs, para, token);

                break;

            case SearchTypeEnum.Author:     // 作者 member id  word = "4338012"; // test
                if (para.Keyword.ToInt() == 0)
                {
                    Extend.ShowMessage("参数错误,必须在关键词中指定画师 id(纯数字)", null, Extend.MessagePos.Window);
                }
                else
                {
                    await SearchByAuthor(imgs, para.Keyword.Trim(), para, token);
                }
                break;

            case SearchTypeEnum.Rank:
                await SearchByRank(imgs, para, token);

                break;
            }

            token.ThrowIfCancellationRequested();
            return(imgs);
        }
コード例 #4
0
        public override async Task <MoeItems> GetRealPageImagesAsync(SearchPara para, CancellationToken token)
        {
            var imgs = new MoeItems();

            if (para.Keyword.IsEmpty())
            {
                await SearchByNewOrHot(para, token, imgs);
            }
            else
            {
                await SearchByKeyword(para, token, imgs);
            }
            return(imgs);
        }
コード例 #5
0
        public async Task <MoeItems> GetRealPageImagesAsyncFromJson(SearchPara para, CancellationToken token)
        {
            var list = await new NetOperator(Settings).GetJsonAsync(GetPageQuery(para), token);

            return(await Task.Run(() =>
            {
                token.ThrowIfCancellationRequested();
                var imageItems = new MoeItems();
                if (list == null)
                {
                    return imageItems;
                }
                foreach (var item in list)
                {
                    token.ThrowIfCancellationRequested();
                    var img = new MoeItem(this, para);
                    img.Width = $"{item.image_width}".ToInt();
                    img.Height = $"{item.image_height}".ToInt();
                    img.Id = $"{item.id}".ToInt();
                    img.Score = $"{item.score}".ToInt();
                    img.Uploader = $"{item.uploader_name}";
                    foreach (var tag in $"{item.tag_string}".Split(' ').SkipWhile(string.IsNullOrWhiteSpace))
                    {
                        img.Tags.Add(tag.Trim());
                    }

                    img.IsExplicit = $"{item.rating}" == "e";
                    img.DetailUrl = GetDetailPageUrl(img);
                    img.Date = $"{item.created_at}".ToDateTime();
                    if (img.Date == null)
                    {
                        img.DateString = $"{item.created_at}";
                    }
                    img.Urls.Add(1, $"{item.preview_file_url}", GetThumbnailReferer(img));
                    img.Urls.Add(2, $"{item.large_file_url}", GetThumbnailReferer(img));
                    img.Urls.Add(4, $"{item.file_url}", img.DetailUrl);
                    img.Copyright = $"{item.tag_string_copyright}";
                    img.Character = $"{item.tag_string_character}";
                    img.Artist = $"{item.tag_string_artist}";
                    img.OriginString = $"{item}";
                    if (GetDetailTaskFunc != null)
                    {
                        img.GetDetailTaskFunc = async() => await GetDetailTaskFunc(img, para, token);
                    }
                    imageItems.Add(img);
                }

                return imageItems;
            }, token));
        }
コード例 #6
0
        public override async Task <MoeItems> GetRealPageImagesAsync(SearchPara para, CancellationToken token)
        {
            if (!_isIdolLogin)
            {
                await LoginAsync(token);
            }
            if (!_isIdolLogin)
            {
                return(new MoeItems());
            }
            var query = $"{_idolQuery}page={para.PageIndex}&limit={para.Count}&tags={para.Keyword.ToEncodedUrl()}";
            var list  = await Net.GetJsonAsync(query, token);

            if (list == null)
            {
                return new MoeItems {
                           Message = "获取Json失败"
                }
            }
            ;
            var          imgs  = new MoeItems();
            const string https = "https:";

            foreach (var item in list)
            {
                var img = new MoeItem(this, para);

                img.Width     = $"{item.width}".ToInt();
                img.Height    = $"{item.height}".ToInt();
                img.Id        = $"{item.id}".ToInt();
                img.Score     = $"{item.fav_count}".ToInt();
                img.Uploader  = $"{item.uploader_name}";
                img.DetailUrl = $"{HomeUrl}/post/show/{img.Id}";
                img.Date      = $"{item.created_at?.s}".ToDateTime();
                foreach (var tag in Extend.GetList(item.tags))
                {
                    img.Tags.Add($"{tag.name}");
                }
                img.IsExplicit = $"{item.rating}" == "e";
                img.Net        = Net.CloneWithOldCookie();
                img.Urls.Add(1, $"{https}{item.preview_url}", img.DetailUrl);
                img.Urls.Add(2, $"{https}{item.sample_url}", img.DetailUrl);
                img.Urls.Add(4, $"{https}{item.file_url}", img.DetailUrl);
                img.OriginString = $"{item}";
                imgs.Add(img);
            }

            return(imgs);
        }
コード例 #7
0
        public override async Task <MoeItems> GetRealPageImagesAsync(SearchPara para, CancellationToken token)
        {
            var          imgs = new MoeItems();
            const string api  = "https://capi-v2.sankakucomplex.com";
            const string beta = "https://beta.sankakucomplex.com";

            Net = Net == null ? new NetDocker(Settings, api) : Net.CloneWithOldCookie();

            Net.SetReferer(beta);
            var pairs = new Pairs
            {
                { "lang", "en" },
                { "page", $"{para.PageIndex}" },
                { "limit", $"{para.Count}" },
                { "hide_posts_in_books", "in-larger-tags" },
                { "default_threshold", "1" },
                { "tags", para.Keyword.ToEncodedUrl() }
            };
            var json = await Net.GetJsonAsync($"{api}/posts", token, pairs);

            foreach (var jitem in Extend.CheckListNull(json))
            {
                var img = new MoeItem(this, para)
                {
                    Net    = Net.CloneWithOldCookie(),
                    Id     = $"{jitem.id}".ToInt(),
                    Width  = $"{jitem.width}".ToInt(),
                    Height = $"{jitem.height}".ToInt(),
                    Score  = $"{jitem.total_score}".ToInt()
                };
                img.Urls.Add(1, $"{jitem.preview_url}", beta);
                img.Urls.Add(2, $"{jitem.sample_url}", beta);
                img.Urls.Add(4, $"{jitem.file_url}", $"{beta}/post/show/{img.Id}");
                img.IsExplicit = $"{jitem.rating}" != "s";
                img.Date       = $"{jitem.created_at?.s}".ToDateTime();
                img.Uploader   = $"{jitem.author?.name}";
                img.DetailUrl  = $"{beta}/post/show/{img.Id}";
                foreach (var tag in Extend.CheckListNull(jitem.tags))
                {
                    img.Tags.Add($"{tag.name_en}");
                }

                img.OriginString = $"{jitem}";
                imgs.Add(img);
            }

            return(imgs);
        }
コード例 #8
0
        public override async Task <MoeItems> GetRealPageImagesAsync(SearchPara para, CancellationToken token)
        {
            var pairs = new Pairs
            {
                { "page", $"{para.PageIndex}" },
                { "limit", $"{para.Count}" },
                { "tags", para.Keyword.ToEncodedUrl() }
            };
            var query = $"{HomeUrl}/post.json{pairs.ToPairsString()}";
            var net   = new NetOperator(Settings);
            var json  = await net.GetJsonAsync(query, token);

            var imageItems = new MoeItems();

            foreach (var item in Extend.GetList(json))
            {
                var img = new MoeItem(this, para);
                img.Width      = $"{item.width}".ToInt();
                img.Height     = $"{item.height}".ToInt();
                img.Id         = $"{item.id}".ToInt();
                img.Score      = $"{item.score}".ToInt();
                img.Uploader   = $"{item.author}";
                img.UploaderId = $"{item.creator_id}";
                foreach (var tag in $"{item.tags}".Split(' ').SkipWhile(string.IsNullOrWhiteSpace))
                {
                    img.Tags.Add(tag.Trim());
                }

                img.IsExplicit = $"{item.rating}" == "e";
                img.DetailUrl  = $"{HomeUrl}/post/show/{img.Id}";
                img.Date       = $"{item.created_at}".ToDateTime();
                if (img.Date == null)
                {
                    img.DateString = $"{item.created_at}";
                }
                img.Urls.Add(1, $"{item.preview_url}");
                img.Urls.Add(2, $"{item.sample_url}");
                img.Urls.Add(4, $"{item.file_url}", img.DetailUrl);
                img.Source       = $"{item.source}";
                img.OriginString = $"{item}";
                imageItems.Add(img);
            }

            return(imageItems);
        }
コード例 #9
0
ファイル: BilibiliSite.cs プロジェクト: xplusky/MoeLoaderP
    public async Task SearchByKeyword(SearchPara para, MoeItems imgs, CancellationToken token)
    {
        const string api              = "https://api.bilibili.com/x/web-interface/search/type";
        var          newOrHotOrder    = para.Lv3MenuIndex == 0 ? "pubdate" : "stow";
        var          drawOrPhotoCatId = para.Lv2MenuIndex == 0 ? "1" : "2";
        var          pairs            = new Pairs
        {
            { "search_type", "photo" },
            { "page", $"{para.PageIndex}" },
            { "order", newOrHotOrder },
            { "keyword", para.Keyword.ToEncodedUrl() },
            { "category_id", drawOrPhotoCatId }
        };
        var net  = new NetOperator(Settings, this);
        var json = await net.GetJsonAsync(api, pairs, token : token);

        if (json == null)
        {
            return;
        }
        foreach (var item in Ex.GetList(json.data?.result))
        {
            var img = new MoeItem(this, para);
            img.Urls.Add(1, $"{item.cover}@336w_336h_1e_1c.jpg");
            img.Urls.Add(2, $"{item.cover}@1024w_768h.jpg");
            img.Urls.Add(4, $"{item.cover}");
            img.Id                = $"{item.id}".ToInt();
            img.Score             = $"{item.like}".ToInt();
            img.Rank              = $"{item.rank_offset}".ToInt();
            img.Title             = $"{item.title}";
            img.Uploader          = $"{item.uname}";
            img.GetDetailTaskFunc = async cancellationToken =>
                                    await GetSearchByKeywordDetailTask(img, para, cancellationToken);

            img.DetailUrl    = $"https://h.bilibili.com/{img.Id}";
            img.OriginString = $"{item}";
            imgs.Add(img);
        }

        var c = $"{json.data?.numResults}".ToInt();

        Ex.ShowMessage($"共搜索到{c}张,已加载至{para.PageIndex}页,共{c / para.CountLimit}页", null, Ex.MessagePos.InfoBar);
    }
コード例 #10
0
        public override async Task <MoeItems> GetRealPageImagesAsync(SearchPara para, CancellationToken token)
        {
            if (Net == null)
            {
                Net = new NetOperator(Settings, HomeUrl);
            }
            const string api   = "https://api.yuriimg.com/posts";
            var          pairs = new Pairs
            {
                { "page", $"{para.PageIndex}" },
                { "tags", para.Keyword.ToEncodedUrl() }
            };
            var json = await Net.GetJsonAsync(api, token, pairs);

            if (json?.posts == null)
            {
                return(null);
            }
            var imgs = new MoeItems();

            foreach (var post in json.posts)
            {
                var img = new MoeItem(this, para);
                img.IsExplicit = $"{post.rating}" == "e";
                if (CurrentSiteSetting.LoginCookie.IsEmpty() && img.IsExplicit)
                {
                    continue;
                }
                img.Id     = $"{post.pid}".ToInt();
                img.Sid    = $"{post.id}";
                img.Width  = $"{post.width}".ToInt();
                img.Height = $"{post.height}".ToInt();
                img.Urls.Add(1, $"https://i.yuriimg.com/{post.src}/yuriimg.com%20{post.id}%20contain.jpg");
                img.DetailUrl         = $"{HomeUrl}/show/{post.id}";
                img.GetDetailTaskFunc = async() => await GetDetailTask(img, $"{post.id}", token);

                img.OriginString = $"{post}";

                imgs.Add(img);
            }

            return(imgs);
        }
コード例 #11
0
 public void AddImages(MoeItems imgs)
 {
     foreach (var img in imgs)
     {
         var itemCtrl = new ImageControl(Settings, img);
         itemCtrl.DownloadButton.Click    += (sender, args) => { ImageItemDownloadButtonClicked?.Invoke(itemCtrl.ImageItem, itemCtrl.PreviewImage.Source); };
         itemCtrl.PreviewButton.Click     += (sender, args) => { MoeItemPreviewButtonClicked?.Invoke(itemCtrl.ImageItem, itemCtrl.PreviewImage.Source); };
         itemCtrl.MouseEnter              += (sender, args) => MouseOnImageControl = itemCtrl;
         itemCtrl.ImageCheckBox.Checked   += (sender, args) => SelectedImageControls.Add(itemCtrl);
         itemCtrl.ImageCheckBox.Unchecked += (sender, args) => SelectedImageControls.Remove(itemCtrl);
         ImageItemsWrapPanel.Children.Add(itemCtrl);
         itemCtrl.Sb("ShowSb").Begin();
         if (ImageLoadingPool.Count < Settings.MaxOnLoadingImageCount)
         {
             ImageLoadingPool.Add(itemCtrl);
         }
         else
         {
             ImageWaitForLoadingPool.Add(itemCtrl);
         }
         itemCtrl.MouseRightButtonUp += ItemCtrlOnMouseRightButtonUp;
     }
 }
コード例 #12
0
        public override async Task <MoeItems> GetRealPageImagesAsync(SearchPara para, CancellationToken token)
        {
            var          imgs = new MoeItems();
            const string api  = "https://capi-v2.sankakucomplex.com";
            const string beta = "https://beta.sankakucomplex.com";

            if (Net == null)
            {
                Net = new NetOperator(Settings, api);
                var cc = GetCookies();

                if (cc != null)
                {
                    Net.SetCookie(cc);
                }
            }
            else
            {
                Net.CloneWithOldCookie();
            }

            Net.SetReferer(beta);
            var pairs = new Pairs
            {
                { "lang", "en" },
                { "next", $"{para.NextPagePara}" },
                { "limit", $"{para.Count}" },
                { "hide_posts_in_books", "in-larger-tags" },
                { "default_threshold", "1" },
                { "tags", para.Keyword.ToEncodedUrl() }
            };
            var json = await Net.GetJsonAsync($"{api}/posts/keyset", token, pairs);

            para.NextPagePara = $"{json.meta.next}";
            foreach (var jitem in Extend.GetList(json.data))
            {
                var img = new MoeItem(this, para)
                {
                    Net    = Net.CloneWithOldCookie(),
                    Id     = $"{jitem.id}".ToInt(),
                    Width  = $"{jitem.width}".ToInt(),
                    Height = $"{jitem.height}".ToInt(),
                    Score  = $"{jitem.total_score}".ToInt()
                };
                img.Urls.Add(1, $"{jitem.preview_url}", beta);
                img.Urls.Add(2, $"{jitem.sample_url}", beta);
                img.Urls.Add(4, $"{jitem.file_url}", $"{beta}/post/show/{img.Id}");
                img.IsExplicit = $"{jitem.rating}" != "s";
                img.Date       = $"{jitem.created_at?.s}".ToDateTime();
                img.Uploader   = $"{jitem.author?.name}";
                img.DetailUrl  = $"{beta}/post/show/{img.Id}";
                if ($"{jitem.redirect_to_signup}".ToLower() == "true")
                {
                    img.Tip = "此图片需要登录查看";
                }
                foreach (var tag in Extend.GetList(jitem.tags))
                {
                    img.Tags.Add($"{tag.name_en}");
                }

                img.OriginString = $"{jitem}";
                imgs.Add(img);
            }

            return(imgs);
        }
コード例 #13
0
        public override async Task <MoeItems> GetRealPageImagesAsync(SearchPara para, CancellationToken token)
        {
            if (Net == null)
            {
                Net = new NetOperator(Settings);
                Net.SetReferer(HomeUrl);
                await Net.Client.GetAsync(HomeUrl, token);
            }
            var size = "";

            if (para.IsFilterResolution)
            {
                var s = para.MinWidth > para.MinHeight ? para.MinWidth : para.MinHeight;
                size = $"{s}";
            }
            var orient = "";

            switch (para.Orientation)
            {
            case ImageOrientation.Portrait:
                orient = "p";
                break;

            case ImageOrientation.Landscape:
                orient = "l";
                break;
            }
            var pair = new Pairs
            {
                { "tags", para.Keyword.ToEncodedUrl() },
                { "size", size },
                { "orient", orient },
                { "page", $"{para.PageIndex}" }
            };
            var imageItems = new MoeItems();
            var json       = await Net.GetJsonAsync($"{HomeUrl}/index.json", token, pair);

            if (json?.images == null)
            {
                return(imageItems);
            }
            foreach (var image in json.images)
            {
                var img = new MoeItem(this, para);
                var id  = (int)image.id;
                img.Id = id;
                var sub = $"https://{id % 10}.s.kawaiinyan.com/i";
                img.Uploader = $"{image.user_name}";
                img.Source   = $"{image.adv_link}";
                img.Score    = (int)image.yes;
                var tags = $"{image.tags}";
                foreach (var s in tags.Split(','))
                {
                    if (s.IsEmpty())
                    {
                        continue;
                    }
                    img.Tags.Add(s);
                }
                var small = $"{image.small}";
                img.Urls.Add(1, $"{sub}{UrlInner($"{id}")}/small.{small}");
                var orig = $"{image.orig}";
                var big  = $"{image.big}";
                if (!orig.IsEmpty())
                {
                    img.Urls.Add(4, $"{sub}{UrlInner($"{id}")}/orig.{orig}");
                }
                else if (!big.IsEmpty())
                {
                    img.Urls.Add(4, $"{sub}{UrlInner($"{id}")}/big.{big}");
                }
                img.DetailUrl = $"{HomeUrl}/image?id={id}";

                img.Site         = this;
                img.OriginString = $"{image}";

                imageItems.Add(img);
            }
            token.ThrowIfCancellationRequested();
            return(imageItems);
        }
コード例 #14
0
ファイル: SearchSession.cs プロジェクト: fengdix4/MoeLoaderP
        /// <summary>
        /// 搜索下一页
        /// </summary>
        public async Task SearchNextPageAsync(CancellationToken token)
        {
            var        newVPage = new SearchedPage(); // 建立虚拟页信息
            var        images   = new MoeItems();
            SearchPara tempPara;

            if (LoadedPages.Count == 0)
            {
                tempPara = CurrentSearchPara.Clone(); // 浅复制一份参数
                newVPage.LastRealPageIndex = tempPara.PageIndex;
                // 搜索起始页的所有图片(若网站查询参数有支持的条件过滤,则在搜索时就已自动过滤相关条件)
                var sb = new StringBuilder();
                sb.AppendLine($"正在搜索站点 {tempPara.Site.DisplayName} 第 {tempPara.PageIndex} 页图片");
                sb.Append($"(参数:kw:{(!tempPara.Keyword.IsEmpty() ? tempPara.Keyword : "N/A")},num:{tempPara.Count})");
                Extend.ShowMessage(sb.ToString(), null, Extend.MessagePos.Searching);
                var imagesOrg = await tempPara.Site.GetRealPageImagesAsync(tempPara, token);

                if (imagesOrg == null || imagesOrg.Count == 0)
                {
                    Extend.ShowMessage("无搜索结果", null, Extend.MessagePos.Searching);
                    return;
                }
                for (var i = 0; i < imagesOrg.Count; i++)
                {
                    var item = imagesOrg[i];
                    if (i < tempPara.Count)
                    {
                        images.Add(item);
                    }
                    else
                    {
                        newVPage.PreLoadNextPageItems.Add(item);
                        if (!newVPage.HasNextPage)
                        {
                            newVPage.HasNextPage = true;
                        }
                    }
                }
            }
            else if (!LoadedPages.Last().HasNextPage) // 若无下一页则返回
            {
                return;
            }
            else
            {
                tempPara           = CurrentSearchPara.Clone(); // 浅复制一份参数
                tempPara.PageIndex = LoadedPages.Last().LastRealPageIndex;

                // 若不是第一页则使用上一页搜索多出来的图片作为本页基数
                images = new MoeItems();
                for (var i = 0; i < LoadedPages.Last().PreLoadNextPageItems.Count; i++)
                {
                    var item = LoadedPages.Last().PreLoadNextPageItems[i];
                    if (i < tempPara.Count)
                    {
                        images.Add(item);
                    }
                    else
                    {
                        newVPage.PreLoadNextPageItems.Add(item);
                        newVPage.HasNextPage = true;
                    }
                }
            }

            Filter(images); // 本地过滤,images数量有可能减少

            // 进入 loop 循环
            var startTime = DateTime.Now;

            while (images.Count < tempPara.Count)                             // 当images数量不够搜索参数数量时循环
            {
                token.ThrowIfCancellationRequested();                         // 整体Task的取消Token,取消时会抛出异常
                tempPara.PageIndex++;                                         // 设置新搜索参数为下一页(真)
                tempPara.LastId            = images.LastOrDefault()?.Id ?? 0; // 设置新搜索参数为最后ID(真)
                newVPage.LastRealPageIndex = tempPara.PageIndex;
                var sb = new StringBuilder();
                sb.AppendLine($"正在搜索站点 {tempPara.Site.DisplayName} 第 {tempPara.PageIndex} 页图片");
                sb.AppendLine($"已获取第{tempPara.PageIndex - 1}页{images.Count}张图片,还需{tempPara.Count - images.Count}张");
                sb.Append($"(参数:kw:{(!tempPara.Keyword.IsEmpty() ? tempPara.Keyword : "N/A")},num:{tempPara.Count})");
                Extend.ShowMessage(sb.ToString(), null, Extend.MessagePos.Searching);
                var imagesNextRPage = await tempPara.Site.GetRealPageImagesAsync(tempPara, token); // 搜索下一页(真)的所有图片

                if (imagesNextRPage == null || imagesNextRPage.Count == 0)                         // 当下一页(真)的搜索到的未进行本地过滤图片数量为0时,表示已经搜索完了
                {
                    newVPage.HasNextPage       = false;                                            // 没有下一页
                    newVPage.LastRealPageIndex = tempPara.PageIndex;
                    break;
                }
                else // 当下一页(真)未过滤图片数量不为0时
                {
                    Filter(imagesNextRPage); // 本地过滤下一页(真)

                    foreach (var item in imagesNextRPage)
                    {
                        if (images.Count < tempPara.Count)
                        {
                            images.Add(item);                                // 添加图片数量直到够参数设定的图片数量为止
                        }
                        else
                        {
                            newVPage.PreLoadNextPageItems.Add(item);  // 多出来的图片存在另一个对象中,下一虚拟页可以调用
                        }
                    }
                    if (images.Count >= tempPara.Count)
                    {
                        break;                                 // 数量已够参数数量,当前虚拟页完成任务
                    }
                }
                if (DateTime.Now - startTime > TimeSpan.FromSeconds(30))
                {
                    break;                                                      // loop超时跳出循环(即使不够数量也跳出)
                }
            }
            token.ThrowIfCancellationRequested();
            // Load end
            newVPage.ImageItems = images;
            LoadedPages.Add(newVPage);
            if (images.Message != null)
            {
                Extend.ShowMessage(images.Message);
            }
            if (images.Ex != null)
            {
                Extend.ShowMessage(images.Ex.Message, images.Ex.ToString(), Extend.MessagePos.Window);
            }
            Extend.ShowMessage("搜索完毕", null, Extend.MessagePos.Searching);
        }
コード例 #15
0
ファイル: SearchSession.cs プロジェクト: fengdix4/MoeLoaderP
        /// <summary>
        /// 本地过滤图片
        /// </summary>
        public void Filter(MoeItems items)
        {
            if (items == null)
            {
                return;
            }
            var para = CurrentSearchPara;

            for (var i = 0; i < items.Count; i++)
            {
                var del   = false;
                var item  = items[i];
                var state = item.Site.SupportState;
                if (state.IsSupportRating) // 过滤r18评级图片
                {
                    if ((!Settings.IsXMode || !para.IsShowExplicit) && item.IsExplicit)
                    {
                        del = true;
                    }
                    if (Settings.IsXMode && para.IsShowExplicitOnly && item.IsExplicit == false)
                    {
                        del = true;
                    }
                }
                if (state.IsSupportResolution && para.IsFilterResolution) // 过滤分辨率
                {
                    if (item.Width < para.MinWidth || item.Height < para.MinHeight)
                    {
                        del = true;
                    }
                }
                if (state.IsSupportResolution) // 过滤图片方向
                {
                    switch (para.Orientation)
                    {
                    case ImageOrientation.Landscape:
                        if (item.Height >= item.Width)
                        {
                            del = true;
                        }
                        break;

                    case ImageOrientation.Portrait:
                        if (item.Height <= item.Width)
                        {
                            del = true;
                        }
                        break;
                    }
                }
                if (para.IsFilterFileType) // 过滤图片扩展名
                {
                    foreach (var s in para.FilterFileTypeText.Split(';'))
                    {
                        if (s.IsEmpty())
                        {
                            continue;
                        }
                        if (string.Equals(item.FileType, s, StringComparison.CurrentCultureIgnoreCase))
                        {
                            if (!para.IsFileTypeShowSpecificOnly)
                            {
                                del = true;
                            }
                        }
                        else if (para.IsFileTypeShowSpecificOnly)
                        {
                            del = true;
                        }
                    }
                }

                if (!del)
                {
                    continue;
                }
                items.RemoveAt(i);
                i--;
            }
        }
コード例 #16
0
        public override async Task <MoeItems> GetRealPageImagesAsync(SearchPara para, CancellationToken token)
        {
            Net = Net == null ? new NetOperator(Settings, HomeUrl) : Net.CloneWithOldCookie();

            if (!IsLogin)
            {
                Extend.ShowMessage("MiniTokyo 正在自动登录中……", null, Extend.MessagePos.Searching);
                var accIndex = new Random().Next(0, _user.Length);
                var content  = new FormUrlEncodedContent(new Pairs
                {
                    { "username", _user[accIndex] },
                    { "password", _pass[accIndex] }
                });
                var p = await Net.Client.PostAsync("http://my.minitokyo.net/login", content, token);

                if (p.IsSuccessStatusCode)
                {
                    IsLogin = true;
                }
            }

            var    imgs = new MoeItems();
            string query;

            if (para.Keyword.IsEmpty()) // by new
            {
                // recent:
                // wall http://gallery.minitokyo.net/wallpapers?display=thumbnails&order=id&page=2
                // mobile http://gallery.minitokyo.net/mobile?order=id&display=thumbnails&page=2
                // indy http://gallery.minitokyo.net/indy-art?order=id&display=thumbnails&page=2
                // scan  http://gallery.minitokyo.net/scans?order=id&display=thumbnails&page=2

                // popular
                // wall http://gallery.minitokyo.net/wallpapers?order=favorites&display=thumbnails&page=2
                // scan http://gallery.minitokyo.net/scans?display=thumbnails&order=favorites&page=2
                query = $"{HomeGalleryUrl}/{GetSort(para)}?order={GetOrder(para)}&display=thumbnails&page={para.PageIndex}";
            }
            else
            {
                var q   = $"{HomeUrl}/search?q={para.Keyword}";
                var net = Net.CloneWithOldCookie();
                net.SetReferer(HomeUrl);
                net.HttpClientHandler.AllowAutoRedirect = false;
                var res = await net.Client.GetAsync(q, token);

                var loc303 = res.Headers.Location.OriginalString;
                var net2   = Net.CloneWithOldCookie();
                var doc1   = await net2.GetHtmlAsync($"{HomeUrl}{loc303}", token);

                var tabnodes = doc1.DocumentNode.SelectNodes("*//ul[@id='tabs']//a");
                var url      = tabnodes[1].Attributes["href"]?.Value;
                var reg      = new Regex(@"(?:^|\?|&)tid=(\d*)(?:&|$)");
                var tid      = reg.Match(url ?? "").Groups[0].Value;
                var indexs   = new [] { 1, 3, 1, 2 };
                query = $"{HomeBrowseUrl}/gallery{tid}index={indexs[para.SubMenuIndex]}&order={GetOrder(para)}&display=thumbnails";
            }

            var doc = await Net.GetHtmlAsync(query, token);

            var docnode = doc.DocumentNode;
            var empty   = docnode.SelectSingleNode("*//p[@class='empty']")?.InnerText.ToLower().Trim();

            if (empty == "no items to display")
            {
                return(imgs);
            }
            var wallNode = docnode.SelectSingleNode("*//ul[@class='scans']");
            var imgNodes = wallNode.SelectNodes(".//li");

            if (imgNodes == null)
            {
                return(imgs);
            }

            foreach (var node in imgNodes)
            {
                var img       = new MoeItem(this, para);
                var detailUrl = node.SelectSingleNode("a").Attributes["href"].Value;
                img.DetailUrl = detailUrl;
                img.Id        = detailUrl.Substring(detailUrl.LastIndexOf('/') + 1).ToInt();
                var imgHref   = node.SelectSingleNode(".//img");
                var sampleUrl = imgHref.Attributes["src"].Value;
                img.Urls.Add(1, sampleUrl, HomeUrl);
                //http://static2.minitokyo.net/thumbs/24/25/583774.jpg preview
                //http://static2.minitokyo.net/view/24/25/583774.jpg   sample
                //http://static.minitokyo.net/downloads/24/25/583774.jpg   full
                const string api2       = "http://static2.minitokyo.net";
                const string api        = "http://static.minitokyo.net";
                var          previewUrl = $"{api2}/view{sampleUrl.Substring(sampleUrl.IndexOf('/', sampleUrl.IndexOf(".net/", StringComparison.Ordinal) + 5))}";
                var          fileUrl    = $"{api}/downloads{previewUrl.Substring(previewUrl.IndexOf('/', previewUrl.IndexOf(".net/", StringComparison.Ordinal) + 5))}";
                img.Urls.Add(4, fileUrl, HomeUrl);
                img.Title    = node.SelectSingleNode("./p/a").InnerText.Trim();
                img.Uploader = node.SelectSingleNode("./p").InnerText.Delete("by ").Trim();
                var res  = node.SelectSingleNode("./a/img").Attributes["title"].Value;
                var resi = res?.Split('x');
                if (resi?.Length == 2)
                {
                    img.Width  = resi[0].ToInt();
                    img.Height = resi[1].ToInt();
                }
                img.OriginString = node.OuterHtml;
                imgs.Add(img);
            }
            token.ThrowIfCancellationRequested();
            return(imgs);
        }
コード例 #17
0
ファイル: PixivSite.cs プロジェクト: N0best1rn/MoeLoaderP
        public async Task SearchByRank(MoeItems imgs, SearchPara para, CancellationToken token)
        {
            var modesR18 = new[] { "daily", "weekly", "male", "female" };
            var modes    = new[] { "daily", "weekly", "monthly", "rookie,", "original", "male", "female" };
            var mode     = IsR18 ? modesR18[para.Lv3MenuIndex] : modes[para.Lv3MenuIndex];

            if (IsR18)
            {
                mode += "_r18";
            }
            var contents = new[] { "all", "illust", "manga", "ugoira" };
            var content  = contents[para.Lv4MenuIndex];
            var referer  = $"{HomeUrl}/ranking.php?mode={mode}&content={content}";

            Net.SetReferer(referer);
            var q    = $"{HomeUrl}/ranking.php";
            var pair = new Pairs
            {
                { "mode", mode },
                { "content", content },
                { "date", para.Date == null ? "" : $"{para.Date:yyyyMMdd}" },
                { "p", $"{para.PageIndex}" },
                { "format", "json" }
            };
            var json = await Net.GetJsonAsync(q, token, pair);

            foreach (var illus in Extend.GetList(json?.contents))
            {
                var img = new MoeItem(this, para)
                {
                    Net = Net.CloneWithOldCookie(),
                    Id  = $"{illus.illust_id}".ToInt()
                };
                img.Urls.Add(1, $"{illus.url}", referer);
                img.Title       = $"{illus.title}";
                img.Uploader    = $"{illus.user_name}";
                img.UploaderId  = $"{illus.user_id}";
                img.Width       = $"{illus.width}".ToInt();
                img.Height      = $"{illus.height}".ToInt();
                img.DetailUrl   = $"{HomeUrl}/artworks/{img.Id}";
                img.ImagesCount = $"{illus.illust_page_count}".ToInt();
                img.Score       = $"{illus.rating_count}".ToInt();
                img.Rank        = $"{illus.rank}".ToInt();
                if (img.Rank > 0)
                {
                    var yes = $"{illus.yes_rank}".ToInt();
                    img.Tip = yes == 0 ? "首次登场" : $"之前#{yes}";
                    if (yes == 0)
                    {
                        img.TipHighLight = true;
                    }
                }
                foreach (var tag in Extend.GetList(illus.tags))
                {
                    img.Tags.Add($"{tag}");
                }

                img.Date = GetDateFromUrl($"{illus.url}");
                if ($"{illus.illust_type}" == "2")
                {
                    img.GetDetailTaskFunc = async() => await GetUgoiraDetailPageTask(img);
                }
                else
                {
                    img.GetDetailTaskFunc = async() => await GetDetailPageTask(img, para);
                }

                img.OriginString = $"{illus}";
                imgs.Add(img);
            }

            var count = $"{json?.rank_total}".ToInt();

            Extend.ShowMessage($"共{count}张,当前日期:{json?.date}", null, Extend.MessagePos.InfoBar);
        }
コード例 #18
0
ファイル: PixivSite.cs プロジェクト: N0best1rn/MoeLoaderP
        public async Task SearchByNewOrTag(MoeItems imgs, SearchPara para, CancellationToken token)
        {
            string referer, api; Pairs pairs;
            var    isIllust = para.Lv3MenuIndex == 0;

            if (para.Keyword.IsEmpty()) // new
            {
                api     = $"{HomeUrl}/ajax/illust/new";
                referer = isIllust ? $"{HomeUrl}/new_illust.php" : $"{HomeUrl}/new_illust.php?type=manga";
                pairs   = new Pairs
                {
                    { "lastId", para.LastId == 0 ? "" : $"{para.LastId}" },
                    { "limit", $"{para.Count}" },
                    { "type", isIllust ? "illust" : "manga" },
                    { "r18", R18Query }
                };
            }
            else // tag
            {
                api     = $"{HomeUrl}/ajax/search/{(isIllust ? "illustrations" : "manga")}/{para.Keyword.ToEncodedUrl()}";
                referer = $"{HomeUrl}tags/{para.Keyword.ToEncodedUrl()}/{(isIllust ? "illustrations" : "manga")}?mode={R18ModeQuery}&s_mode=s_tag";
                pairs   = new Pairs
                {
                    { "word", para.Keyword.ToEncodedUrl() },
                    { "order", "date" },
                    { "mode", R18ModeQuery },
                    { "p", $"{para.PageIndex}" },
                    { "s_mode", "s_tag" },
                    { "type", isIllust ? "illust_and_ugoira" : "manga" }
                };
            }

            Net.SetReferer(referer);
            var json = await Net.GetJsonAsync(api, token, pairs);

            var list = para.Keyword.IsEmpty()
                ? (json?.body?.illusts)
                : (isIllust ? (json?.body?.illust?.data) : (json?.body?.manga?.data));

            foreach (var illus in Extend.GetList(list))
            {
                var img = new MoeItem(this, para);
                img.Site = this;
                img.Net  = Net.CloneWithOldCookie();
                img.Id   = $"{illus.id}".ToInt();
                img.Urls.Add(new UrlInfo(1, $"{illus.url}", $"{HomeUrl}/new_illust.php"));
                img.Title       = $"{illus.title}";
                img.Uploader    = $"{illus.userName}";
                img.UploaderId  = $"{illus.userId}";
                img.Width       = $"{illus.width}".ToInt();
                img.Height      = $"{illus.height}".ToInt();
                img.DetailUrl   = $"{HomeUrl}/artworks/{img.Id}";
                img.ImagesCount = $"{illus.pageCount}".ToInt();
                foreach (var tag in Extend.GetList(illus.tags))
                {
                    img.Tags.Add($"{tag}");
                }
                img.Date = GetDateFromUrl($"{illus.url}");
                if ($"{illus.illustType}" == "2")
                {
                    img.GetDetailTaskFunc = async() => await GetUgoiraDetailPageTask(img);
                }
                else
                {
                    img.GetDetailTaskFunc = async() => await GetDetailPageTask(img, para);
                }
                img.OriginString = $"{illus}";
                imgs.Add(img);
            }
            if (!para.Keyword.IsEmpty() && json != null)
            {
                var count = $"{json?.body?.illust?.total}".ToInt();
                Extend.ShowMessage($"共搜索到{count}张图片,当前已加载至第{para.PageIndex}页,共{count / 60}页", null, Extend.MessagePos.InfoBar);
            }
        }
コード例 #19
0
ファイル: WCosplaySite.cs プロジェクト: fengdix4/MoeLoaderP
        public override async Task <MoeItems> GetRealPageImagesAsync(SearchPara para, CancellationToken token)
        {
            if (Net == null)
            {
                Net = new NetDocker();
            }

            //http://worldcosplay.net/api/photo/list?page=3&limit=2&sort=created_at&direction=descend
            var url   = $"{HomeUrl}/api/photo/list";
            var pairs = new Pairs
            {
                { "page", $"{para.PageIndex}" },
                { "limit", $"{para.Count}" },
                { "sort", "created_at" },
                { "direction", "descend" }
            };

            if (!para.Keyword.IsEmpty())
            {
                //http://worldcosplay.net/api/photo/search?page=2&rows=48&q=%E5%90%8A%E5%B8%A6%E8%A2%9C%E5%A4%A9%E4%BD%BF
                url   = $"{HomeUrl}/api/photo/search";
                pairs = new Pairs
                {
                    { "page", $"{para.PageIndex}" },
                    { "rows", $"{para.Count}" },
                    { "q", para.Keyword.ToEncodedUrl() }
                };
            }

            // images

            var imgs = new MoeItems();
            var json = await Net.GetJsonAsync(url, token, pairs);

            if (json?.list == null)
            {
                return(imgs);
            }
            foreach (var jitem in json.list)
            {
                var img = new MoeItem(this, para)
                {
                    Uploader  = $"{jitem.member?.nickname}",
                    DetailUrl = $"{HomeUrl}{jitem.photo?.url}",
                    Id        = (int)(jitem.photo?.id ?? 0d)
                };
                img.Urls.Add(1, $"{jitem.photo?.thumbnail_url_display}", HomeUrl);
                img.Urls.Add(3, $"{jitem.photo?.large_url}", img.DetailUrl);
                img.Score = $"{jitem.photo?.good_cnt}".ToInt();
                img.Date  = $"{jitem.photo?.created_at}".ToDateTime();
                var twidth  = (int)(jitem.photo?.thumbnail_width ?? 0d);
                var theight = (int)(jitem.photo?.thumbnail_height ?? 0d);
                if (twidth > 0 && theight > 0) //缩略图的尺寸 175级别 大图 740级别
                {
                    if (twidth > theight)
                    {
                        img.Height = 740 * theight / twidth;
                        img.Width  = 740;
                    }
                    else
                    {
                        img.Width  = 740 * twidth / theight;
                        img.Height = 740;
                    }
                }
                img.Title        = $"{jitem.photo?.subject}";
                img.IsExplicit   = jitem.photo?.viewable ?? false;
                img.OriginString = $"{jitem}";
                imgs.Add(img);
            }

            return(imgs);
        }
コード例 #20
0
ファイル: PixivSite.cs プロジェクト: N0best1rn/MoeLoaderP
        public async Task SearchByAuthor(MoeItems imgs, string uid, SearchPara para, CancellationToken token)
        {
            var isIorM = para.Lv3MenuIndex == 0;
            var mi     = isIorM ? "illustrations" : "manga";
            var mi2    = isIorM ? "illusts" : "manga";
            var mi3    = isIorM ? "插画" : "漫画";

            Net.SetReferer($"{HomeUrl}/users/{uid}/{mi}");
            var allJson = await Net.GetJsonAsync($"{HomeUrl}/ajax/user/{uid}/profile/all", token);

            if ($"{allJson?.error}".ToLower() == "true")
            {
                Extend.ShowMessage($"搜索失败,网站信息:“{$"{allJson?.message}".ToDecodedUrl()}”", null, Extend.MessagePos.Window);
                return;
            }
            var picIds = new List <string>();
            var arts   = isIorM ? allJson?.body?.illusts : allJson?.body?.manga;

            foreach (var ill in Extend.GetList(arts))
            {
                picIds.Add((ill as JProperty)?.Name);
            }
            var picCurrentPage = picIds.OrderByDescending(i => i.ToInt()).Skip((para.PageIndex - 1) * para.Count).Take(para.Count).ToList();

            if (!picCurrentPage.Any())
            {
                return;
            }
            var pairs = new Pairs();

            foreach (var pic in picCurrentPage)
            {
                pairs.Add("ids[]".ToEncodedUrl(), pic);
            }
            pairs.Add("work_category", mi2);
            pairs.Add("is_first_page", "1");
            var picsJson = await Net.GetJsonAsync($"{HomeUrl}/ajax/user/{uid}/profile/illusts", token, pairs);

            var works = picsJson?.body?.works;

            foreach (var item in Extend.GetList(works))
            {
                dynamic illus = (item as JProperty)?.Value;
                if (illus == null)
                {
                    continue;
                }
                var img = new MoeItem(this, para);
                img.Urls.Add(1, $"{illus.url}", $"{HomeUrl}/users/{uid}/{mi}");
                img.Id              = $"{illus.id}".ToInt();
                img.Net             = Net.CloneWithOldCookie();
                img.Title           = $"{illus.title}";
                img.Uploader        = $"{illus.userName}";
                img.UploaderId      = $"{illus.userId}";
                img.UploaderHeadUrl = $"{illus.profileImageUrl}";
                img.Width           = $"{illus.width}".ToInt();
                img.Height          = $"{illus.height}".ToInt();
                img.DetailUrl       = $"{HomeUrl}/artworks/{img.Id}";
                img.ImagesCount     = $"{illus.pageCount}".ToInt();
                foreach (var tag in Extend.GetList(illus.tags))
                {
                    img.Tags.Add($"{tag}");
                }
                img.Date = GetDateFromUrl($"{illus.url}");
                if ($"{illus.illustType}" == "2")
                {
                    img.GetDetailTaskFunc = async() => await GetUgoiraDetailPageTask(img);
                }
                else
                {
                    img.GetDetailTaskFunc = async() => await GetDetailPageTask(img, para);
                }
                img.OriginString = $"{item}";

                imgs.Add(img);
            }
            Extend.ShowMessage($"该作者共有{mi3}{picIds.Count}张,当前第{para.Count * (para.PageIndex - 1) + 1}张", null, Extend.MessagePos.InfoBar);
        }
コード例 #21
0
ファイル: ZeroChanSite.cs プロジェクト: fengdix4/MoeLoaderP
        public override async Task <MoeItems> GetRealPageImagesAsync(SearchPara para, CancellationToken token)
        {
            // logon
            if (!IsLogon)
            {
                Login(token);
            }
            if (!IsLogon)
            {
                return(new MoeItems());
            }

            // get page source
            string pageString;
            var    url = $"{HomeUrl}{(para.Keyword.Length > 0 ? $"/search?q={para.Keyword}&" : "/?")}p={para.PageIndex}";

            if (!_beforeWord.Equals(para.Keyword, StringComparison.CurrentCultureIgnoreCase))
            {
                // 301
                var respose = await Net.Client.GetAsync(url, token);

                if (respose.IsSuccessStatusCode)
                {
                    _beforeUrl = respose.Headers.Location.AbsoluteUri;
                }
                else
                {
                    Extend.ShowMessage("搜索失败,请检查您输入的关键词");
                    return(new MoeItems());
                }

                pageString = await respose.Content.ReadAsStringAsync();

                _beforeWord = para.Keyword;
            }
            else
            {
                url = para.Keyword.IsEmpty() ? url : $"{_beforeUrl}?p={para.PageIndex}";
                var res = await Net.Client.GetAsync(url, token);

                pageString = await res.Content.ReadAsStringAsync();
            }

            // images
            var imgs = new MoeItems();
            var doc  = new HtmlDocument();

            doc.LoadHtml(pageString);
            HtmlNodeCollection nodes;

            try
            {
                nodes = doc.DocumentNode.SelectSingleNode("//ul[@id='thumbs2']").SelectNodes(".//li");
            }
            catch { return(new MoeItems {
                    Message = "没有搜索到图片"
                }); }

            foreach (var imgNode in nodes)
            {
                var img = new MoeItem(this, para);
                var mo  = imgNode.SelectSingleNode(".//b")?.InnerText?.Trim();
                if (mo?.ToLower().Trim().Contains("members only") == true)
                {
                    continue;
                }
                var strId = imgNode.SelectSingleNode("a").Attributes["href"].Value;
                var fav   = imgNode.SelectSingleNode("a/span")?.InnerText;
                if (!fav.IsEmpty())
                {
                    img.Score = Regex.Replace(fav, @"[^0-9]+", "")?.ToInt() ?? 0;
                }
                var imgHref    = imgNode.SelectSingleNode(".//img");
                var previewUrl = imgHref?.Attributes["src"]?.Value;
                //http://s3.zerochan.net/Morgiana.240.1355397.jpg   preview
                //http://s3.zerochan.net/Morgiana.600.1355397.jpg    sample
                //http://static.zerochan.net/Morgiana.full.1355397.jpg   full
                //先加前一个,再加后一个  范围都是00-49
                //string folder = (id % 2500 % 50).ToString("00") + "/" + (id % 2500 / 50).ToString("00");
                var sampleUrl = "";
                var fileUrl   = "";
                if (!previewUrl.IsEmpty())
                {
                    sampleUrl = previewUrl?.Replace("240", "600");
                    fileUrl   = Regex.Replace(previewUrl, "^(.+?)zerochan.net/", "https://static.zerochan.net/").Replace("240", "full");
                }

                var resAndFileSize = imgHref?.Attributes["title"]?.Value;
                if (!resAndFileSize.IsEmpty())
                {
                    foreach (var s in resAndFileSize.Split(' '))
                    {
                        if (!s.Contains("x"))
                        {
                            continue;
                        }
                        var res = s.Split('x');
                        if (res.Length != 2)
                        {
                            continue;
                        }
                        img.Width  = res[0].ToInt();
                        img.Height = res[1].ToInt();
                    }
                }

                var title = imgHref?.Attributes["alt"]?.Value;

                //convert relative url to absolute
                if (!fileUrl.IsEmpty() && fileUrl.StartsWith("/"))
                {
                    fileUrl = $"{HomeUrl}{fileUrl}";
                }
                if (sampleUrl != null && sampleUrl.StartsWith("/"))
                {
                    sampleUrl = HomeUrl + sampleUrl;
                }

                img.Description = title;
                img.Title       = title;
                img.Id          = strId.Substring(1).ToInt();

                img.Urls.Add(1, previewUrl, HomeUrl);
                img.Urls.Add(2, sampleUrl, HomeUrl);
                img.Urls.Add(4, fileUrl, img.DetailUrl);
                img.DetailUrl = $"{HomeUrl}/{img.Id}";

                img.OriginString = imgNode.OuterHtml;
                imgs.Add(img);
            }
            token.ThrowIfCancellationRequested();
            return(imgs);
        }
コード例 #22
0
ファイル: AnimePicsSite.cs プロジェクト: fengdix4/MoeLoaderP
        public override async Task <MoeItems> GetRealPageImagesAsync(SearchPara para, CancellationToken token)
        {
            if (!IsLogon)
            {
                await LoginAsync(token);
            }

            // pages source
            //http://mjv-art.org/pictures/view_posts/0?lang=en
            var url = $"{HomeUrl}/pictures/view_posts/{para.PageIndex - 1}?lang=en";

            if (para.Keyword.Length > 0)
            {
                //http://mjv-art.org/pictures/view_posts/0?search_tag=suzumiya%20haruhi&order_by=date&ldate=0&lang=en
                url = $"{HomeUrl}/pictures/view_posts/{para.PageIndex - 1}?search_tag={para.Keyword}&order_by=date&ldate=0&lang=en";
            }

            var imgs = new MoeItems();

            var doc = await Net.GetHtmlAsync(url, token);

            if (doc == null)
            {
                return(null);
            }
            var pre      = "https:";
            var listnode = doc.DocumentNode.SelectNodes("//*[@id='posts']/div[@class='posts_block']/span[@class='img_block_big']");

            if (listnode == null)
            {
                return new MoeItems {
                           Message = "读取HTML失败"
                }
            }
            ;
            foreach (var node in listnode)
            {
                var img = new MoeItem(this, para)
                {
                    Site = this
                };

                var imgnode = node.SelectSingleNode("a/picture/img");
                var idattr  = imgnode.GetAttributeValue("id", "0");
                var reg     = Regex.Replace(idattr, @"[^0-9]+", "");
                img.Id = reg.ToInt();
                var src = imgnode.GetAttributeValue("src", "");
                if (!src.IsEmpty())
                {
                    img.Urls.Add(new UrlInfo(1, $"{pre}{src}", url));
                }
                var resstrs = node.SelectSingleNode("div[@class='img_block_text']/a")?.InnerText.Trim().Split('x');
                if (resstrs?.Length == 2)
                {
                    img.Width  = resstrs[0].ToInt();
                    img.Height = resstrs[1].ToInt();
                }
                var scorestr = node.SelectSingleNode("div[@class='img_block_text']/span")?.InnerText.Trim();
                var match    = Regex.Replace(scorestr ?? "0", @"[^0-9]+", "");
                img.Score = match.ToInt();
                var detail = node.SelectSingleNode("a").GetAttributeValue("href", "");
                if (!detail.IsEmpty())
                {
                    img.DetailUrl         = $"{HomeUrl}{detail}";
                    img.GetDetailTaskFunc = async() => await GetDetailTask(img);
                }
                imgs.Add(img);
            }
            token.ThrowIfCancellationRequested();
            return(imgs);
        }
コード例 #23
0
ファイル: EshuuSite.cs プロジェクト: fengdix4/MoeLoaderP
        public override async Task <MoeItems> GetRealPageImagesAsync(SearchPara para, CancellationToken token)
        {
            var imgs = new MoeItems();
            var url  = $"{HomeUrl}/?page={para.PageIndex}";

            if (Net == null)
            {
                Net = new NetDocker(Settings);
            }
            if (!para.Keyword.IsEmpty())
            {
                url = $"{HomeUrl}/search/process/";
                var i  = para.SubMenuIndex;
                var kw = $"{$"\"{para.Keyword.Delete("\"")}\"".ToEncodedUrl()}+";
                //e-shuushuu需要将关键词转换为tag id,然后进行搜索
                var mc = new FormUrlEncodedContent(new Pairs
                {
                    { "tags", i == 0 ? kw : "" },
                    { "source", i == 1 ? kw : "" },
                    { "char", i == 3 ? kw : "" },
                    { "artist", i == 2 ? kw : "" },
                    { "postcontent", "" },
                    { "txtposter", "" }
                });
                var net = Net.CloneWithOldCookie();
                var r   = await net.Client.GetAsync(HomeUrl, token);

                if (r.IsSuccessStatusCode == false)
                {
                    return(imgs);
                }

                net = net.CloneWithOldCookie();
                net.SetReferer($"{HomeUrl}/search");
                net.HttpClientHandler.AllowAutoRedirect = false; //prevent 303
                var res = await net.Client.PostAsync(url, mc, token);

                var loc303 = res.Headers.Location?.OriginalString;     //todo 无法实现,需要大神

                //http://e-shuushuu.net/search/results/?tags=2
                if (!loc303.IsEmpty())
                {
                    url = $"{loc303}&page={para.PageIndex}";
                }
                else
                {
                    return new MoeItems {
                               Message = "没有搜索到关键词相关的图片"
                    }
                };
            }

            // images
            var doc = await Net.GetHtmlAsync(url, token);

            if (doc == null)
            {
                return new MoeItems
                       {
                           Message = "获取HTML失败"
                       }
            }
            ;
            var nodes = doc.DocumentNode.SelectNodes("//div[@class='image_thread display']");

            if (nodes == null)
            {
                return(imgs);
            }

            foreach (var imgNode in nodes)
            {
                var img = new MoeItem(this, para);
                var id  = imgNode.Attributes["id"]?.Value.Delete("i");
                img.Id = $"{id}".ToInt();
                var imgHref = imgNode.SelectSingleNode(".//a[@class='thumb_image']");
                var fileUrl = imgHref.Attributes["href"].Value;
                if (fileUrl.StartsWith("/"))
                {
                    fileUrl = $"{HomeUrl}{fileUrl}";
                }
                var previewUrl = imgHref.SelectSingleNode("img").Attributes["src"].Value;
                if (previewUrl.StartsWith("/"))
                {
                    previewUrl = $"{HomeUrl}{previewUrl}";
                }
                img.Urls.Add(1, previewUrl, HomeUrl);
                var meta = imgNode.SelectSingleNode(".//div[@class='meta']");
                img.Date = meta.SelectSingleNode(".//dd[2]").InnerText.ToDateTime();
                var dimension = meta.SelectSingleNode(".//dd[4]").InnerText;
                foreach (var s in dimension.Split(' '))
                {
                    if (!s.Contains("x"))
                    {
                        continue;
                    }
                    var res = s.Split('x');
                    if (res.Length != 2)
                    {
                        continue;
                    }
                    img.Width  = res[0].ToInt();
                    img.Height = res[1].ToInt();
                    break;
                }

                var tags = meta.SelectNodes(".//span[@class='tag']/a");
                if (tags != null)
                {
                    foreach (var tag in tags)
                    {
                        if (tag.InnerText.IsEmpty())
                        {
                            continue;
                        }
                        img.Tags.Add(tag.InnerText);
                    }
                    img.Uploader = tags.LastOrDefault()?.InnerText;
                }
                var detail = $"{HomeUrl}/image/{id}";
                img.DetailUrl = detail;
                img.Urls.Add(4, fileUrl, detail);
                img.OriginString = imgNode.OuterHtml;
                imgs.Add(img);
            }

            return(imgs);
        }
コード例 #24
0
        public async Task SearchByNewOrHot(SearchPara para, CancellationToken token, MoeItems imgs)
        {
            const string api   = "https://api.vc.bilibili.com/link_draw/v2";
            var          type  = para.Lv3MenuIndex == 0 ? "new" : "hot";
            var          count = para.Count > 20 ? 20 : para.Count;
            var          api2  = "";

            switch (para.SubMenuIndex)
            {
            case 0:
                api2 = $"{api}/Doc/list";
                break;

            case 1:
            case 2:
                api2 = $"{api}/Photo/list";
                break;
            }
            var net  = new NetDocker(Settings);
            var json = await net.GetJsonAsync(api2, token, new Pairs
            {
                { "category", para.SubMenuIndex == 0 ? "all" : (para.SubMenuIndex == 1 ? "cos" : "sifu") },
                { "type", type },
                { "page_num", $"{para.PageIndex - 1}" },
                { "page_size", $"{count}" }
            });


            foreach (var item in Extend.CheckListNull(json?.data?.items))
            {
                var cat = para.SubMenuIndex == 0 ? "/d" : "/p";
                var img = new MoeItem(this, para)
                {
                    Uploader = $"{item.user?.name}",
                    Id       = $"{item.item?.doc_id}".ToInt(),
                };
                img.DetailUrl = $"https://h.bilibili.com/{img.Id}";
                var i0 = item.item?.pictures[0];
                img.Width  = $"{i0?.img_width}".ToInt();
                img.Height = $"{i0?.img_height}".ToInt();
                img.Date   = $"{item.item?.upload_time}".ToDateTime();
                img.Urls.Add(1, $"{i0?.img_src}@336w_336h_1e_1c.jpg", HomeUrl + cat);
                img.Urls.Add(2, $"{i0?.img_src}@1024w_768h.jpg");
                img.Urls.Add(4, $"{i0?.img_src}");
                img.Title = $"{item.item?.title}";
                var list = item.item?.pictures as JArray;
                if (list?.Count > 1)
                {
                    foreach (var pic in item.item.pictures)
                    {
                        var child = new MoeItem(this, para);
                        child.Urls.Add(1, $"{pic.img_src}@336w_336h_1e_1c.jpg", HomeUrl + cat);
                        child.Urls.Add(2, $"{pic.img_src}@1024w_768h.jpg", HomeUrl + cat);
                        child.Urls.Add(4, $"{pic.img_src}");
                        child.Width  = $"{pic.img_width}".ToInt();
                        child.Height = $"{pic.img_height}".ToInt();
                        img.ChildrenItems.Add(child);
                    }
                }
                img.GetDetailTaskFunc = async() => await GetSearchByNewOrHotDetailTask(img, token, para);

                img.OriginString = $"{item}";
                imgs.Add(img);
            }

            var c = $"{json?.data.total_count}".ToInt();

            Extend.ShowMessage($"共搜索到{c}张,已加载至{para.PageIndex}页,共{c / para.Count}页", null, Extend.MessagePos.InfoBar);
        }
コード例 #25
0
    public async Task <MoeItems> GetNewItems(string url, MoeItem father, CustomPagePara pa, bool isFirst,
                                             CancellationToken token)
    {
        var newItems = new MoeItems();
        var net      = Net.CloneWithCookie();
        var html     = await net.GetHtmlAsync(url, token : token, showSearchMessage : false);

        if (html == null)
        {
            return(newItems);
        }
        var root      = html.DocumentNode;
        var imgOrImgs = root.GetValue(pa.DetailImagesList);

        if (pa.DetailImagesList.IsMultiValues)
        {
            var imgs = (HtmlNodeCollection)imgOrImgs;
            if (imgs?.Count > 0)
            {
                foreach (var img in imgs)
                {
                    var newm = GetChildrenItem(img, pa, father);
                    newItems.Add(newm);
                }
            }
            else
            {
                return(newItems);
            }
        }
        else
        {
            var img  = (HtmlNode)imgOrImgs;
            var newm = GetChildrenItem(img, pa, father);
            newItems.Add(newm);
        }


        var currentPageIndex = root.GetValue(pa.DetailCurrentPageIndex);
        var currentIndex     = $"{currentPageIndex}".ToInt();
        var nextpageIndex    = $"{root.GetValue(pa.DetailNextPageIndex)}".ToInt();

        //var maxPageIndex = $"{root.GetValue(pa.DetailMaxPageIndex)}".ToInt();
        if (isFirst)
        {
            var imageCount = $"{root.GetValue(pa.DetailImagesCount)}".ToInt();
            if (imageCount != 0)
            {
                father.ChildrenItemsCount = imageCount;
            }
        }

        if (nextpageIndex == currentIndex + 1)
        {
            var nextUrl = root.GetValue(pa.DetailNextPageUrl);
            var last    = newItems.LastOrDefault();
            if (last != null)
            {
                last.IsResolveAndDownloadNextItem = true;
                last.GetNextItemsTaskFunc        += async t => await GetNewItems(nextUrl, father, pa, false, t);
            }
        }

        return(newItems);
    }