Exemple #1
0
        /// <inheritdoc />
        public async Task <ImageResponse> GetImagesAsync(IDownloaderClient client)
        {
            if (PostUrl.ToString().IsImagePath())
            {
                return(ImageResponse.FromUrl(PostUrl));
            }
            if (client.Gatherers.SingleOrDefault(x => x.IsFromWebsite(PostUrl)) is IImageGatherer gatherer)
            {
                return(await gatherer.FindImagesAsync(client, PostUrl).CAF());
            }
            var result = await client.GetHtmlAsync(() => client.GenerateReq(PostUrl)).CAF();

            if (result.IsSuccess)
            {
                var img = result.Value.DocumentNode.Descendants("img");
                var src = img
                          .Select(x => x.GetAttributeValue("src", null))
                          .Select(x =>
                {
                    if (Uri.TryCreate(x, UriKind.Absolute, out var uri) ||
                        Uri.TryCreate($"https://{PostUrl.Host}{x}", UriKind.Absolute, out uri))
                    {
                        return(uri);
                    }
                    //How to check if relative to something other than just the host?
                    return(null);
                })
                          .Where(x => x != null);
                if (src.Any())
                {
                    return(ImageResponse.FromImages(src));
                }
            }
            return(ImageResponse.FromNotFound(PostUrl));
        }
Exemple #2
0
        /// <inheritdoc />
        public async Task <ImageResponse> GetImagesAsync(IDownloaderClient client)
        {
            //Only one image, so return the one image's url
            if (PageCount == 1)
            {
                return(ImageResponse.FromUrl(ImageUrls["large"]));
            }
            //Metadata is null so we need to get it again
            else if (Metadata == null)
            {
                var query = new Uri($"https://public-api.secure.pixiv.net/v1/works/{Id}.json" +
                                    $"?access_token={client.ApiKeys[typeof(PixivPostDownloader)]}" +
                                    "&include_stats=1" +
                                    "&include_sanity_level=1" +
                                    "&image_sizes=large" +
                                    "&inclue_metadata=1" +
                                    "&include_content_type=1");
                var result = await client.GetTextAsync(() => client.GenerateReq(query)).CAF();

                if (!result.IsSuccess)
                {
                    throw new InvalidOperationException("Unable to use the Pixiv api.");
                }
                //First b/c returns a list
                Metadata = JObject.Parse(result.Value)["response"].First["metadata"].ToObject <PixivPostMetadata>();
            }
            return(ImageResponse.FromImages(Metadata.Pages.Select(x => x.ImageUrls["large"])));
        }
        /// <summary>
        /// Gets the images from the specified url.
        /// </summary>
        /// <param name="client"></param>
        /// <param name="url"></param>
        /// <returns></returns>
        public static async Task <ImageResponse> GetDiyidanImagesAsync(IDownloaderClient client, Uri url)
        {
            var u = DownloaderClient.RemoveQuery(url).ToString();

            if (u.IsImagePath())
            {
                return(ImageResponse.FromUrl(new Uri(u)));
            }
            var result = await client.GetHtmlAsync(() => client.GenerateReq(url)).CAF();

            if (!result.IsSuccess)
            {
                return(ImageResponse.FromNotFound(url));
            }
            var div = result.Value.DocumentNode.Descendants("div");

            if (div.Any(x => x.GetAttributeValue("class", null) == "video_404_box"))
            {
                return(ImageResponse.FromAnimated(url));
            }
            var content = div.SingleOrDefault(x => x.GetAttributeValue("class", "").CaseInsContains("user_post_content"));

            if (content == null)
            {
                return(ImageResponse.FromNotFound(url));
            }
            var img        = content.Descendants("img");
            var postImages = img.Where(x => x.GetAttributeValue("class", null) != "mb-img");
            var src        = postImages.Select(x => x.GetAttributeValue("src", ""));
            var urls       = src.Select(x => new Uri($"https:{x.Substring(0, x.LastIndexOf('!'))}"));

            return(src.Any() ? ImageResponse.FromImages(urls) : ImageResponse.FromNotFound(url));
        }
Exemple #4
0
 /// <inheritdoc />
 public Task <ImageResponse> GetImagesAsync(IDownloaderClient client)
 {
     if (Photos?.Count > 0)
     {
         var urls = Photos.Select(x => x.FullSizeImageUrl).ToArray();
         return(Task.FromResult(ImageResponse.FromImages(urls)));
     }
     return(Task.FromResult(ImageResponse.FromUrl(FullSizeImageUrl)));
 }
        /// <inheritdoc />
        public Task <ImageResponse> GetImagesAsync(IDownloaderClient client)
        {
            if (ExtendedEntities.Media == null)
            {
                return(Task.FromResult(ImageResponse.FromNotFound(PostUrl)));
            }
            var urls = ExtendedEntities.Media.Select(x => new Uri($"{x.MediaUrlHttps}:orig"));

            return(Task.FromResult(ImageResponse.FromImages(urls)));
        }
        /// <summary>
        /// Gets the images from the specified url.
        /// </summary>
        /// <param name="client"></param>
        /// <param name="url"></param>
        /// <returns></returns>
        public static async Task <ImageResponse> GetLofterImagesAsync(IDownloaderClient client, Uri url)
        {
            var result = await client.GetHtmlAsync(() => client.GenerateReq(url)).CAF();

            var div  = result.Value.DocumentNode.Descendants("div");
            var pics = div.Where(x => x.GetAttributeValue("class", null) == "pic").Select(x => x.Descendants("a").Single());
            var urls = pics.Select(x => new Uri(x.GetAttributeValue("bigimgsrc", null).Split('?')[0]));

            return(ImageResponse.FromImages(urls));
        }
        /// <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));
        }
