コード例 #1
0
    public override async Task <SearchedPage> GetRealPageAsync(SearchPara para, CancellationToken token)
    {
        if (!IsUserLogin)
        {
            Login();
        }
        var net = Net.CloneWithCookie();
        var cat = CustomConfig.Categories[para.Lv2MenuIndex];
        var api = para.PageIndex <= 1 ? cat.FirstPageApi : cat.FollowUpPageApi;

        if (!para.Keyword.IsEmpty() && cat.OverrideSearchApi == null)
        {
            api = CustomConfig.SearchApi.Replace("{keyword}", para.Keyword.ToEncodedUrl());
        }
        var rapi = api.Replace("{pagenum}", $"{para.PageIndex}").Replace("{pagenum-1}", $"{para.PageIndex - 1}");
        var html = await net.GetHtmlAsync(rapi, token : token);

        if (html == null)
        {
            return(null);
        }
        var moes = new SearchedPage();

        moes.OriginString = new StringBuilder(html.Text);
        var pa   = cat.OverridePagePara ?? CustomConfig.PagePara;
        var list = (HtmlNodeCollection)html.DocumentNode.GetValue(pa.ImagesList);

        if (!(list?.Count > 0))
        {
            return(moes);
        }
        foreach (var item in list)
        {
            var moe = new MoeItem(this, para);
            var url = item.GetValue(pa.ImageItemThumbnailUrlFromImagesList);
            if (url == null)
            {
                continue;
            }
            var refer = pa.ImageItemThumbnailUrlFromImagesList.Referer;
            moe.Urls.Add(DownloadTypeEnum.Thumbnail, url, refer);
            moe.Title = item.GetValue(pa.ImageItemTitleFromImagesList);
            var detail = item.GetValue(pa.ImageItemDetailUrlFromImagesList);
            moe.DetailUrl          = detail;
            moe.GetDetailTaskFunc += t => GetDetail(moe.DetailUrl, moe, pa, true, t);
            if (pa.ImageItemDateTimeFromImagesList != null)
            {
                var date = item.GetValue(pa.ImageItemDateTimeFromImagesList);
                moe.DateString = $"{date}";
            }

            moe.OriginString = item.InnerHtml;
            moes.Add(moe);
        }

        return(moes);
    }
コード例 #2
0
ファイル: KonachanSite.cs プロジェクト: xplusky/MoeLoaderP
    public override async Task <SearchedPage> GetRealPageAsync(SearchPara para, CancellationToken token)
    {
        //var homeUrl = para.IsShowExplicit ? HomeUrl : SafeHomeUrl;
        var homeUrl = HomeUrl;
        var pairs   = new Pairs
        {
            { "page", $"{para.PageIndex}" },
            { "limit", $"{para.CountLimit}" },
            { "tags", para.Keyword.ToEncodedUrl() }
        };

        var query = $"{homeUrl}/post.json{pairs.ToPairsString()}";
        var net   = new NetOperator(Settings, this);
        var json  = await net.GetJsonAsync(query, token : token);

        var imageItems = new SearchedPage();

        foreach (var item in Ex.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(DownloadTypeEnum.Thumbnail, $"{item.preview_url}");
            img.Urls.Add(DownloadTypeEnum.Medium, $"{item.sample_url}");
            img.Urls.Add(DownloadTypeEnum.Origin, $"{item.file_url}", img.DetailUrl,
                         filesize: $"{item.file_size}".ToUlong());
            img.Source       = $"{item.source}";
            img.OriginString = $"{item}";
            imageItems.Add(img);
        }

        return(imageItems);
    }
