コード例 #1
0
        private async Task <bool> Func_AnalysisMovie_Cover(HtmlNode sourcenode)
        {
            NewMovieInfo.CoverWebUrl = XService.UrlCheck(sourcenode.SelectSingleNode("//a[@class='bigImage']/img").Attributes["src"].Value);
            Uri coveruri = new Uri(NewMovieInfo.CoverWebUrl);

            NewMovieInfo.CoverFileName = System.IO.Path.Combine(NewMovieInfo.SourcePath, coveruri.Segments[coveruri.Segments.Length - 1]);

            listInformation.SelectedIndex = listInformation.Items.Add($"創建影片封面 {NewMovieInfo.CoverFileName} ...");
            var coverimage = new ImageSourceConverter().ConvertFrom(coveruri);

            using (Stream temp = await XService.Func_Net_ReadWebStream(coveruri, new Uri(NewMovieInfo.OfficialWeb)))
            {
                if (temp != Stream.Null)
                {
                    if (File.Exists(NewMovieInfo.CoverFileName))
                    {
                        File.Delete(NewMovieInfo.CoverFileName);
                    }
                    using (FileStream sourceStream = new FileStream(
                               NewMovieInfo.CoverFileName,
                               FileMode.Create,
                               FileAccess.Write,
                               FileShare.ReadWrite,
                               bufferSize: 4096,
                               useAsync: true))
                    {
                        temp.Seek(0, SeekOrigin.Begin);
                        await temp.CopyToAsync(sourceStream);

                        await sourceStream.FlushAsync();
                    }
                }
            }
            return(true);
        }
コード例 #2
0
        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

            /**
            **/
        }
コード例 #3
0
        private async Task <bool> Func_AnalysisStars(HtmlNode sourcenode)
        {
            NewMovieStars.Clear();
            listInformation.SelectedIndex = listInformation.Items.Add("READ: STARS...");

            HtmlNodeCollection _hncc = sourcenode.SelectNodes("//a[@class='avatar-box']");

            string name_ja = string.Empty;

            NewMovieInfo.ActorUIDs = new List <Guid>();

            if (_hncc == null)
            {
                MessageBox.Show($"No movie information from{NewMovieQuerySite.QName.ToUpper()}.\nTry other web source.", "數據缺損");
                //return false;
            }
            else
            {
                foreach (HtmlNode _node in _hncc)
                {
                    bool is_star_stored = true;
                    name_ja = XService.IllegalFiltered(_node.SelectSingleNode(".//span").InnerText.Trim());
                    StarInfo star = XGlobal.CurrentContext.TotalStars.Find(s => s.JName == name_ja);
                    if (star is null)
                    {
                        star           = new StarInfo(name_ja);
                        is_star_stored = false;
                    }

                    //Read Avator to Stream
                    listInformation.SelectedIndex = listInformation.Items.Add($"CREATE: DIR/{star.JName}/TEMP");

                    star.AvatorWebUrl = XService.UrlCheck(_node.SelectSingleNode(".//img").Attributes["src"].Value);
                    //star.CreateStarDirectoryTemp();
                    star.CreateLocalStarDirectory(NewMovieInfo);

                    Stream temp = await XService.Func_Net_ReadWebStream(star.AvatorWebUrl, NewMovieInfo.OfficialWeb);

                    var au = new Uri(star.AvatorWebUrl);
                    star.AvatorFileName = System.IO.Path.Combine(star.DirStored, au.Segments[au.Segments.Length - 1]);

                    using (FileStream sourceStream = new FileStream(star.AvatorFileName, FileMode.Create, FileAccess.Write, FileShare.None, bufferSize: 4096, useAsync: true))
                    {
                        await temp.CopyToAsync(sourceStream);

                        await sourceStream.FlushAsync();
                    }

                    //list_CurrentStars.Images.Add(Image.FromStream(temp));

                    star.StoredMovieIDs.Add(NewMovieInfo.ReleaseID);
                    NewMovieStars.Add(star);
                    NewMovieInfo.ActorUIDs.Add(star.UniqueID);
                    if (!is_star_stored)
                    {
                        XGlobal.CurrentContext.TotalStars.Add(star);
                    }
                }
            }

            return(true);
        }