private async void Func_NMBRecordAsync(string qName, string keyword) { //XGlobal.RebuildSubDirTemp(); listInformation.SelectedIndex = listInformation.Items.Add($"QUERY: {NewMovieQuerySite.QUri.Host.ToUpper()} / KEY: {keyword}..."); Uri uri_search = new Uri($"{NewMovieQuerySite.QUri}ja/search/{WebUtility.UrlEncode(keyword.Trim())}"); var streamresult = (await XService.Func_Net_ReadWebData(uri_search)).response; if (streamresult.Contains("System.Net.Http.HttpRequestException:")) { System.Diagnostics.Debug.WriteLine(uri_search.ToString()); System.Diagnostics.Debug.WriteLine(streamresult); return; } if (streamresult == HttpStatusCode.NotFound.ToString()) { MessageBox.Show("404", "Key Words Mismatch"); txtNMKeyword.Focus(); return; } CurrentHtmlDocument.LoadHtml(streamresult); HtmlNode hnode = CurrentHtmlDocument.DocumentNode; HtmlNode _errornode = null; switch (NewMovieQuerySite.QName) { case "CSite": case "USite": _errornode = hnode.SelectSingleNode("//div[@class='alert alert-block alert-error']"); break; case "BSite": _errornode = hnode.SelectSingleNode("//div[@class='alert alert-danger alert-page']"); break; case "LSite": break; default: break; } if (_errornode != null) { gbNMQueryResult.Header = $"Query Result: {_errornode.SelectSingleNode("./h4").InnerText}"; MessageBox.Show(_errornode.InnerText, "Key Words Mismatch"); txtNMKeyword.Focus(); return; } #region 讀取搜索結果 NewMovieQueryResult.Clear(); HtmlNodeCollection node_results = CurrentHtmlDocument.DocumentNode.SelectNodes("//div[@class='item']"); gbNMQueryResult.Header = $"Query Result: {NewMovieQuerySite.QUri.Host.ToUpper()} / {keyword} / {node_results.Count}"; foreach (HtmlNode _node in node_results) { Stream tempimg = await XService.Func_Net_ReadWebStream(_node.SelectSingleNode(".//img").Attributes["src"].Value, uri_search); QueryResultMovieInfo mi = new QueryResultMovieInfo { ReleaseID = _node.SelectSingleNode(".//date[1]").InnerText }; _node.SelectSingleNode(".//span[1]/date[1]").Remove(); mi.ReleaseDateTicks = Convert.ToDateTime(_node.SelectSingleNode(".//date[1]").InnerText).Ticks; _node.SelectSingleNode(".//span[1]/date[1]").Remove(); _node.SelectSingleNode(".//span[1]/div[1]").Remove(); mi.ReleaseName = _node.SelectSingleNode(".//span[1]").InnerText.Trim(new char[] { ' ', '/' }); //gi.Glyph = new BitmapImage() { StreamSource = tempimg }; mi.MovieCoverImage = new ImageSourceConverter().ConvertFrom(tempimg) as ImageSource; mi.OfficialWeb = XService.UrlCheck(_node.SelectSingleNode(".//a[1]").Attributes["href"].Value); NewMovieQueryResult.Add(mi); } #endregion /** **/ }
private async void Func_NMLRecordAsync(string qName, string keyword) { //XGlobal.RebuildSubDirTemp(); listInformation.SelectedIndex = listInformation.Items.Add($"QUERY: {NewMovieQuerySite.QUri.Host.ToUpper()} / KEY: {keyword}..."); Uri uri_search = new Uri($"{NewMovieQuerySite.QUri}ja/vl_searchbyid.php?keyword={WebUtility.UrlEncode(keyword.Trim())}"); var(response, requestmessage) = await XService.Func_Net_ReadWebData(uri_search); var streamresult = response; var request = requestmessage; if (streamresult.Contains("System.Net.Http.HttpRequestException:")) { System.Diagnostics.Debug.WriteLine(uri_search.ToString()); System.Diagnostics.Debug.WriteLine(streamresult); return; } if (streamresult == HttpStatusCode.NotFound.ToString()) { MessageBox.Show("404", "Key Words Mismatch"); txtNMKeyword.Focus(); return; } CurrentHtmlDocument.LoadHtml(streamresult); HtmlNode hnode = CurrentHtmlDocument.DocumentNode; HtmlNode _errornode = null; _errornode = hnode.SelectSingleNode("//div[@id='rightcolumn']//em"); if (_errornode != null && _errornode.InnerText.Contains("ご指定の検索条件に合う項目がありませんでした")) { gbNMQueryResult.Header = $"Query Result: ご指定の検索条件に合う項目がありませんでした"; MessageBox.Show(_errornode.InnerText, "Key Words Mismatch"); txtNMKeyword.Focus(); return; } if (request.RequestUri.PathAndQuery.Contains("searchbyid")) { //Records list #region 讀取搜索結果 NewMovieQueryResult.Clear(); HtmlNodeCollection node_results = CurrentHtmlDocument.DocumentNode.SelectNodes("//div[@class='videothumblist']//div[@class='video']"); gbNMQueryResult.Header = $"Query Result: {NewMovieQuerySite.QUri.Host.ToUpper()} / {keyword} / {node_results.Count}"; foreach (HtmlNode _node in node_results) { Stream tempimg = await XService.Func_Net_ReadWebStream(_node.SelectSingleNode(".//img").Attributes["src"].Value, uri_search); QueryResultMovieInfo mi = new QueryResultMovieInfo { ReleaseID = _node.SelectSingleNode(".//div[@class='id']").InnerText.Trim(), ReleaseName = _node.SelectSingleNode(".//div[@class='title']").InnerText.Trim(), MovieCoverImage = new ImageSourceConverter().ConvertFrom(tempimg) as ImageSource }; string reurl = _node.SelectSingleNode(".//a[1]").Attributes["href"].Value; if (reurl.StartsWith("./")) { reurl = reurl.Replace("./", $"{NewMovieQuerySite.QUri}ja/"); } mi.OfficialWeb = reurl; NewMovieQueryResult.Add(mi); }//end foreach in node_results #endregion } else { Func_NMResolveLResult(request.RequestUri.OriginalString); } }