/// <summary> /// Asynchronously downloads the specified link. /// </summary> /// <param name="link"> /// The object containing the link. /// This can be an URL in a string or a <c>Link</c>/<c>Subtitle</c> object. /// </param> /// <param name="target">The target location.</param> /// <param name="token">The user token.</param> public void Download(object link, string target, string token = null) { string url; if (link is string) { url = link as string; } else if (link is Link) { url = (link as Link).FileURL; } else if (link is Subtitle) { url = (link as Subtitle).FileURL; } else { throw new Exception("The link object is an unsupported type."); } // we need to check if the URL is really an HTTP link. // if we don't do this, the software could be exploited into running any command if (!Regex.IsMatch(url, @"(https?|ftp)://", RegexOptions.IgnoreCase)) { throw new Exception("The specified URL doesn't look like a HTTP/FTP link."); } DownloadProgressChanged.Fire(this, 50); Utils.Run(url); DownloadProgressChanged.Fire(this, 100); DownloadFileCompleted.Fire(this, null, null, "LaunchedBrowser"); }
/// <summary> /// Downloads the specified subtitle from subscene. /// </summary> /// <param name="url">The URL of the subtitle page.</param> /// <param name="target">The target location.</param> /// <param name="token">The user token.</param> private void InternalDownload(string url, string target, string token) { // get the info page var info = Utils.GetHTML(url); DownloadProgressChanged.Fire(this, 25); // extract the download link var dllink = "http://simple.podnapisi.net" + info.DocumentNode.GetNodeAttributeValue("//img[@title='Download']/..", "href"); if (dllink == "http://simple.podnapisi.net") { DownloadFileCompleted.Fire(this, null, null, null); return; } // pass the rest of the work to HTTPDownloader _dl = new HTTPDownloader(); _dl.DownloadProgressChanged += (s, e) => DownloadProgressChanged.Fire(this, e.Data); _dl.DownloadFileCompleted += (s, e) => DownloadFileCompleted.Fire(this, e.First, e.Second, e.Third); _dl.Download(dllink, target, token); }
/// <summary> /// Downloads the specified subtitle from subscene. /// </summary> /// <param name="url">The URL of the subtitle page.</param> /// <param name="target">The target location.</param> /// <param name="token">The user token.</param> private void InternalDownload(string url, string target, string token) { // get the info page var info = Utils.GetJSON("http://aliensubtitles.com/?d=" + Regex.Match(url, "/download#([0-9a-z]+)").Groups[1].Value + "&a=3a2677106d44d238f13ba200dd9ff53454af87a6"); DownloadProgressChanged.Fire(this, 25); // check download link if (info["url"] == null) { DownloadFileCompleted.Fire(this, null, null, null); return; } // pass the rest of the work to HTTPDownloader _dl = new HTTPDownloader(); _dl.DownloadProgressChanged += (s, e) => DownloadProgressChanged.Fire(this, e.Data); _dl.DownloadFileCompleted += (s, e) => DownloadFileCompleted.Fire(this, e.First, e.Second, e.Third); _dl.Download((string)info["url"], target, token); }
/// <summary> /// Downloads the specified subtitle from subscene. /// </summary> /// <param name="url">The URL of the subtitle page.</param> /// <param name="target">The target location.</param> /// <param name="token">The user token.</param> private void InternalDownload(string url, string target, string token) { var parts = url.Split(';'); var nzb = Utils.GetURL(parts[0], parts[1], encoding: new Utils.Base64Encoding()); DownloadProgressChanged.Fire(this, 75); File.WriteAllBytes(target, Convert.FromBase64String(nzb)); DownloadProgressChanged.Fire(this, 100); DownloadFileCompleted.Fire(this, target, parts[2], token ?? string.Empty); }
/// <summary> /// Downloads the specified subtitle from subscene. /// </summary> /// <param name="url">The URL of the subtitle page.</param> /// <param name="target">The target location.</param> /// <param name="token">The user token.</param> private void InternalDownload(string url, string target, string token) { // get the info page var info = Utils.GetURL(url); DownloadProgressChanged.Fire(this, 25); // extract required info var dllink = "http://subscene.com" + Regex.Match(info, "href=\"([^\"]+)\".*?id=\"downloadButton\"", RegexOptions.IgnoreCase).Groups[1].Value; // pass the rest of the work to HTTPDownloader _dl = new HTTPDownloader(); _dl.DownloadProgressChanged += (s, e) => DownloadProgressChanged.Fire(this, e.Data); _dl.DownloadFileCompleted += (s, e) => DownloadFileCompleted.Fire(this, e.First, e.Second, e.Third); _dl.Download(dllink, target, token); }
/// <summary> /// Asynchronously downloads the specified link. /// </summary> /// <param name="link"> /// The object containing the link. /// This can be an URL in a string or a <c>Link</c>/<c>Subtitle</c> object. /// </param> /// <param name="target">The target location.</param> /// <param name="token">The user token.</param> public void Download(object link, string target, string token = null) { var id = Utils.Rand.Next(short.MaxValue); var st = DateTime.Now; _wc = new Utils.SmarterWebClient(); Uri uri; if (link is string) { uri = new Uri(link as string); } else if (link is Link) { uri = new Uri((link as Link).FileURL); if (!string.IsNullOrWhiteSpace((link as Link).Source.Cookies)) { _wc.Headers[HttpRequestHeader.Cookie] = (link as Link).Source.Cookies; } } else if (link is Subtitle) { uri = new Uri((link as Subtitle).FileURL); if (!string.IsNullOrWhiteSpace((link as Subtitle).Source.Cookies)) { _wc.Headers[HttpRequestHeader.Cookie] = (link as Subtitle).Source.Cookies; } } else { throw new Exception("The link object is an unsupported type."); } var domain = uri.Host.Replace("www.", string.Empty); Log.Debug("HTTP#{0} GET {1}", new[] { id.ToString(), uri.ToString() }); _wc.Headers[HttpRequestHeader.Referer] = "http://" + uri.DnsSafeHost + "/"; _wc.DownloadProgressChanged += (s, e) => DownloadProgressChanged.Fire(this, e.ProgressPercentage); _wc.DownloadFileCompleted += (s, e) => { Log.Debug("HTTP#" + id + " [" + domain + "] is " + Utils.GetFileSize(new FileInfo(target).Length) + " and took " + (DateTime.Now - st).TotalSeconds + "s."); if (Log.IsTraceEnabled) { Log.Trace("HTTP#" + id + " [" + domain + "] is " + (s as Utils.SmarterWebClient).ContentType + ", saved to " + target + " with token " + token); } DownloadFileCompleted.Fire(this, target, (s as Utils.SmarterWebClient).FileName, token ?? string.Empty); }; var proxy = default(string); var proxyId = default(object); if (Settings.Get <Dictionary <string, object> >("Proxied Domains").TryGetValue(domain, out proxyId)) { proxy = (string)Settings.Get <Dictionary <string, object> >("Proxies")[(string)proxyId]; } if (proxy != null) { var proxyUri = new Uri(proxy.Replace("$domain.", string.Empty)); switch (proxyUri.Scheme.ToLower()) { case "http": if (proxy.Contains("$url")) { uri = new Uri(proxy.Replace("$url", Utils.EncodeURL(uri.ToString()))); } else if (proxy.Contains("$domain") && proxy.Contains("$path")) { uri = new Uri(proxy.Replace("$domain", uri.DnsSafeHost).Replace("$path", uri.AbsolutePath)); } else { _wc.Proxy = new WebProxy(proxyUri.Host + ":" + proxyUri.Port); } break; case "socks4": case "socks4a": case "socks5": var tunnel = new HttpToSocks { RemoteProxy = HttpToSocks.Proxy.ParseUri(proxyUri) }; tunnel.Listen(); _wc.Proxy = (WebProxy)tunnel.LocalProxy; break; } Log.Debug("HTTP#" + id + " [" + domain + "] is proxied through " + proxyId + " (" + proxyUri + ")"); } _wc.DownloadFileAsync(uri, target); }