Ejemplo n.º 1
0
        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));
                }
            });
        }
Ejemplo n.º 2
0
 public void Refresh()
 {
     if (string.IsNullOrEmpty(_settings.Url))
     {
         _hub.Publish(new EmptyUrlMessage(this));
     }
     else
     {
         Execute.Background(_server.StartPolling);
     }
 }
Ejemplo n.º 3
0
 private void SendToServer(Action action)
 {
     Execute.Background(() =>
     {
         try
         {
             action();
             _server.StartPolling();
         }
         catch (Exception exc)
         {
             Execute.BeginInvoke(() => MessageBox.Show(exc.Message, "Error"));
         }
     });
 }
Ejemplo n.º 4
0
 public void Search(string searchText)
 {
     Execute.Background(() =>
     {
         try
         {
             HttpWebRequest request = HttpWebRequest.Create(BuildUrl(searchText)) as HttpWebRequest;
             request.Timeout        = Timeout;
             request.Method         = WebRequestMethods.Http.Get;
             request.UserAgent      = "Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727)";
             using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
             {
                 using (Stream stream = response.GetResponseStream())
                 {
                     OnRssCompleted((Rss)_serializer.Deserialize(stream));
                 }
             }
         }
         catch (Exception exc)
         {
             OnSearchCompleted(new SearchEventArgs(exc.Message));
         }
     });
 }
Ejemplo n.º 5
0
        public void Search(string searchText)
        {
            Execute.Background(() =>
            {
                try
                {
                    HttpWebRequest request = HttpWebRequest.Create(string.Format(Url, HttpUtility.UrlEncode(searchText).Replace("%20", "+"))) 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 baseUrl      = new Uri(BaseUrl);
                            var urls         = new List <TorrentUrl>();
                            var links        = html.DocumentNode.SelectNodes("//div[@class='detName']/a");
                            var categories   = html.DocumentNode.SelectNodes("//td[@class='vertTh']/center/a[2]");
                            var descriptions = html.DocumentNode.SelectNodes("//font[@class='detDesc']");

                            HtmlNode link;
                            Uri infoUrl;
                            string[] sizeSplit;
                            string size;
                            for (int i = 0; i < links.Count; i++)
                            {
                                link      = links[i];
                                infoUrl   = new Uri(baseUrl, link.Attributes["href"].Value);
                                sizeSplit = descriptions[i].InnerText.Split(',');
                                if (sizeSplit.Length > 1)
                                {
                                    size      = HttpUtility.HtmlDecode(sizeSplit[1]);
                                    sizeSplit = size.Split(' ');
                                    size      = sizeSplit.Last().Replace("iB", "B");
                                }
                                else
                                {
                                    size = null;
                                }

                                urls.Add(new TorrentUrl
                                {
                                    Name     = HttpUtility.HtmlDecode(link.Attributes["title"].Value.Replace("Details for", string.Empty)).Trim(),
                                    InfoUrl  = infoUrl.ToString(),
                                    Url      = BaseUrl + link.ParentNode.NextSibling.NextSibling.Attributes["href"].Value,
                                    Category = categories[i].InnerText.Trim(),
                                    Size     = size.Trim(),
                                });
                            }

                            OnSearchCompleted(new SearchEventArgs(urls.ToArray()));
                        }
                    }
                }
                catch (Exception exc)
                {
                    OnSearchCompleted(new SearchEventArgs(exc.Message));
                }
            });
        }
Ejemplo n.º 6
0
		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
		}