public void ExtendedSearch(TorrentUrl url) { Execute.Background(() => { try { HttpWebRequest request = HttpWebRequest.Create(url.InfoUrl) as HttpWebRequest; request.Timeout = Timeout; request.Method = WebRequestMethods.Http.Get; request.UserAgent = UserAgent; using (HttpWebResponse response = request.GetResponse() as HttpWebResponse) { using (Stream stream = response.GetResponseStream()) { var html = new HtmlDocument(); html.Load(stream); var uploaded = html.DocumentNode.SelectSingleNode("//dt[starts-with(text(), 'Uploaded')]"); var by = html.DocumentNode.SelectSingleNode("//dt[starts-with(text(), 'By')]"); var seeders = html.DocumentNode.SelectSingleNode("//dt[starts-with(text(), 'Seeders')]"); var leechers = html.DocumentNode.SelectSingleNode("//dt[starts-with(text(), 'Leechers')]"); var download = html.DocumentNode.SelectSingleNode("//div[@class='download']/a"); var details = new TorrentUrlDetails(url); details.TorrentUrl.Url = download.Attributes["href"].Value; details.CreatedOn = uploaded.NextSibling.NextSibling.InnerText.ToDate(); details.CreatedBy = HttpUtility.HtmlDecode(by.NextSibling.NextSibling.InnerText).Trim(); details.Seeds = seeders.NextSibling.NextSibling.InnerText.ToInt(); details.Peers = leechers.NextSibling.NextSibling.InnerText.ToInt(); var comments = html.DocumentNode.SelectNodes("//div[starts-with(@id, 'comment-')]"); if (comments != null) { var commentsList = new List <Comment>(comments.Count); foreach (var comment in comments) { var byLine = comment.FirstChild.ChildNodes[1]; commentsList.Add(new Comment { User = HttpUtility.HtmlDecode(byLine.InnerText).Trim(), CommentInfo = HttpUtility.HtmlDecode(byLine.NextSibling.InnerText).Trim(), Text = HttpUtility.HtmlDecode(comment.ChildNodes[1].InnerText).Trim(), }); } details.Comments = commentsList.ToArray(); } details.Files = new TorrentFile[0]; OnExtendedSearchCompleted(new ExtendedSearchEventArgs(details)); } } } catch (Exception exc) { OnExtendedSearchCompleted(new ExtendedSearchEventArgs(exc.Message)); } }); }
public UITableViewCell Load(TorrentUrl url) { _title.Text = url.Name; _category.Text = url.Category; _size.Text = url.Size; return _cell; }
public override void ExtendedSearch (TorrentUrl url) { #if !NUnit Execute.Background(() => { #endif try { if (string.IsNullOrEmpty(url.InfoUrl)) { throw new Exception("Could not find a URL to access this torrent's details."); } HttpWebRequest request = HttpWebRequest.Create(url.InfoUrl) as HttpWebRequest; request.Timeout = Timeout; request.Method = WebRequestMethods.Http.Get; using (HttpWebResponse response = request.GetResponse () as HttpWebResponse) { using (Stream stream = response.GetResponseStream ()) { TorrentUrlDetails details = new TorrentUrlDetails(url); HtmlDocument html = new HtmlDocument(); html.Load(stream); var table = html.DocumentNode.SelectSingleNode("//th[@style='background-color: #EEEEEE;']/div/table"); //Seeds and Peers string status = table.SelectSingleNode("//tr[3]/th[2]/font/b").InnerText; string[] split = status.Split('|'); string seeds = _seedsRegex.Replace(split[0], string.Empty), peers = _peersRegex.Replace(split[1], string.Empty); details.Seeds = seeds.Replace(",", string.Empty).ToLong(); details.Peers = peers.Replace(",", string.Empty).ToLong(); //Date and user string torrentBy = table.SelectSingleNode("//tr[3]/th[4]/font/b").InnerText; split = _byRegex.Split(torrentBy); details.CreatedOn = split[0].ToDate(); details.CreatedBy = HttpUtility.HtmlDecode(split[1]); //Comments var commentNodes = html.DocumentNode.SelectNodes("//div/table[@style='border-top: 1px solid #000000; border-left: 1px solid #000000; border-right: 1px solid #000000;']/tr/th"); var comments = new List<Comment>(); var comment = new Comment(); for (int i = 1; i < commentNodes.Count; i++) { HtmlNode node = commentNodes[i]; //User info, votes, etc. if (i % 2 == 1) { if (node.ChildNodes.Count < 6) { break; } comment.User = HttpUtility.HtmlDecode(node.ChildNodes[1].InnerText).Trim(); comment.UserInfo = HttpUtility.HtmlDecode(node.ChildNodes[3].InnerText).Trim(); comment.CommentInfo = HttpUtility.HtmlDecode(node.ChildNodes[5].InnerText).Trim(); } //Comment body else { comment.Text = HttpUtility.HtmlDecode(node.InnerText).Trim(); comments.Add(comment); comment = new Comment(); } } details.Comments = comments.ToArray(); //Files details.Files = html.DocumentNode .SelectNodes("//table[@class='tor_details']/tr/th/font") .Select(n => new TorrentFile { Name = HttpUtility.HtmlDecode(_fileSizeRegex.Replace(n.InnerText, string.Empty)).Trim(), Size = HttpUtility.HtmlDecode(_fileSizeRegex.Match(n.InnerText).Groups[1].Value).Trim(), }) .ToArray(); OnExtendedSearchCompleted(new ExtendedSearchEventArgs(details)); } } } catch (Exception exc) { OnExtendedSearchCompleted(new ExtendedSearchEventArgs(exc.Message)); } #if !NUnit }); #endif }
public virtual void ExtendedSearch(TorrentUrl url) { }
public TorrentUrlDetails(TorrentUrl torrent) { TorrentUrl = torrent; }