private void Button_Click_2(object sender, RoutedEventArgs e) { if (ruleListBox.SelectedIndex < 0) { return; } loadingBar.IsIndeterminate = true; RuleItemModel ruleItem = RuleList[ruleListBox.SelectedIndex]; string baseUrl = ruleItem.source.Replace("XXX", keyword.Text); string nameTag = ruleItem.group; List <MovieItemModel> movieList = new List <MovieItemModel>(); HttpUtil.Instance.RequestGetAsync(baseUrl, (HTTPClientResponse r) => { loadingBar.IsIndeterminate = false; var nodes = r.node.SelectNodes(nameTag); if (nodes == null) { return; } foreach (var node in nodes) { MovieItemModel movieItem = MovieItemModel.ModelWithDocument(node, ruleItem); movieList.Add(movieItem); } resultListView.ItemsSource = movieList; }); }
public static MovieItemModel ModelWithDocument(HtmlNode pNode, RuleItemModel ruleItem) { MovieItemModel movieItem = new MovieItemModel(); var node = pNode.SelectNodes(ruleItem.magnet)[0]; string firstMagnet = node.Attributes["href"].Value; if (firstMagnet.StartsWith(".html") || firstMagnet.EndsWith(".html")) { firstMagnet = firstMagnet.Replace(".html", ""); } if (firstMagnet.Split('&').Length > 1) { firstMagnet = firstMagnet.Split('&')[0]; } string magnet = firstMagnet.Substring(firstMagnet.Length - 40, 40); movieItem.magnet = String.Format("magnet:?xt=urn:btih:{0}", magnet); movieItem.name = node.InnerText; node = FirstChildWIthXPath(pNode, ruleItem.size); movieItem.size = node.InnerText; movieItem.count = FirstChildWIthXPath(pNode, ruleItem.count).InnerText; movieItem.source = ruleItem.site; return(movieItem); }