Exemple #8
0
 /// <inheritdoc />
 public override async Task <ImageResponse> GetImagesAsync(IDownloaderClient client)
 {
     if (IsAlbum)
     {
         var tasks = Images.Select(async x => await x.GetImagesAsync(client).CAF());
         var urls  = (await Task.WhenAll(tasks).CAF()).SelectMany(x => x.ImageUrls).ToArray();
         return(ImageResponse.FromImages(urls));
     }
     return(Mp4Url != null
                         ? ImageResponse.FromAnimated(Mp4Url)
                         : ImageResponse.FromUrl(PostUrl));
 }
Exemple #9
0
 /// <inheritdoc />
 public async Task <ImageResponse> GetImagesAsync(IDownloaderClient client)
 {
     if (ChildrenInfo.Nodes != null)
     {
         var tasks = ChildrenInfo.Nodes.Select(async x => await x.Child.GetImagesAsync(client).CAF());
         var urls  = (await Task.WhenAll(tasks).CAF()).SelectMany(x => x.ImageUrls).ToArray();
         return(ImageResponse.FromImages(urls));
     }
     return(VideoUrl != null
                         ? ImageResponse.FromAnimated(VideoUrl)
                         : ImageResponse.FromUrl(DisplayUrl));
 }
        /// <summary>
        /// Gets the images from the specified url.
        /// </summary>
        /// <param name="client"></param>
        /// <param name="url"></param>
        /// <returns></returns>
        public static async Task <ImageResponse> GetImgurImagesAsync(IDownloaderClient client, Uri url)
        {
            var u = DownloaderClient.RemoveQuery(url).ToString().Replace("_d", "");

            if (u.IsImagePath())
            {
                return(ImageResponse.FromUrl(new Uri(u)));
            }
            var id     = u.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries).Last();
            var images = await GetImgurImagesByCode(client, id).CAF();

            if (images.Count > 0)
            {
                var tasks = images.Select(async x => await x.GetImagesAsync(client).CAF());
                var urls  = (await Task.WhenAll(tasks).CAF()).SelectMany(x => x.ImageUrls).ToArray();
                return(ImageResponse.FromImages(urls));
            }
            return(ImageResponse.FromNotFound(url));
        }
Exemple #11
0
        /// <summary>
        /// Gets the images from the specified url.
        /// </summary>
        /// <param name="client"></param>
        /// <param name="url"></param>
        /// <returns></returns>
        public static async Task <ImageResponse> GetBcyImagesAsync(IDownloaderClient client, Uri url)
        {
            var u = DownloaderClient.RemoveQuery(url).ToString();

            if (u.IsImagePath())
            {
                return(ImageResponse.FromUrl(new Uri(u)));
            }
            var result = await client.GetHtmlAsync(() => client.GenerateReq(url)).CAF();

            if (!result.IsSuccess)
            {
                return(ImageResponse.FromNotFound(url));
            }
            var img     = result.Value.DocumentNode.Descendants("img");
            var details = img.Where(x => x.GetAttributeValue("class", "").CaseInsContains("detail_std"));
            var src     = details.Select(x => x.GetAttributeValue("src", ""));
            var urls    = src.Select(x => new Uri(x.Substring(0, x.LastIndexOf('/'))));

            return(src.Any() ? ImageResponse.FromImages(urls) : ImageResponse.FromNotFound(url));
        }
 /// <inheritdoc />
 public Task <ImageResponse> GetImagesAsync(IDownloaderClient client) => Task.FromResult(ImageResponse.FromImages(ImageUrls));
Exemple #13
0
 /// <inheritdoc />
 public Task <ImageResponse> GetImagesAsync(IDownloaderClient client) => Task.FromResult(ImageResponse.FromImages(Images.Select(x => x.FullImageUrl)));
Exemple #14
0
        /// <inheritdoc />
        public Task <ImageResponse> GetImagesAsync(IDownloaderClient client)
        {
            var images = Assets.Where(x => x.AssetType == "image").Select(x => x.ImageUrl);

            return(Task.FromResult(ImageResponse.FromImages(images)));
        }
Exemple #15
0
 /// <inheritdoc />
 public Task <ImageResponse> GetImagesAsync(IDownloaderClient client) => Task.FromResult(ImageResponse.FromImages(MediaAttachments.Select(x => x.Url)));