Ejemplo n.º 1
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> 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));
        }
Ejemplo n.º 2
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> 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));
        }
Ejemplo n.º 3
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> 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));
        }
Ejemplo n.º 4
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> 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));
        }
Ejemplo n.º 5
0
        private async Task Gatherer_Test <T>(string input) where T : IImageGatherer, new()
        {
            var client   = new DownloaderClient();
            var gatherer = new T();

            var url = new Uri(input);

            Assert.IsTrue(gatherer.IsFromWebsite(url), $"Unable to verify that {input} is from {typeof(T).Name}.");
            var results = await gatherer.FindImagesAsync(client, url).CAF();

            Assert.AreNotEqual(0, results.ImageUrls.Length, $"Unable to find any images for {typeof(T).Name}");
        }
Ejemplo n.º 6
0
        public async void OnStartAsync(string url)
        {
            try
            {
                DownloaderClient client = new DownloaderClient();
                await client.Create_joblistAsync(url);

                _jobs = client.getJobs();
                statusgroup.setLengthPlaylist(_jobs.Count);
                statusgroup.UpdateThreadText(_threadStatus[0]);

                if (_jobs.Count == 0)
                {
                    await client.Create_joblistAsync(url);

                    statusgroup.UpdateThreadText(_threadStatus[0]);
                }
                if (statusgroup.getProgressCounter() > 0)
                {
                    statusgroup.resetProgressCounter();
                }

                while (true)
                {
                    if (_jobs.Count > 0)
                    {
                        statusgroup.UpdateThreadText(_threadStatus[1]);
                        var job = _jobs[0];
                        _jobs.RemoveAt(0);
                        await client.start_downloadAsync(job.Id);

                        statusgroup.Updatelbl(_jobs.Count, job.Title);
                        statusgroup.addProgressCounter();
                        statusgroup.UpdateUI();
                        Thread.Sleep(1000);
                    }
                    else
                    {
                        Thread.Sleep(1000);
                    }
                    if (_jobs.Count == 0)
                    {
                        statusgroup.UpdateThreadText(_threadStatus[2]);
                        _Downloader.Abort();
                    }
                }
            }
            catch (Exception ex)
            {
                Mainform main = new Mainform();
                lbl_invoke.Invoke(new UpdateMbox(UpdateMboxes), ex.Message);
            }
        }
Ejemplo n.º 7
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> 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));
        }
Ejemplo n.º 8
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> 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));
        }
Ejemplo n.º 9
0
        /// <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));
        }
Ejemplo n.º 10
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> 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));
        }
        private async void btn_download_ClickAsync(object sender, EventArgs e)
        {
            string           url    = txt_url.Text;
            DownloaderClient client = new DownloaderClient();
            string           id     = client.GetVideoID(url);
            await client.start_downloadAsync(id);

            Download download = client.GetDownload();

            if (download.getError() != string.Empty)
            {
                MessageBox.Show(download.getError());
            }
            else
            {
                UpdateInfoPanel(download.getTitle(), download.getAuthor(), download.getDuration());
            }
        }
Ejemplo n.º 12
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> 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));
        }
Ejemplo n.º 13
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));
        }
Ejemplo n.º 14
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> 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));
        }