コード例 #3
0
ファイル: SankakuIdolSite.cs プロジェクト: xplusky/MoeLoaderP
    public override async Task <SearchedPage> GetRealPageAsync(SearchPara para, CancellationToken token)
    {
        if (!IsUserLogin)
        {
            await LoginAsync(token);
        }
        if (!IsUserLogin)
        {
            return(new SearchedPage());
        }
        var query = $"{_idolQuery}page={para.PageIndex}&limit={para.CountLimit}&tags={para.Keyword.ToEncodedUrl()}";
        var list  = await Net.GetJsonAsync(query, token : token);

        if (list == null)
        {
            return new SearchedPage {
                       Message = "获取Json失败"
            }
        }
        ;
        var          imgs  = new SearchedPage();
        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 Ex.GetList(item.tags))
            {
                img.Tags.Add($"{tag.name}");
            }
            img.IsExplicit = $"{item.rating}" == "e";
            img.Urls.Add(DownloadTypeEnum.Thumbnail, $"{https}{item.preview_url}", img.DetailUrl);
            img.Urls.Add(DownloadTypeEnum.Medium, $"{https}{item.sample_url}", img.DetailUrl);
            img.Urls.Add(DownloadTypeEnum.Origin, $"{https}{item.file_url}", img.DetailUrl);
            img.OriginString = $"{item}";
            imgs.Add(img);
        }

        return(imgs);
    }
コード例 #4
0
ファイル: PixivSite.cs プロジェクト: xplusky/MoeLoaderP
    public async Task SearchByRank(NetOperator net, SearchedPage 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, pair, token : token);

        foreach (var illus in Ex.GetList(json?.contents))
        {
            var img = new MoeItem(this, para);
            img.Urls.Add(DownloadTypeEnum.Thumbnail, $"{illus.url}", referer);
            img.Id                 = $"{illus.illust_id}".ToInt();
            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.ChildrenItemsCount = $"{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 Ex.GetList(illus.tags))
            {
                img.Tags.Add($"{tag}");
            }

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

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

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

        Ex.ShowMessage($"共{count}张,当前日期:{json?.date}", null, Ex.MessagePos.InfoBar);
    }
コード例 #5
0
ファイル: PixivSite.cs プロジェクト: xplusky/MoeLoaderP
    public async Task SearchByAuthor(NetOperator net, SearchedPage imgs, string uid, SearchPara para,
                                     CancellationToken token)
    {
        var isIllust = para.Lv3MenuIndex == 0;
        var mi       = isIllust ? "illustrations" : "manga";
        var mi2      = isIllust ? "illusts" : "manga";
        var mi3      = isIllust ? "插画" : "漫画";

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

        if ($"{allJson?.error}".ToLower() == "true")
        {
            Ex.ShowMessage($"搜索失败,网站信息:“{$"{allJson?.message}".ToDecodedUrl()}”", null, Ex.MessagePos.Window);
            return;
        }

        var picIds = new List <string>();
        var arts   = isIllust ? allJson?.body?.illusts : allJson?.body?.manga;

        foreach (var ill in Ex.GetList(arts))
        {
            picIds.Add((ill as JProperty)?.Name);
        }
        var picCurrentPage = picIds.OrderByDescending(i => i.ToInt())
                             .Skip(((para.PageIndex ?? 0) - 1) * para.CountLimit).Take(para.CountLimit).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", pairs, token : token);

        var works = picsJson?.body?.works;

        foreach (var item in Ex.GetList(works))
        {
            dynamic illus = (item as JProperty)?.Value;
            if (illus == null)
            {
                continue;
            }
            var img = new MoeItem(this, para);
            img.Urls.Add(DownloadTypeEnum.Thumbnail, $"{illus.url}", $"{HomeUrl}/users/{uid}/{mi}");
            img.Id                 = $"{illus.id}".ToInt();
            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.ChildrenItemsCount = $"{illus.pageCount}".ToInt();
            foreach (var tag in Ex.GetList(illus.tags))
            {
                img.Tags.Add($"{tag}");
            }
            img.Date = GetDateFromUrl($"{illus.url}");
            if ($"{illus.illustType}" == "2")
            {
                img.GetDetailTaskFunc = async t => await GetUgoiraDetailPageTask(img, t);
            }
            else
            {
                img.GetDetailTaskFunc = async t => await GetDetailPageTask(img, para, t);
            }
            img.OriginString = $"{item}";

            imgs.Add(img);
        }

        Ex.ShowMessage($"该作者共有{mi3}{picIds.Count}张,当前第{para.CountLimit * (para.PageIndex - 1) + 1}张", null,
                       Ex.MessagePos.InfoBar);
    }
