Esempio n. 1
0
        public async Task Async_ResponseURI_InputHttpBinGoOrg_ResultGoogleCom()
        {
            await _wc.DownloadStringTaskAsync("https://httpbingo.org/redirect-to?url=https://google.com/");

            Assert.IsTrue(new Regex(@"^https?:\/\/(?:www\.)?google\.com\/?$")
                          .IsMatch(_wc.ResponseURI.ToString()));
        }
Esempio n. 2
0
        public override async Task <MemeInfo> RandomAsync()
        {
            WebClientPlus wc;
            string        html;

            try
            {
                wc   = new WebClientPlus();
                html = await wc.DownloadStringTaskAsync(_uris[UriType.Random]);
            }
            catch (WebException ex)
            {
                throw new ServiceOrConnectionException("Could not load the page", ex);
            }

            IConfiguration   config   = Configuration.Default;
            IBrowsingContext context  = BrowsingContext.New(config);
            IDocument        document = await context.OpenAsync(req => req.Content(html).Address(_baseUrl));

            IElement picDiv = document.DocumentElement.QuerySelector("#main_container .pic");

            IHtmlImageElement img =
                (IHtmlImageElement)picDiv.QuerySelector(".pic_image img");

            IHtmlHeadingElement h =
                (IHtmlHeadingElement)picDiv.QuerySelector("h1.picture");

            if (img == null || h == null)
            {
                throw new NotFoundException("Either \"img\" or \"h1\" tag could not be found");
            }

            return(new MemeInfo
            {
                ViewURI = wc.ResponseURI.ToString(),
                URI = img.Source,
                Alt = img.AlternativeText,
                Name = h.TextContent
            });
        }
        public async void BuscaLegenda(Episodio episodio)
        {
            string urlLegenda = "http://legendas.tv/util/carrega_legendas_busca/{0}/1/d";
            string urlDownload = "http://legendas.tv/downloadarquivo/{0}";

            HtmlAgilityPack.HtmlDocument html = new HtmlAgilityPack.HtmlDocument();

            using (WebClientPlus webClient = new WebClientPlus())
            {
                try
                {
                    webClient.OutboundCookies.Add(cookieAuth);
                    var htmlString = await webClient.DownloadStringTaskAsync(String.Format(urlLegenda, episodio.Nome));
                    html.LoadHtml(htmlString);

                    string idLegenda = String.Empty;

                    var links = html.DocumentNode.SelectNodes("//p//a[ contains (@href, 'download') ]");

                    if (links == null)
                    {
                        episodio.Download = "Erro";
                        episodio.Status = "Legenda não encontrada.";
                    }
                    else
                    {
                        foreach (var link in links)
                        {
                            idLegenda = link.Attributes["href"].Value.Replace("/download/", "");
                            idLegenda = idLegenda.Substring(0, idLegenda.IndexOf('/'));
                        }

                        var uriDownload = new Uri(String.Format(urlDownload, idLegenda));
                        var nomeArquivoDownload = String.Format("{0}{1}.rar", pastaDownloads, idLegenda);

                        episodio.ArquivoDownload = nomeArquivoDownload;

                        if (!File.Exists(nomeArquivoDownload))
                        {
                            webClient.DownloadFileAsync(uriDownload, nomeArquivoDownload, episodio);
                            webClient.DownloadFileCompleted += webClient_DownloadFileCompleted;
                            webClient.DownloadProgressChanged += webClient_DownloadProgressChanged;
                        }
                        else
                        {
                            episodio.Download = "100";
                            ExtrairLegenda(episodio);
                        }

                        dgvEpisodios.FirstDisplayedScrollingRowIndex = dgvEpisodios.Rows.Count - 1;
                        dgvEpisodios.Update();
                    }
                }
                catch
                {
                    episodio.Download = "Erro";
                    episodio.Status = "Ocorreu um erro na busca da legenda.";
                }
            }
        }