private void InitializeCommand() { var cbQuit = new CommandBinding(ApplicationCommands.Close, (sender, e) => { Application.Current.Shutdown(); e.Handled = true; }, (sender, e) => { e.CanExecute = true; e.Handled = true; }); CommandBinding cbNMBrowse = new CommandBinding(cmdNMBrowse, (sender, e) => { NewMovieInfo = new MovieInfo(); Microsoft.Win32.OpenFileDialog ofd_selectmovie = new Microsoft.Win32.OpenFileDialog { Filter = "Video files|*.avi;*.wmv;*.mp4;*.m4v;*.asf;*.asx;*.rm;*.rmvb;*.mpg;*.mpeg;*.mpe;*.3gp;*.mov;*.dat;*.mkv;*.flv;*.vob" }; Nullable <bool> result = ofd_selectmovie.ShowDialog(); if (result.HasValue && result.Value) { txtNMFullFileName.Text = ofd_selectmovie.FileName; Func_NMOpenMediaFile(ofd_selectmovie.FileName); } e.Handled = true; }, (sender, e) => { e.CanExecute = true; e.Handled = true; }); CommandBinding cbNMQuery = new CommandBinding(cmdNMQuery, (sender, e) => { switch (NewMovieQuerySite.QName) { case "CSite": case "USite": Func_NMBRecordAsync(NewMovieQuerySite.QName, txtNMKeyword.Text); break; case "BSite": Func_NMBRecordAsync(NewMovieQuerySite.QName, txtNMKeyword.Text); break; case "LSite": Func_NMLRecordAsync(NewMovieQuerySite.QName, txtNMKeyword.Text); break; default: break; } e.Handled = true; }, (sender, e) => { e.CanExecute = true; e.Handled = true; }); CommandBinding cbNMQueryResultItemSolve = new CommandBinding(CommandNMQueryResultItemSolve, (sender, e) => { switch (NewMovieQuerySite.QName) { case "CSite": case "USite": Func_NMResolveUCResult(e.Parameter as string); break; case "BSite": Func_NMResolveBResult(e.Parameter as string); break; case "LSite": Func_NMResolveLResult(e.Parameter as string); break; default: break; } e.Handled = true; }, (sender, e) => { e.CanExecute = true; e.Handled = true; }); CommandBinding cbNMRecordSolve = new CommandBinding(CommandNMRecordSolve, (sender, e) => { var _st = NewMovieStars.FirstOrDefault(s => s.JName == e.Parameter as string); DirectoryInfo _dirsource = new DirectoryInfo(NewMovieInfo.SourcePath); _st.CreateLocalMovieDirectory(NewMovieInfo); listInformation.SelectedIndex = listInformation.Items.Add($"MKDIR: {NewMovieInfo.SourcePath}..."); var encoder = new PngBitmapEncoder(); encoder.Frames.Add(BitmapFrame.Create((BitmapSource)picCover.Source)); using (FileStream stream = new FileStream(System.IO.Path.Combine(NewMovieInfo.SourcePath, NewMovieInfo.CoverFileName), FileMode.Create)) encoder.Save(stream); listInformation.SelectedIndex = listInformation.Items.Add($"SAVE COVER: {NewMovieInfo.CoverFileName}..."); NewMovieInfo.MediaFiles.ForEach(m => File.Move(m.LocalFileName, System.IO.Path.Combine(NewMovieInfo.SourcePath, System.IO.Path.GetFileName(m.LocalFileName)))); XGlobal.CurrentContext.TotalMovies.Add(NewMovieInfo); listInformation.SelectedIndex = listInformation.Items.Add($"MOVE VIDEO: {NewMovieInfo.MediaFiles.Count}..."); //todo: 保存记录数据 string mdatafile = ConfigurationManager.AppSettings["MovieDataFile"]; if (File.Exists(mdatafile)) { File.Delete(mdatafile); } XService.XMLDeserializerHelper.Serialization <List <MovieInfo> >(XGlobal.CurrentContext.TotalMovies, mdatafile); string sdatafile = ConfigurationManager.AppSettings["StarDataFile"]; if (File.Exists(sdatafile)) { File.Delete(sdatafile); } XService.XMLDeserializerHelper.Serialization <List <StarInfo> >(XGlobal.CurrentContext.TotalStars, sdatafile); e.Handled = true; }, (sender, e) => { e.CanExecute = true; e.Handled = true; }); bnNMBrowse.Command = cmdNMBrowse; bnNMQuery.Command = cmdNMQuery; this.CommandBindings.AddRange(new CommandBinding[] { cbNMBrowse, cbQuit, cbNMQuery, cbNMQueryResultItemSolve, cbNMRecordSolve }); }
/// <summary> /// Function: Add New Movie, Open Media File /// </summary> /// <param name="_filename">New media file full name</param> private void Func_NMOpenMediaFile(string _filename) { NewMovieInfo = new MovieInfo(_filename) { SourceMediaFileExt = System.IO.Path.GetExtension(_filename) }; txtNMKeyword.Items.Clear(); NewMovieQuerySite = new XQuerySite("LSite"); Match _match_heyzo = Regex.Match(_filename, @"hey.*?(\d+)", RegexOptions.Singleline | RegexOptions.IgnoreCase); Match _match_caribbean = Regex.Match(_filename, @"carib.*?(\d+[_-]\d+)", RegexOptions.Singleline | RegexOptions.IgnoreCase); Match _match_1pondo = Regex.Match(_filename, @"1pondo.*?(\d+[_-]\d+)", RegexOptions.Singleline | RegexOptions.IgnoreCase); Match _match_nums = Regex.Match(_filename, @"(\d{6,}[_-]\d{3,})", RegexOptions.Singleline | RegexOptions.IgnoreCase); Match _match_3d2d = Regex.Match(_filename, @"([a-z|A-Z]+3d(?:2d)?[a-z|A-Z]*\-?\d+)", RegexOptions.Singleline | RegexOptions.IgnoreCase); Match _match_bd = Regex.Match(_filename, @"([a-z|A-Z]+bd\-?[a-z|A-Z]?\d+)", RegexOptions.Singleline | RegexOptions.IgnoreCase); Match _match_tokyohot = Regex.Match(_filename, @"(n\d{4,})", RegexOptions.Singleline | RegexOptions.IgnoreCase); if (_match_heyzo.Success) { txtNMKeyword.Items.Add("heyzo " + _match_heyzo.Groups[1].Value); NewMovieQuerySite.ChangeTo("BSite"); } else if (_match_caribbean.Success) { txtNMKeyword.Items.Add(_match_caribbean.Groups[1].Value); NewMovieQuerySite.ChangeTo("BSite"); } else if (_match_1pondo.Success) { txtNMKeyword.Items.Add(_match_1pondo.Groups[1].Value); NewMovieQuerySite.ChangeTo("BSite"); } else if (_match_nums.Success) { txtNMKeyword.Items.Add(_match_nums.Groups[1].Value); NewMovieQuerySite.ChangeTo("BSite"); } else if (_match_3d2d.Success) { txtNMKeyword.Items.Add(_match_3d2d.Groups[1].Value); NewMovieQuerySite.ChangeTo("BSite"); } else if (_match_bd.Success) { txtNMKeyword.Items.Add(_match_bd.Groups[1].Value); NewMovieQuerySite.ChangeTo("BSite"); } else if (_match_tokyohot.Success) { txtNMKeyword.Items.Add(_match_tokyohot.Groups[1].Value); NewMovieQuerySite.ChangeTo("BSite"); } else { MatchCollection _mc = Regex.Matches(_filename, @"([a-z|A-Z]+\-?\d+)", RegexOptions.Singleline | RegexOptions.IgnoreCase); foreach (Match _m in _mc) { if (_m.Groups[1].Value == "whole1") { continue; } if (_m.Groups[1].Value == "hd1") { continue; } if (_m.Groups[1].Value == "mp4") { continue; } txtNMKeyword.Items.Add(Regex.Replace(_m.Groups[1].Value, @"0+", "0")); } _mc = Regex.Matches(_filename, @"(\d+[_-]\d+)|(\d+_[a-z|A-Z]+_\d+)", RegexOptions.Singleline | RegexOptions.IgnoreCase); foreach (Match _m in _mc) { txtNMKeyword.Items.Add(_m.Groups[1].Value); } NewMovieQuerySite.ChangeTo("LSite"); } txtNMKeyword.SelectedIndex = 0; }