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); }
private async void Func_NMResolveLResult(string v) { listInformation.SelectedIndex = listInformation.Items.Add($"READ: {v}..."); NewMovieInfo.OfficialWeb = v; var streamresult = (await XService.Func_Net_ReadWebData(NewMovieInfo.OfficialWeb)).response; CurrentHtmlDocument.LoadHtml(streamresult); HtmlNode hnode = CurrentHtmlDocument.DocumentNode.SelectSingleNode("//div[@id='rightcolumn']"); NewMovieInfo.ReleaseName = hnode.SelectSingleNode("//div[@id='video_title']/h3[1]").InnerText; var cvurl = hnode.SelectSingleNode("//img[@id='video_jacket_img']").Attributes["src"].Value; if (cvurl.StartsWith("//")) { cvurl = $"http:{cvurl}"; } ; NewMovieInfo.CoverWebUrl = cvurl; NewMovieInfo.CoverFileName = new Uri(cvurl).Segments.Last(); hnode = hnode.SelectSingleNode("//table[@id='video_jacket_info']"); //Resolve movie data Func_NMAnalysisLMovie(hnode); //處理 Stars 段 if (!Func_NMAnalysisLStars(hnode)) { return; } //處理 Sample Images 段 //if (!await Func_AnalysisMovie_Samples(hnode)) return; }
/// <summary> /// Analysis media files -> MediaFiles/MediaFilesTotalLength/MediaFilesTotalSize/MediaFilesDecodeDesc/VWidth/VHeight/NRefFrame/VFormat /// </summary> /// <param name="targetFileNameFromSource">Full name of media file.</param> public MovieInfo(string targetFileNameFromSource) { ActorUIDs = new List <Guid>(); MediaFiles = new List <MediaFileInfo>(); SourcePath = Path.GetDirectoryName(targetFileNameFromSource); SourceMediaFileExt = Path.GetExtension(targetFileNameFromSource); if (Directory.Exists(SourcePath)) { List <string> files = Directory.EnumerateFiles(SourcePath, "*" + SourceMediaFileExt, SearchOption.TopDirectoryOnly) .Where(f => f.EndsWith(SourceMediaFileExt, StringComparison.CurrentCultureIgnoreCase)).ToList(); files.ForEach(f => MediaFiles.Add(new MediaFileInfo(f))); } else { throw new DirectoryNotFoundException(String.Format("源目录{0}不存在!", SourcePath)); } if (MediaFiles == null) { return; } if (MediaFiles.Count == 0) { return; } VWidth = MediaFiles[0].VWidth; VHeight = MediaFiles[0].VHeight; NRefFrame = MediaFiles[0].NRefFrame; VFormat = MediaFiles[0].VFormat; MediaFilesTotalLength = MediaFiles.Sum(t => t.VLength); MediaFilesTotalSize = MediaFiles.Sum(t => t.VFileSize); var _vlength = TimeSpan.FromMinutes(MediaFilesTotalLength); MediaFilesDecodeDesc = string.Format("[{0}, {1}*{2}, {3:00}:{4:00}:{5:00}, {6}, {7}]", MediaFiles[0].VFormat, MediaFiles[0].VWidth, MediaFiles[0].VHeight, _vlength.Hours, _vlength.Minutes, _vlength.Seconds, XService.Format_MachineSize(MediaFilesTotalSize), MediaFiles[0].V2D3DVR); }
private bool Func_NMAnalysisLStars(HtmlNode hnode) { NewMovieStars.Clear(); listInformation.SelectedIndex = listInformation.Items.Add("READ: STARS..."); HtmlNode ncast = hnode.SelectSingleNode("//div[@id='video_cast']"); string jname = string.Empty; NewMovieInfo.ActorUIDs = new List <Guid>(); if (!ncast.SelectSingleNode("//td[@class='text']").HasChildNodes) { MessageBox.Show($"No cast information from {NewMovieQuerySite.QName.ToUpper()}.\nTry other web source.", "Expect Cast Data"); return(false); } HtmlNodeCollection ncasts = ncast.SelectNodes("//span[@class='star']/a"); foreach (HtmlNode _nc in ncasts) { bool is_star_stored = true; jname = XService.IllegalFiltered(_nc.InnerText.Replace(" ", "").Trim()); StarInfo star = XGlobal.CurrentContext.TotalStars.Find(s => s.JName == jname); if (star is null) { star = new StarInfo(jname); is_star_stored = false; } star.CreateLocalStarDirectory(NewMovieInfo); listInformation.SelectedIndex = listInformation.Items.Add($"CREATE: DIR/{System.IO.Path.Combine(System.IO.Path.GetPathRoot(NewMovieInfo.SourcePath), ConfigurationManager.AppSettings["ArchiveName"], star.JName)}"); star.StoredMovieIDs.Add(NewMovieInfo.ReleaseID); NewMovieStars.Add(star); NewMovieInfo.ActorUIDs.Add(star.UniqueID); if (!is_star_stored) { XGlobal.CurrentContext.TotalStars.Add(star); } } return(true); }
//private XContext() { } private XContext() { HttpClient = new HttpClient(); HttpCTS = new CancellationTokenSource(); TotalStars = new List <StarInfo>(); TotalMovies = new List <MovieInfo>(); DataFile = ConfigurationManager.AppSettings["DataFile"]; ArchiveName = ConfigurationManager.AppSettings["ArchiveName"]; string _strapppathtemp = Path.Combine(Path.GetTempPath(), $"_x_{Guid.NewGuid():D}"); if (Directory.Exists(_strapppathtemp)) { XService.ForceDeleteDirectory(new DirectoryInfo(_strapppathtemp)); } UseProxy = ConfigurationManager.AppSettings["UseProxy"] == "0" ? false : true; SSProxy = new WebProxy(ConfigurationManager.AppSettings["Proxy"]); }
public MediaFileInfo(string fname) { LocalFileName = fname; _mfile = new MediaFile(LocalFileName); VFileSize = _mfile.General.Size; TimeSpan tss = TimeSpan.FromMilliseconds(Convert.ToDouble(_mfile.General.Duration)); if (_mfile.Video.Count > 0) { V2D3DVR = "2D"; int nref = 1; VFormat = _mfile.General.Format; VWidth = _mfile.Video[0].Width; VHeight = _mfile.Video[0].Height; VLength = tss.Minutes; NRefFrame = 1; if (_mfile.Video[0].encoderSettings.Count > 0) { if (int.TryParse(_mfile.Video[0].EncoderSettings["ref"], out nref)) { if (nref > 1) { V2D3DVR = "3D"; NRefFrame = nref; } } } MediaDecodeDesc = string.Format("[{0}, {1}*{2}, {3:00}:{4:00}:{5:00}, {6}, {7}]", _mfile.General.Format, _mfile.Video[0].Width, _mfile.Video[0].Height, tss.Hours, tss.Minutes, tss.Seconds, XService.Format_MachineSize(_mfile.General.Size), V2D3DVR); } }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { long lsize = (long)value; return(XService.Format_MachineSize(lsize)); }
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); } }
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); }
private async void Func_NMResolveBResult(string v) { listInformation.SelectedIndex = listInformation.Items.Add($"READ: {v}..."); NewMovieInfo.OfficialWeb = v; var streamresult = (await XService.Func_Net_ReadWebData(NewMovieInfo.OfficialWeb)).response; CurrentHtmlDocument.LoadHtml(streamresult.Replace(Environment.NewLine, " ").Replace("\t", " ")); HtmlNode hnode = CurrentHtmlDocument.DocumentNode; HtmlNode _errornode = hnode.SelectSingleNode("//div[@class='alert alert-block alert-error']"); if (_errornode != null) { listInformation.SelectedIndex = listInformation.Items.Add($"ERR: {v}..."); return; } switch (NewMovieQuerySite.QName) { case "CSite": case "USite": hnode = hnode.SelectSingleNode("/html/body/div[2]"); break; case "BSite": hnode = hnode.SelectSingleNode("/html/body/div[@class='container']"); break; case "LSite": break; default: break; } foreach (HtmlNode _txt_node in hnode.SelectNodes(".//text()")) { if (!Regex.IsMatch(_txt_node.InnerText, @"\S", RegexOptions.Singleline)) { _txt_node.Remove(); } } NewMovieInfo.ReleaseName = hnode.SelectSingleNode("//h3[1]").InnerText; //TODO: LINE 180 Func_AnalysisMovie(hnode); //刪除重複 Mov if (XGlobal.CurrentContext.TotalMovies.Exists(m => m.ReleaseID == NewMovieInfo.ReleaseID)) { if (MessageBox.Show( String.Format( "影片 [{0}] 已有歸類存檔({1}*{2}, {3}),操作取消,刪除影片文件嗎?", NewMovieInfo.ReleaseID, NewMovieInfo.VWidth, NewMovieInfo.VHeight, XService.Format_MachineSize(NewMovieInfo.MediaFilesTotalSize)), "影片已歸檔", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { XService.DeleteMovies(NewMovieInfo.SourcePath, NewMovieInfo.SourceMediaFileExt); listInformation.SelectedIndex = listInformation.Items.Add($"源目錄 {NewMovieInfo.SourcePath} 已刪除."); return; } else { listInformation.SelectedIndex = listInformation.Items.Add($"影片 [{NewMovieInfo.ReleaseID}] 已有歸類存檔,操作取消."); return; } } //處理 Stars 段 if (!await Func_AnalysisStars(hnode)) { return; } //處理Cover //if (!await Func_AnalysisMovie_Cover(hnode)) return; //處理 Sample Images 段 //if (!await Func_AnalysisMovie_Samples(hnode)) return; }