/// <summary> /// Gets the images from the specified url. /// </summary> /// <param name="client"></param> /// <param name="url"></param> /// <returns></returns> public static async Task <ImageResponse> GetPixivImagesAsync(IDownloaderClient client, Uri url) { var u = DownloaderClient.RemoveQuery(url).ToString().Replace("_d", ""); if (u.IsImagePath()) { return(ImageResponse.FromUrl(new Uri(u))); } if (!(HttpUtility.ParseQueryString(url.Query)["illust_id"] is string id)) { return(ImageResponse.FromUrl(url)); } var mangaQuery = new Uri($"https://www.pixiv.net/member_illust.php?mode=manga&illust_id={id}"); var mangaResult = await client.GetHtmlAsync(() => client.GenerateReq(mangaQuery)).CAF(); if (mangaResult.IsSuccess) { //18+ filter if (mangaResult.Value.DocumentNode.Descendants("p").Any(x => x.HasClass("title") && x.InnerText.Contains("R-18"))) { return(ImageResponse.FromException(url, new InvalidOperationException("Locked behind R18 filter."))); } //Sign up menu if (mangaResult.Value.DocumentNode.Descendants("div").Any(x => x.HasClass("signup-form"))) { return(ImageResponse.FromException(url, new InvalidOperationException("Locked behind R18 filter or is private."))); } var div = mangaResult.Value.DocumentNode.Descendants("div"); var itemContainer = div.Where(x => x.GetAttributeValue("class", "") == "item-container"); var images = itemContainer.Select(x => x.Descendants("img").Single()); var imageUrls = images.Select(x => new Uri(FixPixivUrl(x.GetAttributeValue("data-src", "")))); return(ImageResponse.FromImages(imageUrls)); } var mediumQuery = new Uri($"https://www.pixiv.net/member_illust.php?mode=medium&illust_id={id}"); var mediumResult = await client.GetHtmlAsync(() => client.GenerateReq(mediumQuery)).CAF(); if (mediumResult.IsSuccess) { //18+ filter if (mediumResult.Value.DocumentNode.Descendants("p").Any(x => x.HasClass("title") && x.InnerText.Contains("R-18"))) { return(ImageResponse.FromException(url, new InvalidOperationException("Locked behind R18 filter."))); } var div = mediumResult.Value.DocumentNode.Descendants("div"); var imgContainer = div.Single(x => x.GetAttributeValue("class", "") == "img-container"); var img = imgContainer.Descendants("img").Single(); var imageUrl = new Uri(FixPixivUrl(img.GetAttributeValue("src", ""))); return(ImageResponse.FromUrl(imageUrl)); } return(ImageResponse.FromNotFound(url)); }