/// <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 #2
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 #3
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));
 }
Exemple #4
0
 /// <inheritdoc />
 public override Task <ImageResponse> GetImagesAsync(IDownloaderClient client)
 {
     return(Mp4Url != null
                         ? Task.FromResult(ImageResponse.FromAnimated(Mp4Url))
                         : Task.FromResult(ImageResponse.FromUrl(PostUrl)));
 }