protected override async Task <string> GetRedirect(string url, CookieAwareWebClient client, CancellationToken cancellation) { using (client.SetUserAgent("Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)")) { return(Encoding.UTF8.GetString(Convert.FromBase64String(Reverse( Regex.Match(await client.DownloadStringTaskAsync(url), @"ysmm\s=\s'(.*?)'").Groups[1].Value))).Remove(0, 2)); } }
protected override async Task <string> DownloadAsyncInner(CookieAwareWebClient client, FlexibleLoaderGetPreferredDestinationCallback getPreferredDestination, FlexibleLoaderReportDestinationCallback reportDestination, Func <bool> checkIfPaused, IProgress <long> progress, CancellationToken cancellation) { using (client.SetUserAgent(CmApiProvider.CommonUserAgent)) using (client.SetDebugMode(OptionDebugMode)) using (client.SetAutoRedirect(!OptionManualRedirect)) { return(await base.DownloadAsyncInner(client, getPreferredDestination, reportDestination, checkIfPaused, progress, cancellation)); } }
protected override async Task <string> GetRedirectOverrideAsync(string url, CookieAwareWebClient client, CancellationToken cancellation) { using (client.SetUserAgent("Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)")) { var redirectTo = Reverse(Regex.Match(await client.DownloadStringTaskAsync(url), @"ysmm\s=\s'(.*?)'").Groups[1].Value); if (cancellation.IsCancellationRequested) { return(redirectTo); } if (Test(redirectTo)) { redirectTo = Unwrap(await client.DownloadStringTaskAsync(redirectTo)) ?? redirectTo; if (cancellation.IsCancellationRequested) { return(redirectTo); } } using (var stream = await client.OpenReadTaskAsync(redirectTo)) { if (cancellation.IsCancellationRequested) { return(redirectTo); } if (client.ResponseHeaders?.Get("Content-Type").Contains(@"text/html", StringComparison.OrdinalIgnoreCase) == true) { redirectTo = Unwrap((await stream.ReadAsBytesAsync()).ToUtf8String()) ?? redirectTo; } } return(redirectTo); } string Unwrap(string html) { var doc = new HtmlDocument(); doc.LoadHtml(html); return(doc.DocumentNode.Descendants(@"a") .FirstOrDefault(x => x.InnerText.Contains(@"click"))? .Attributes[@"href"]?.Value); } }