コード例 #6
0
ファイル: PixivSite.cs プロジェクト: xplusky/MoeLoaderP
    public async Task SearchByNewOrTag(NetOperator net, SearchedPage imgs, SearchPara para, CancellationToken token)
    {
        string referer, api;
        Pairs  pairs;
        var    isIllust = para.Lv3MenuIndex == 0;
        var    homeurl  = HomeUrl;

        //if (para.MirrorSite.Name == "pixiviz")
        //{
        //    homeurl = "https://pixiviz-api-us.pwp.link/v1";
        //}
        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.PageIndexCursor.IsEmpty() ? "" : $"{para.PageIndexCursor}" },
                { "limit", $"{para.CountLimit}" },
                { "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, pairs, token : token);

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

        foreach (var illus in Ex.GetList(list))
        {
            var img = new MoeItem(this, para);
            img.Id = $"{illus.id}".ToInt();
            img.Urls.Add(new UrlInfo(DownloadTypeEnum.Thumbnail, $"{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.ChildrenItemsCount = $"{illus.pageCount}".ToInt();
            foreach (var tag in Ex.GetList(illus.tags))
            {
                img.Tags.Add($"{tag}");
            }
            img.Date = GetDateFromUrl($"{illus.url}");
            if ($"{illus.illustType}" == "2")
            {
                img.GetDetailTaskFunc = async t => await GetUgoiraDetailPageTask(img, t);
            }
            else
            {
                img.GetDetailTaskFunc = async t => await GetDetailPageTask(img, para, t);
            }
            img.OriginString = $"{illus}";
            imgs.Add(img);
        }

        var lastid = $"{json?.body?.lastId}";

        if (!lastid.IsEmpty())
        {
            imgs.NextPageIndexCursor = lastid;
        }
        if (!para.Keyword.IsEmpty() && json != null)
        {
            var count = $"{json?.body?.illust?.total}".ToInt();
            Ex.ShowMessage($"共搜索到{count}张图片,当前已加载至第{para.PageIndex}页,共{count / 60}页", null, Ex.MessagePos.InfoBar);
        }
    }
コード例 #7
0
ファイル: PixivSite.cs プロジェクト: xplusky/MoeLoaderP
    public async Task SearchViaMirrorSite(NetOperator net, SearchedPage imgs, SearchPara para, CancellationToken token)
    {
        var referer   = "https://pixiviz.pwp.app";
        var homeurl   = referer;
        var replaceTo = "";

        net.SetReferer(referer);
        if (para.Keyword.IsEmpty())
        {
            throw new Exception("镜像站点必须填入关键字");
        }
        var api =
            $"https://pixiviz-api-us.pwp.link/v1/illust/search?word={para.Keyword.ToEncodedUrl()}&page={para.PageIndex}";

        if (para.MirrorSite.Name == "pixiviz")
        {
            replaceTo = "https://pixiv-image-lv.pwp.link";
        }
        var json = await net.GetJsonAsync(api, token : token);

        dynamic list = null;

        if (para.MirrorSite.Name == "pixiviz")
        {
            list = json?.illusts;
        }

        foreach (var illus in Ex.GetList(list))
        {
            var img = new MoeItem(this, para);
            img.Id = $"{illus.id}".ToInt();
            var imgurl  = $"{illus.image_urls.medium}".Replace("https://i.pximg.net", replaceTo);
            var imgurlL = $"{illus.image_urls.large}".Replace("https://i.pximg.net", replaceTo);
            img.Urls.Add(new UrlInfo(DownloadTypeEnum.Large, imgurl, referer));
            img.Urls.Add(new UrlInfo(DownloadTypeEnum.Thumbnail, imgurlL, referer));
            img.Title              = $"{illus.title}";
            img.Uploader           = $"{illus.user.account}";
            img.UploaderId         = $"{illus.user.id}";
            img.Width              = $"{illus.width}".ToInt();
            img.Height             = $"{illus.height}".ToInt();
            img.ChildrenItemsCount = $"{illus.page_count}".ToInt();
            foreach (var tag in Ex.GetList(illus.tags))
            {
                img.Tags.Add($"{tag.name}");
            }
            img.Date         = $"{illus.create_date}".ToDateTime();
            img.OriginString = $"{illus}";
            img.Score        = $"{illus.total_bookmarks}".ToInt();
            if (illus.meta_pages != null)
            {
                foreach (var item in Ex.GetList(illus.meta_pages))
                {
                    if (item.image_urls?.original != null)
                    {
                        var child   = new MoeItem(this, para);
                        var imgUrlO = $"{item.image_urls?.original}".Replace("https://i.pximg.net", replaceTo);
                        child.Urls.Add(new UrlInfo(DownloadTypeEnum.Origin, imgUrlO, homeurl));
                        img.ChildrenItems.Add(child);
                    }
                }
            }

            if (illus.meta_single_page?.original_image_url != null)
            {
                var imgurlO = $"{illus.meta_single_page?.original_image_url}".Replace("https://i.pximg.net", replaceTo);
                img.Urls.Add(new UrlInfo(DownloadTypeEnum.Origin, imgurlO, homeurl));
            }

            imgs.Add(img);
        }
    }
コード例 #8
0
    public override async Task <SearchedPage> GetRealPageAsync(SearchPara para, CancellationToken token)
    {
        Net ??= new NetOperator();

        //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.CountLimit}" },
            { "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.CountLimit}" },
                { "q", para.Keyword.ToEncodedUrl() }
            };
        }

        // images

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

        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(DownloadTypeEnum.Thumbnail, $"{jitem.photo?.thumbnail_url_display}", HomeUrl);
            img.Urls.Add(DownloadTypeEnum.Large, $"{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);
    }
コード例 #9
0
    public override async Task <SearchedPage> GetRealPageAsync(SearchPara para, CancellationToken token)
    {
        if (Net == null)
        {
            Net = new NetOperator(Settings, this);
            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 SearchedPage();
        var json       = await Net.GetJsonAsync($"{HomeUrl}/index.json", pair, token : token);

        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(DownloadTypeEnum.Thumbnail, $"{sub}{UrlInner($"{id}")}/small.{small}");
            var orig = $"{image.orig}";
            var big  = $"{image.big}";
            if (!orig.IsEmpty())
            {
                img.Urls.Add(DownloadTypeEnum.Origin, $"{sub}{UrlInner($"{id}")}/orig.{orig}");
            }
            else if (!big.IsEmpty())
            {
                img.Urls.Add(DownloadTypeEnum.Origin, $"{sub}{UrlInner($"{id}")}/big.{big}");
            }
            img.DetailUrl = $"{HomeUrl}/image?id={id}";

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

            imageItems.Add(img);
        }

        token.ThrowIfCancellationRequested();
        return(imageItems);
    }
コード例 #10
0
    public override async Task <SearchedPage> GetRealPageAsync(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 SearchedPage();

        var doc = await Net.GetHtmlAsync(url, token : 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 SearchedPage {
                       Message = "读取HTML失败"
            }
        }
        ;
        foreach (var node in listnode)
        {
            var img = new MoeItem(this, para);

            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(DownloadTypeEnum.Thumbnail, $"{pre}{src}", url));
            }
            var resstrs = node.GetInnerText("div[@class = 'img_block_text'] / a").Split('x');
            if (resstrs.Length == 2)
            {
                img.Width  = resstrs[0].ToInt();
                img.Height = resstrs[1].ToInt();
            }

            var scorestr = node.GetInnerText("div[@class='img_block_text']/span");
            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 t => await GetDetailTask(img, t);
            }

            imgs.Add(img);
        }

        token.ThrowIfCancellationRequested();
        return(imgs);
    }
