/// <summary> /// 获取"猜你喜欢"(PixivCS Api) /// </summary> /// <param name="imgId">获取与此插画类似的其他插画</param> /// <param name="nextUrl">从首次请求中获取到的带有参数设置的请求url,可用于下一次的带参请求</param> /// <param name="account"></param> /// /// <param name="password"></param> /// <param name="refreshToken"></param> /// <returns>元组数据,item1为插画信息队列,item2为下次请求的url参数</returns> public async Task <ValueTuple <ConcurrentQueue <ImageInfo>, string> > getRecommenList(string imgId, string nextUrl) { ConcurrentQueue <ImageInfo> queue = new ConcurrentQueue <ImageInfo>(); if (imgId == null) { PixivCS.Objects.IllustRecommended recommendres = null; try { //是否使用nexturl更新list if ("begin".Equals(nextUrl)) { recommendres = await new PixivAppAPI(baseAPI).GetIllustRecommendedAsync(); } else { Uri next = new Uri(nextUrl); string getparam(string param) => HttpUtility.ParseQueryString(next.Query).Get(param); recommendres = await new PixivAppAPI(baseAPI).GetIllustRecommendedAsync (ContentType: getparam("content_type"), IncludeRankingLabel: bool.Parse(getparam("include_ranking_label")), Filter: getparam("filter"), MinBookmarkIDForRecentIllust: getparam("min_bookmark_id_for_recent_illust"), MaxBookmarkIDForRecommended: getparam("max_bookmark_id_for_recommend"), Offset: getparam("offset"), IncludeRankingIllusts: bool.Parse(getparam("include_ranking_illusts")), IncludePrivacyPolicy: getparam("include_privacy_policy")); } nextUrl = recommendres.NextUrl?.ToString() ?? ""; foreach (PixivCS.Objects.UserPreviewIllust ill in recommendres.Illusts) { //当插画数大于1时插画URL会改变,以后再解决吧 if (ill.PageCount == 1) { ImageInfo imginfo = new ImageInfo(); imginfo.imgUrl = ill.MetaSinglePage.OriginalImageUrl.ToString(); imginfo.viewCount = (int)ill.TotalView; imginfo.isR18 = false; imginfo.userId = ill.User.Id.ToString(); imginfo.userName = ill.User.Name; imginfo.imgId = ill.Id.ToString(); imginfo.title = ill.Title; imginfo.height = (int)ill.Height; imginfo.width = (int)ill.Width; imginfo.format = imginfo.imgUrl.Split('.').Last(); queue.Enqueue(imginfo); } } } catch (Exception e) { Console.WriteLine(e.Message); return(new ValueTuple <ConcurrentQueue <ImageInfo>, string>(null, "begin")); } } else { PixivCS.Objects.UserIllusts related = null; try { related = await new PixivAppAPI(baseAPI).GetIllustRelatedAsync(imgId); foreach (PixivCS.Objects.UserPreviewIllust ill in related.Illusts) { if (ill.PageCount == 1) { ImageInfo imginfo = new ImageInfo(); imginfo.imgUrl = ill.MetaSinglePage.OriginalImageUrl.ToString(); imginfo.viewCount = (int)ill.TotalView; imginfo.isR18 = false; imginfo.userId = ill.User.Id.ToString(); imginfo.userName = ill.User.Name; imginfo.imgId = ill.Id.ToString(); imginfo.title = ill.Title; imginfo.height = (int)ill.Height; imginfo.width = (int)ill.Width; imginfo.format = imginfo.imgUrl.Split('.').Last(); queue.Enqueue(imginfo); } } } catch (Exception e) { Console.WriteLine(e.Message); return(new ValueTuple <ConcurrentQueue <ImageInfo>, string>(null, "begin")); } } return(new ValueTuple <ConcurrentQueue <ImageInfo>, string>(queue, nextUrl)); }
protected override async Task <LoadMoreItemsResult> LoadMoreItemsAsync(CancellationToken c, uint count) { try { LoadMoreItemsResult toret = new LoadMoreItemsResult { Count = 0 }; if (!HasMoreItems) { return(toret); } PixivCS.Objects.IllustRecommended recommendres = null; try { Debug.WriteLine($"[RecommendIllustsCollection.LoadMoreItemsAsync]\t{nexturl}"); if (nexturl == "begin") { recommendres = await new PixivAppAPI(OverAll.GlobalBaseAPI) .GetIllustRecommendedAsync(); } else { Uri next = new Uri(nexturl); string getparam(string param) => HttpUtility.ParseQueryString(next.Query).Get(param); recommendres = await new PixivAppAPI(OverAll.GlobalBaseAPI) .GetIllustRecommendedAsync( ContentType: getparam("content_type"), IncludeRankingLabel: bool.Parse(getparam("include_ranking_label")), Filter: getparam("filter"), MinBookmarkIDForRecentIllust: getparam("min_bookmark_id_for_recent_illust"), MaxBookmarkIDForRecommended: getparam("max_bookmark_id_for_recommend"), Offset: getparam("offset"), IncludeRankingIllusts: bool.Parse(getparam("include_ranking_illusts")), IncludePrivacyPolicy: getparam("include_privacy_policy")); } } catch (Exception ex) { Debug.WriteLine(ex); return(toret); } nexturl = recommendres.NextUrl?.ToString() ?? ""; Debug.WriteLine($"[RecommendIllustsCollection.LoadMoreItemsAsync]\t{nexturl}"); if (recommendres.Illusts is null) { Debug.WriteLine("出现了NULL"); // 这里调用更新身份信息的方法 Debug.WriteLine("Done"); } else { foreach (var recillust in recommendres.Illusts) { await Task.Run(pause.WaitOne); Debug.WriteLine($"[RecommendIllustsCollection.LoadMoreItemsAsync]\t加载图片:{toret.Count + 1}/{recommendres.Illusts.Length}"); if (_emergencyStop) { Debug.WriteLine("_emergencyStop = " + _emergencyStop); nexturl = ""; Clear(); return(new LoadMoreItemsResult { Count = 0 }); } WaterfallItem recommendi = WaterfallItem.FromObject(recillust); var recommendmodel = ViewModels.WaterfallItemViewModel.FromItem(recommendi); await recommendmodel.LoadImageAsync(); Add(recommendmodel); toret.Count++; } } return(toret); } finally { LoadMoreItemsAsync_Finally(); } }