예제 #1
0
    public async Task GetDetailPageTask(MoeItem img, SearchPara para, CancellationToken token)
    {
        var net  = Net.CloneWithCookie();
        var json = await net.GetJsonAsync($"{HomeUrl}/ajax/illust/{img.Id}/pages", showSearchMessage : false,
                                          token : token);

        var img1  = json?.body?[0];
        var refer = $"{HomeUrl}/artworks/{img.Id}";

        if (img1 != null)
        {
            //img.Urls.Add(2, $"{img1.urls.small}", refer);
            img.Urls.Add(DownloadTypeEnum.Large, $"{img1.urls.regular}", refer);
            img.Urls.Add(DownloadTypeEnum.Origin, $"{img1.urls.original}", refer);
        }

        var list = (JArray)json?.body;

        if (list?.Count > 1)
        {
            foreach (var item in json.body)
            {
                var imgItem = new MoeItem(this, para);
                //imgItem.Urls.Add(2, $"{img1?.urls.small}", refer);
                imgItem.Urls.Add(DownloadTypeEnum.Large, $"{img1?.urls.regular}", refer);
                imgItem.Urls.Add(DownloadTypeEnum.Origin, $"{item?.urls?.original}", refer);
                img.ChildrenItems.Add(imgItem);
            }
        }
    }
예제 #2
0
    public async Task GetUgoiraDetailPageTask(MoeItem img, CancellationToken token)
    {
        if (img.Tip.IsEmpty())
        {
            img.Tip = "动图";
        }
        var net     = Net.CloneWithCookie();
        var api     = $"{HomeUrl}/ajax/illust/{img.Id}/ugoira_meta";
        var jsonRes = await net.Client.GetAsync(api, token);

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

        dynamic json  = JsonConvert.DeserializeObject(jsonStr);
        var     img1  = json?.body;
        var     refer = $"{HomeUrl}/artworks/{img.Id}";

        if (img1 != null)
        {
            //img.Urls.Add(2, $"{img1.src}", refer, UgoiraAfterEffects);
            img.Urls.Add(3, $"{img1.src}", refer, UgoiraAfterEffects);
            img.Urls.Add(4, $"{img1.originalSrc}", refer, UgoiraAfterEffects);
            img.ExtraFile = new TextFileInfo {
                FileExt = "json", Content = jsonStr
            };
        }
    }
예제 #3
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);
    }
예제 #4
0
    public override async Task <SearchedPage> GetRealPageAsync(SearchPara para, CancellationToken token)
    {
        var islogin = CheckIsLogin();

        if (!islogin)
        {
            return(null);
        }
        if (Net == null)
        {
            Net = new NetOperator(Settings, this);
            Net.SetCookie(SiteSettings.GetCookieContainer());
        }

        var net = Net.CloneWithCookie();

        net.SetTimeOut(40);

        var imgs = new SearchedPage();

        if (para.MirrorSite.IsDefault)
        {
            switch ((SearchTypeEnum)para.Lv2MenuIndex)
            {
            case SearchTypeEnum.TagOrNew:
                await SearchByNewOrTag(net, imgs, para, token);

                break;

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

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

                break;
            }
        }
        else
        {
            await SearchViaMirrorSite(net, imgs, para, token);
        }

        token.ThrowIfCancellationRequested();
        return(imgs);
    }
예제 #5
0
    public NetOperator CloneNet()
    {
        var net = Net.CloneWithCookie();

        if (!AccessToken.IsEmpty())
        {
            net.Client.DefaultRequestHeaders.Add("authorization", $"Bearer {AccessToken}");
        }

        return(net);
    }
예제 #6
0
    public override async Task <AutoHintItems> GetAutoHintItemsAsync(SearchPara para, CancellationToken token)
    {
        if (Net == null)
        {
            Login();
        }
        var net  = Net.CloneWithCookie();
        var list = new AutoHintItems();

        switch (SiteType)
        {
        case SiteTypeEnum.Xml:
            var xml = await net.GetXmlAsync(GetHintQuery(para), token : token);

            if (xml == null)
            {
                return(list);
            }

            var root = xml.SelectSingleNode("tags");
            if (root?.ChildNodes == null)
            {
                return(list);
            }
            foreach (XmlElement child in root.ChildNodes)
            {
                list.Add(new AutoHintItem
                {
                    Word  = child.GetAttribute("name"),
                    Count = child.GetAttribute("count")
                });
            }
            return(list);

        case SiteTypeEnum.Json:
            var json = await net.GetJsonAsync(GetHintQuery(para), token : token);

            foreach (var item in Ex.GetList(json))
            {
                list.Add(new AutoHintItem
                {
                    Word  = $"{item.name}",
                    Count = $"{item.post_count}"
                });
            }
            return(list);
        }

        return(list);
    }