コード例 #11
0
    public override async Task <SearchedPage> GetRealPageAsync(SearchPara para, CancellationToken token)
    {
        if (!IsUserLogin)
        {
            Login();
        }
        if (!IsUserLogin)
        {
            throw new Exception("必须登录才能搜索");
        }
        var page = new SearchedPage();
        var net  = GetCloneNet();

        var pairs = new Pairs();
        var api   = "";

        switch (para.Lv2MenuIndex)
        {
        case 0:
            if (para.Keyword.Trim().Length > 0)
            {
                api = $"{SearchDeviationsApi}";
                pairs.Add(new ("q", para.Keyword.Trim().Replace(" ", "+")));
            }
            else
            {
                api = $"{NewDeviationsApi}";
            }

            break;

        case 1:
            api = $"{PopularDeviationsApi}";
            break;
        }

        if (!para.PageIndexCursor.IsEmpty())
        {
            pairs.Add("cursor", para.PageIndexCursor);
        }
        var json = await net.GetJsonAsync($"{HomeUrl}{api}", pairs, true,
                                          token);

        foreach (var devi in Ex.GetList(json.deviations))
        {
            if (!$"{devi.type}".Equals("image", StringComparison.OrdinalIgnoreCase))
            {
                continue;
            }
            var item       = new MoeItem(this, para);
            var orgfile    = $"{devi.media.baseUri}";
            var thumbToken = "";
            foreach (var t in Ex.GetList(devi.media.token))
            {
                thumbToken = $"{t}";
                if (thumbToken.IsEmpty())
                {
                    continue;
                }
                break;
            }

            var types = devi.media.types;
            item.DetailUrl = $"{devi.url}";
            var dlbool = false;
            var dl     = $"{devi.isDownloadable}";
            if (dl.Equals("true", StringComparison.OrdinalIgnoreCase))
            {
                var org = $"{orgfile}?token={thumbToken}";
                item.Urls.Add(DownloadTypeEnum.Origin, org, HomeUrl);
                dlbool = true;
            }

            foreach (var type in Ex.GetList(types))
            {
                var t = $"{type.t}";
                if (t.Contains("350"))
                {
                    //thumbContnent = $"/v1/fit/w_{type.w},h_{type.h},q_70,strp/{type.c}";
                    var thumbContnent = $"/{type.c}".Replace("<prettyName>", $"{devi.media.prettyName}");
                    var url           = $"{orgfile}{thumbContnent}?token={thumbToken}";
                    item.Urls.Add(DownloadTypeEnum.Thumbnail, url, HomeUrl);
                    continue;
                }

                if (t.Equals("preview", StringComparison.OrdinalIgnoreCase))
                {
                    var thumbContnent = $"/{type.c}".Replace("<prettyName>", $"{devi.media.prettyName}");
                    var url           = $"{orgfile}{thumbContnent}?token={thumbToken}";
                    item.Urls.Add(DownloadTypeEnum.Medium, url, HomeUrl);
                    continue;
                }

                if (t.Equals("fullview", StringComparison.OrdinalIgnoreCase))
                {
                    if ($"{type.c}".IsEmpty())
                    {
                        continue;
                    }
                    var thumbContnent = $"/{type.c}".Replace("<prettyName>", $"{devi.media.prettyName}");
                    var url           = $"{orgfile}{thumbContnent}?token={thumbToken}";
                    item.Urls.Add(DownloadTypeEnum.Large, url, HomeUrl);
                    if (!dlbool)
                    {
                        item.Urls.Add(DownloadTypeEnum.Origin, url, HomeUrl);
                    }
                }
            }


            item.Id = $"{devi.deviationId}".ToInt();

            item.Title        = $"{devi.title}";
            item.UploaderId   = $"{devi.author.userId}";
            item.Uploader     = $"{devi.author.username}";
            item.OriginString = $"{devi}";
            page.Add(item);
        }

        page.NextPageIndexCursor = $"{json.nextCursor}";
        return(page);
    }
コード例 #12
0
    public override async Task <SearchedPage> GetRealPageAsync(SearchPara para, CancellationToken token)
    {
        var rp  = new SearchedPage();
        var url = $"{HomeUrl}/?page={para.PageIndex}";

        Net ??= new NetOperator(Settings, this);
        if (!para.Keyword.IsEmpty())
        {
            url = $"{HomeUrl}/search/process/";
            var i = para.Lv2MenuIndex;
            //var kw = $"{$"\"{para.Keyword.Delete("\"")}\"".ToEncodedUrl()}";
            var kw = $"\"{para.Keyword}\"";
            //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.CloneWithCookie();
            var r   = await net.Client.GetAsync(HomeUrl, token);

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

            net = net.CloneWithCookie();
            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 SearchedPage {
                           Message = "没有搜索到关键词相关的图片"
                }
            };
        }

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

        if (doc == null)
        {
            return(new SearchedPage
            {
                Message = "获取HTML失败"
            });
        }

        var nodes = doc.DocumentNode.SelectNodes("//div[@class='image_thread display']");

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

        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(DownloadTypeEnum.Thumbnail, 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;
            rp.Add(img);
        }

        return(rp);
    }