/// <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)); }
/// <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)); }
/// <summary> /// Gets the images from the specified url. /// </summary> /// <param name="client"></param> /// <param name="url"></param> /// <returns></returns> public static async Task <ImageResponse> GetPawooImagesAsync(IDownloaderClient client, Uri url) { var u = DownloaderClient.RemoveQuery(url).ToString(); if (u.IsImagePath()) { return(ImageResponse.FromUrl(new Uri(u))); } const string search = "/statuses/"; if (u.CaseInsIndexOf(search, out var index)) { var id = u.Substring(index + search.Length).Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries)[0]; if (await GetPawooPostAsync(client, id).CAF() is Model post) { return(await post.GetImagesAsync(client).CAF()); } } if (u.Contains("@")) { var id = u.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries).Last(); if (await GetPawooPostAsync(client, id).CAF() is Model post) { return(await post.GetImagesAsync(client).CAF()); } } return(ImageResponse.FromNotFound(url)); }
/// <summary> /// Gets the images from the specified url. /// </summary> /// <param name="client"></param> /// <param name="url"></param> /// <returns></returns> public static async Task <ImageResponse> GetRedditImagesAsync(IDownloaderClient client, Uri url) { var u = DownloaderClient.RemoveQuery(url).ToString(); if (u.IsImagePath()) { return(ImageResponse.FromUrl(new Uri(u))); } const string search = "/comments/"; if (u.CaseInsIndexOf(search, out var index)) { var id = u.Substring(index + search.Length).Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries)[0]; if (await GetRedditPostAsync(id).CAF() is Model model) { return(await model.GetImagesAsync(client).CAF()); } } var parts = url.LocalPath.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries); if (parts.Length == 1 && await GetRedditPostAsync(parts[0]).CAF() is Model post) { return(await post.GetImagesAsync(client).CAF()); } return(ImageResponse.FromNotFound(url)); }
/// <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> 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)); }
/// <inheritdoc /> public async Task <ImageResponse> GetImagesAsync(IDownloaderClient client) { if (Post.Url.ToString().IsImagePath()) { return(ImageResponse.FromUrl(Post.Url)); } if (client.Gatherers.SingleOrDefault(x => x.IsFromWebsite(Post.Url)) is IImageGatherer gatherer) { return(await gatherer.FindImagesAsync(client, Post.Url).CAF()); } return(ImageResponse.FromNotFound(PostUrl)); }
/// <summary> /// Gets the images from the specified url. /// </summary> /// <param name="client"></param> /// <param name="url"></param> /// <returns></returns> public static async Task <ImageResponse> GetDeviantArtImagesAsync(IDownloaderClient client, Uri url) { var u = DownloaderClient.RemoveQuery(url).ToString(); if (u.IsImagePath()) { return(ImageResponse.FromUrl(new Uri(u))); } if (await GetDeviantArtPostAsync(client, url).CAF() is DeviantArtOEmbedPost post) { return(await post.GetImagesAsync(client).CAF()); } return(ImageResponse.FromNotFound(url)); }
/// <inheritdoc /> public Task <ImageResponse> GetImagesAsync(IDownloaderClient client) { if (Uri.TryCreate(FileUrl, UriKind.Absolute, out var url) || Uri.TryCreate($"{BaseUrl}{FileUrl}", UriKind.Absolute, out url)) { if (url.Scheme != Uri.UriSchemeHttp && url.Scheme != Uri.UriSchemeHttps) { url = new Uri($"https:{url.ToString().Substring(url.ToString().IndexOf("//"))}"); } return(Task.FromResult(ImageResponse.FromUrl(url))); } return(Task.FromResult(ImageResponse.FromNotFound(PostUrl))); }
/// <summary> /// Gets the images from the specified url. /// </summary> /// <param name="client"></param> /// <param name="url"></param> /// <returns></returns> public static async Task <ImageResponse> GetZerochanImagesAsync(IDownloaderClient client, Uri url) { var u = DownloaderClient.RemoveQuery(url).ToString(); if (u.IsImagePath()) { return(ImageResponse.FromUrl(new Uri(u))); } var parts = url.LocalPath.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries); if (parts.Length == 1 && int.TryParse(parts[0], out var val) && await GetZerochanPostAsync(client, val.ToString()).CAF() is Model post) { return(await post.GetImagesAsync(client).CAF()); } return(ImageResponse.FromNotFound(url)); }
/// <summary> /// Gets images from the specified url. /// </summary> /// <param name="client"></param> /// <param name="url"></param> /// <returns></returns> public static async Task <ImageResponse> GetGelbooruImagesAsync(IDownloaderClient client, Uri url) { var u = DownloaderClient.RemoveQuery(url).ToString(); if (u.IsImagePath()) { return(ImageResponse.FromUrl(new Uri(u))); } var id = HttpUtility.ParseQueryString(url.Query)["id"]; if (id != null && await GetGelbooruPostAsync(client, id).CAF() is Model post) { return(await post.GetImagesAsync(client).CAF()); } return(ImageResponse.FromNotFound(url)); }
/// <summary> /// Gets the images from the specified url. /// </summary> /// <param name="client"></param> /// <param name="url"></param> /// <returns></returns> public static async Task <ImageResponse> GetWeiboImagesAsync(IDownloaderClient client, Uri url) { var u = DownloaderClient.RemoveQuery(url).ToString(); if (u.IsImagePath()) { return(ImageResponse.FromUrl(new Uri(u))); } //Url is formatted something like this https://weibo.com/1632765501/GijfWif2d var parts = url.LocalPath.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries); if (parts.Length == 2 && await GetWeiboPostAsync(client, parts[1]).CAF() is Model post) { return(await post.GetImagesAsync(client).CAF()); } return(ImageResponse.FromNotFound(url)); }
/// <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)); }
/// <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)); }
/// <summary> /// Gets the images from the specified url. /// </summary> /// <param name="client"></param> /// <param name="url"></param> /// <returns></returns> public static async Task <ImageResponse> GetTumblrImagesAsync(IDownloaderClient client, Uri url) { var u = GetFullSizeTumblrImage(DownloaderClient.RemoveQuery(url)).ToString().Replace("/post/", "/image/"); if (u.IsImagePath()) { return(ImageResponse.FromUrl(new Uri(u))); } var searches = new[] { "/image/", "/post/" }; foreach (var search in searches) { if (u.CaseInsIndexOf(search, out var index)) { var username = url.Host.Split('.')[0]; var id = u.Substring(index + search.Length).Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries)[0]; if (await GetTumblrPostAsync(client, username, id).CAF() is Model post) { return(await post.GetImagesAsync(client).CAF()); } } } return(ImageResponse.FromNotFound(url)); }
/// <inheritdoc /> public Task <ImageResponse> GetImagesAsync(IDownloaderClient client) { return(Task.FromResult(Post.HasImage ? ImageResponse.FromUrl(new Uri($"http://i.4cdn.org/{Post.Board}/{Post.FileName}{Post.FileExtension}")) : ImageResponse.FromNotFound(PostUrl))); }