예제 #7
0
    public async Task GetDetailLv2(CustomPagePara pa, MoeItem currentItem, UrlInfo urlinfo, CancellationToken token)
    {
        var url  = currentItem.DetailUrl;
        var net  = Net.CloneWithCookie();
        var html = await net.GetHtmlAsync(url, null, false, token);

        if (pa.DetailLv2ImageOriginUrl != null)
        {
            var originUrl = html.DocumentNode.GetValue(pa.DetailLv2ImageOriginUrl);
            urlinfo.Url = $"{originUrl}";
        }

        if (pa.DetailLv2ImagePreviewUrl != null)
        {
            var prevUrl = html.DocumentNode.GetValue(pa.DetailLv2ImagePreviewUrl);
            currentItem.Urls.Add(DownloadTypeEnum.Medium, $"{prevUrl}");
        }
    }
예제 #8
0
    public override async Task <AutoHintItems> GetAutoHintItemsAsync(SearchPara para, CancellationToken token)
    {
        Net ??= new NetOperator(Settings, this);
        //type 1 tag 2 source 3 artist | chara no type
        var items = new AutoHintItems();

        //chara without hint
        if (para.Lv2MenuIndex == 3)
        {
            return(items);
        }
        var pairs = new Pairs
        {
            { "mode", "tag_search" },
            { "tags", para.Keyword },
            { "type", $"{para.Lv2MenuIndex + 1}" }
        };
        var url = $"{HomeUrl}/httpreq.php{pairs.ToPairsString()}";
        var net = Net.CloneWithCookie();
        var res = await net.Client.GetAsync(url, token);

        var txt = await res.Content.ReadAsStringAsync(token);

        var lines = txt.Split('\n');

        for (var i = 0; i < lines.Length && i < 8; i++)
        {
            if (lines[i].Trim().Length > 0)
            {
                items.Add(new AutoHintItem
                {
                    Word = lines[i].Trim().Delete("\"")
                });
            }
        }

        return(items);
    }
예제 #9
0
    public async Task AddCat()
    {
        if (CustomConfig.CustomLv2MenuItems?.Count > 0)
        //if (false)
        {
            CustomConfig.Categories.Clear();
            //CustomConfig.Categories.Add("加载中..",null,null);
            //CatChange();
            //CustomConfig.Categories.Clear();
            //Lv2Cat.Add("加载中..");
            //CatChange();
            foreach (var item in CustomConfig.CustomLv2MenuItems)
            {
                var net  = Net.CloneWithCookie();
                var url  = item.PageUrl ?? CustomConfig.HomeUrl;
                var html = await net.GetHtmlAsync(url);

                var nodes = html.DocumentNode.SelectNodes(item.Menus.Path);
                foreach (var node in nodes)
                {
                    var cat = new CustomCategory();

                    try
                    {
                        var name = node.GetValue(item.MenuTitleFromMenus);
                        var url2 = node.GetValue(item.MenuUrlFromMenus);
                        if ($"{url2}".Equals(HomeUrl, StringComparison.OrdinalIgnoreCase))
                        {
                            continue;
                        }
                        cat.Name = name;
                        if (cat.Name.Equals("首页"))
                        {
                            continue;
                        }
                        cat.FirstPageApi = $"{url2}{item.FirstApi}";
                        var follow = $"{url2}{item.FollowApi}";
                        if (item.FollowApiReplaceFrom != null)
                        {
                            follow = follow.Replace(item.FollowApiReplaceFrom, item.FollowApiReplaceTo);
                        }
                        cat.FollowUpPageApi = $"{follow}";
                        if (item.OverridePagePara != null)
                        {
                            cat.OverridePagePara = item.OverridePagePara;
                        }
                        CustomConfig.Categories.Add(cat);
                    }
                    catch (Exception e)
                    {
                        Ex.Log(e);
                    }
                }
            }
        }
        //Lv2Cat.Clear();

        foreach (var cat in CustomConfig.Categories)
        {
            Lv2Cat.Add(cat.Name);
        }
        CatChange();
    }
예제 #10
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);
    }
예제 #11
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);
    }