private async void DownLoad(object o) { //下载信息=>下载图片 Movie movie = o as Movie; try { if (movie.id.ToUpper().IndexOf("FC2") >= 0) { SemaphoreFC2.WaitOne(); } else { Semaphore.WaitOne(); } if (Cancel | movie.id == "") { return; } bool success; string resultMessage; //下载信息 State = DownLoadState.DownLoading; if (movie.title == "" | movie.smallimageurl == "" | movie.bigimageurl == "" | movie.sourceurl == "") { (success, resultMessage) = await Task.Run(() => { return(Net.DownLoadFromNet(movie)); }); if (success) { InfoUpdate?.Invoke(this, new InfoUpdateEventArgs() { Movie = movie, progress = downLoadProgress.value }); } } DetailMovie dm = new DetailMovie(); DataBase cdb = new DataBase(""); dm = cdb.SelectDetailMovieById(movie.id); cdb.CloseDB(); //下载小图 await DownLoadSmallPic(dm); dm.smallimage = StaticClass.GetBitmapImage(dm.id, "SmallPic"); InfoUpdate?.Invoke(this, new InfoUpdateEventArgs() { Movie = dm, progress = downLoadProgress.value, state = State }); if (dm.sourceurl?.IndexOf("fc2club") >= 0) { //复制大图 if (File.Exists(StaticVariable.BasePicPath + $"SmallPic\\{dm.id}.jpg") & !File.Exists(StaticVariable.BasePicPath + $"BigPic\\{dm.id}.jpg")) { File.Copy(StaticVariable.BasePicPath + $"SmallPic\\{dm.id}.jpg", StaticVariable.BasePicPath + $"BigPic\\{dm.id}.jpg"); } } else { //下载大图 await DownLoadBigPic(dm); } dm.bigimage = StaticClass.GetBitmapImage(dm.id, "BigPic"); lock (downLoadProgress.lockobject) downLoadProgress.value += 1; InfoUpdate?.Invoke(this, new InfoUpdateEventArgs() { Movie = dm, progress = downLoadProgress.value, state = State }); Task.Delay(1000).Wait(); } catch (Exception e) { Logger.LogE(e); } finally { if (movie.id.ToUpper().IndexOf("FC2") >= 0) { SemaphoreFC2.Release(); } else { Semaphore.Release(); } } }
public async Task <(bool, string)> AsyncScreenShot(Movie movie) { bool result = true; string message = ""; List <string> outputPath = new List <string>(); await Task.Run(() => { // n 个线程截图 if (!File.Exists(Properties.Settings.Default.FFMPEG_Path)) { result = false; message = Jvedio.Language.Resources.Message_SetFFmpeg; return; } int num = Properties.Settings.Default.ScreenShot_ThreadNum; string ScreenShotPath = ""; ScreenShotPath = BasePicPath + "ScreenShot\\" + movie.id; if (!Directory.Exists(ScreenShotPath)) { Directory.CreateDirectory(ScreenShotPath); } string[] cutoffArray = MediaParse.GetCutOffArray(movie.filepath); //获得影片长度数组 if (cutoffArray.Length == 0) { result = false; message = Jvedio.Language.Resources.FailToCutOffVideo; return; } if (!File.Exists(movie.filepath)) { result = false; message = Jvedio.Language.Resources.NotExists; return; } int SemaphoreNum = cutoffArray.Length > 10 ? 10 : cutoffArray.Length;//最多 10 个线程截图 SemaphoreScreenShot = new Semaphore(SemaphoreNum, SemaphoreNum); ScreenShotCurrent = 0; int ScreenShotTotal = cutoffArray.Count(); ScreenShotLockObject = new object(); for (int i = 0; i < cutoffArray.Count(); i++) { outputPath.Add($"{ScreenShotPath}\\ScreenShot-{i.ToString().PadLeft(2, '0')}.jpg"); List <object> list = new List <object>() { cutoffArray[i], i.ToString(), movie.filepath, ScreenShotPath }; Thread threadObject = new Thread(BeginScreenShot); threadObject.Start(list); } //等待直到所有线程结束 while (ScreenShotCurrent != ScreenShotTotal) { Task.Delay(100).Wait(); } }); foreach (var item in outputPath) { if (!File.Exists(item)) { result = false; message = $"{Jvedio.Language.Resources.FailToGenerate} {item}"; break; } } return(result, message); }
public async void StartRun(object sender, RoutedEventArgs e) { if (Running) { HandyControl.Controls.Growl.Error("其他任务正在进行!", "ToolsGrowl"); return; } cts = new CancellationTokenSource(); cts.Token.Register(() => { HandyControl.Controls.Growl.Info("取消当前下载任务!", "ToolsGrowl"); }); ct = cts.Token; var grids = MainGrid.Children.OfType <Grid>().ToList(); int index = 0; for (int i = 0; i < grids.Count; i++) { if (grids[i].Visibility == Visibility.Visible) { index = i; break; } } Running = true; switch (index) { case 0: //扫描 double totalnum = 0; //扫描出的视频总数 double insertnum = 0; //导入的视频总数 try { //全盘扫描 if ((bool)ScanAll.IsChecked) { LoadingStackPanel.Visibility = Visibility.Visible; await Task.Run(() => { ct.ThrowIfCancellationRequested(); List <string> filepaths = Scan.ScanAllDrives(); totalnum = filepaths.Count; insertnum = Scan.InsertWithNfo(filepaths, ct); }); } else { if (vieModel.ScanPath.Count == 0) { break; } LoadingStackPanel.Visibility = Visibility.Visible; await Task.Run(() => { ct.ThrowIfCancellationRequested(); StringCollection stringCollection = new StringCollection(); foreach (var item in vieModel.ScanPath) { if (Directory.Exists(item)) { stringCollection.Add(item); } } List <string> filepaths = Scan.ScanPaths(stringCollection, ct); totalnum = filepaths.Count; insertnum = Scan.InsertWithNfo(filepaths, ct); }, cts.Token); } LoadingStackPanel.Visibility = Visibility.Hidden; if (!cts.IsCancellationRequested) { HandyControl.Controls.Growl.Info($"扫描出 {totalnum} 个,导入 {insertnum} 个", "ToolsGrowl"); } } catch (OperationCanceledException ex) { Console.WriteLine($"{nameof(OperationCanceledException)} thrown with message: {ex.Message}"); } finally { cts.Dispose(); Running = false; } break; case 1: //Access LoadingStackPanel.Visibility = Visibility.Visible; string AccessPath = AccessPathTextBox.Text; if (!File.Exists(AccessPath)) { HandyControl.Controls.Growl.Error($"不存在 :{AccessPath}", "ToolsGrowl"); break; } try { await Task.Run(() => { DataBase.InsertFromAccess(AccessPath); }); LoadingStackPanel.Visibility = Visibility.Hidden; if (!cts.IsCancellationRequested) { HandyControl.Controls.Growl.Success("成功!", "ToolsGrowl"); } } finally { cts.Dispose(); Running = false; } break; case 2: //NFO if ((bool)NfoRB1.IsChecked) { if (vieModel.NFOScanPath.Count == 0) { HandyControl.Controls.Growl.Warning("路径为空!", "ToolsGrowl"); } } else { if (!File.Exists(NFOPathTextBox.Text)) { HandyControl.Controls.Growl.Warning($"文件不存在{NFOPathTextBox.Text}", "ToolsGrowl"); } } Running = true; try { List <string> nfoFiles = new List <string>(); if (!(bool)NfoRB1.IsChecked) { nfoFiles.Add(NFOPathTextBox.Text); } else { //扫描所有nfo文件 await Task.Run(() => { this.Dispatcher.Invoke((Action) delegate { StatusTextBlock.Visibility = Visibility.Visible; StatusTextBlock.Text = "开始扫描"; }); StringCollection stringCollection = new StringCollection(); foreach (var item in vieModel.NFOScanPath) { if (Directory.Exists(item)) { stringCollection.Add(item); } } nfoFiles = Scan.ScanNFO(stringCollection, ct, (filepath) => { this.Dispatcher.Invoke((Action) delegate { StatusTextBlock.Text = filepath; }); }); }, cts.Token); } //记录日志 Logger.LogScanInfo("\n-----【" + DateTime.Now.ToString() + "】NFO扫描-----"); Logger.LogScanInfo($"\n扫描出 => {nfoFiles.Count} 个 "); //导入所有 nfo 文件信息 double total = 0; bool importpic = (bool)NFOCopyPicture.IsChecked; await Task.Run(() => { nfoFiles.ForEach(item => { if (File.Exists(item)) { Movie movie = GetInfoFromNfo(item); if (movie != null && !string.IsNullOrEmpty(movie.id)) { DataBase.InsertFullMovie(movie); //复制并覆盖所有图片 if (importpic) { CopyPicToPath(movie.id, item); } total += 1; Logger.LogScanInfo($"\n成功导入数据库 => {item} "); } } }); }); LoadingStackPanel.Visibility = Visibility.Hidden; if (!cts.IsCancellationRequested) { Logger.LogScanInfo($"\n成功导入 {total} 个"); HandyControl.Controls.Growl.Success($"\n成功导入 {total} 个", "ToolsGrowl"); } } finally { cts.Dispose(); Running = false; } break; case 3: //欧美扫描 if (vieModel.ScanEuPath.Count == 0) { break; } LoadingStackPanel.Visibility = Visibility.Visible; totalnum = 0; insertnum = 0; try { await Task.Run(() => { StringCollection stringCollection = new StringCollection(); foreach (var item in vieModel.ScanEuPath) { if (Directory.Exists(item)) { stringCollection.Add(item); } } List <string> filepaths = Scan.ScanPaths(stringCollection, ct); totalnum = filepaths.Count; insertnum = Scan.InsertWithNfo(filepaths, ct, IsEurope: true); }); LoadingStackPanel.Visibility = Visibility.Hidden; if (!cts.IsCancellationRequested) { HandyControl.Controls.Growl.Info($"扫描出 {totalnum} 个,导入 {insertnum} 个"); } } finally { cts.Dispose(); Running = false; } break; case 4: break; case 5: //网络驱动器 LoadingStackPanel.Visibility = Visibility.Visible; string path = UNCPathTextBox.Text; if (path == "") { break; } bool CanScan = true; //检查权限 await Task.Run(() => { try { var tl = Directory.GetFiles(path, "*.*", SearchOption.TopDirectoryOnly); } catch { CanScan = false; } }); if (!CanScan) { LoadingStackPanel.Visibility = Visibility.Hidden; HandyControl.Controls.Growl.Error($"权限不够!"); break; } bool IsEurope = !(bool)ScanTypeRadioButton.IsChecked; totalnum = 0; insertnum = 0; try { await Task.Run(() => { StringCollection stringCollection = new StringCollection(); stringCollection.Add(path); List <string> filepaths = Scan.ScanPaths(stringCollection, ct); totalnum = filepaths.Count; insertnum = Scan.InsertWithNfo(filepaths, ct, IsEurope: IsEurope); }); LoadingStackPanel.Visibility = Visibility.Hidden; if (!cts.IsCancellationRequested) { HandyControl.Controls.Growl.Info($"扫描出 {totalnum} 个,导入 {insertnum} 个"); } } finally { cts.Dispose(); Running = false; } break; default: break; } Running = false; }
private static void ReplaceWithValue(string property, Movie movie, ref string result) { string inSplit = Properties.Settings.Default.InSplit.Replace("无", ""); PropertyInfo[] PropertyList = movie.GetType().GetProperties(); foreach (PropertyInfo item in PropertyList) { string name = item.Name; if (name == property) { object o = item.GetValue(movie); if (o != null) { string value = o.ToString(); if (property == "actor" || property == "genre" || property == "label") { value = value.Replace(" ", inSplit).Replace("/", inSplit); } if (property == "vediotype") { int v = 1; int.TryParse(value, out v); if (v == 1) { value = Jvedio.Language.Resources.Uncensored; } else if (v == 2) { value = Jvedio.Language.Resources.Censored; } else if (v == 3) { value = Jvedio.Language.Resources.Europe; } } if (string.IsNullOrEmpty(value)) { //如果值为空,则删掉前面的分隔符 int idx = result.IndexOf("{" + property + "}"); if (idx >= 1) { result = result.Remove(idx - 1, 1); } result = result.Replace("{" + property + "}", ""); } else { result = result.Replace("{" + property + "}", value); } } else { int idx = result.IndexOf("{" + property + "}"); if (idx >= 1) { result = result.Remove(idx - 1); } result = result.Replace("{" + property + "}", ""); } break; } } }
/// <summary> /// 分类视频并导入 /// </summary> /// <param name="MoviePaths"></param> /// <param name="ct"></param> /// <param name="IsEurope"></param> /// <returns></returns> public static double DistinctMovieAndInsert(List <string> MoviePaths, CancellationToken ct, bool IsEurope = false) { Logger.LogScanInfo("\n-----【" + DateTime.Now.ToString() + "】-----"); Logger.LogScanInfo($"\n扫描出 => {MoviePaths.Count} 个 \n"); DataBase cdb = new DataBase(); //检查未识别出番号的视频 List <string> r1 = new List <string>(); string c1 = ""; string id = ""; VedioType vt = 0; double totalinsertnum = 0; double unidentifynum = 0; foreach (var item in MoviePaths) { if (File.Exists(item)) { id = IsEurope ? Identify.GetEuFanhao(new FileInfo(item).Name) : Identify.GetFanhao(new FileInfo(item).Name); //Console.WriteLine($"{id}=>{item}"); if (IsEurope) { if (string.IsNullOrEmpty(id)) { vt = 0; } else { vt = VedioType.欧美; } } else { vt = Identify.GetVedioType(id); } if (vt != 0) { r1.Add(item); } else { //写日志 c1 += " " + item + "\n"; unidentifynum++; } } } Logger.LogScanInfo($"\n【未识别出的视频:{unidentifynum}个】\n" + c1); //检查 重复|分段 视频 Dictionary <string, List <string> > repeatlist = new Dictionary <string, List <string> >(); string c2 = ""; foreach (var item in r1) { if (File.Exists(item)) { id = IsEurope ? Identify.GetEuFanhao(new FileInfo(item).Name) : Identify.GetFanhao(new FileInfo(item).Name); if (!repeatlist.ContainsKey(id)) { List <string> pathlist = new List <string>(); pathlist.Add(item); repeatlist.Add(id, pathlist); } else { repeatlist[id].Add(item); } } } Console.WriteLine("repeatlist:" + repeatlist.Count); List <string> removelist = new List <string>(); List <List <string> > subsectionlist = new List <List <string> >(); foreach (KeyValuePair <string, List <string> > kvp in repeatlist) { if (kvp.Value.Count > 1) { bool issubsection = IsSubSection(kvp.Value); if (issubsection) { subsectionlist.Add(kvp.Value); } else { c2 += $" 识别码为:{kvp.Key}\n"; (string maxfilepath, List <string> Excludelsist) = ExcludeMaximumSize(kvp.Value); removelist.AddRange(Excludelsist); c2 += $" 导入的:{maxfilepath},文件大小:{new FileInfo(maxfilepath).Length}\n"; Excludelsist.ForEach(arg => { c2 += $" 未导入:{arg},文件大小:{new FileInfo(arg).Length}\n"; }); } } else { } } Logger.LogScanInfo($"\n【重复的视频:{removelist.Count + subsectionlist.Count}个】\n" + c2); List <string> insertList = r1.Except(removelist).ToList(); Console.WriteLine("removelist:" + removelist.Count); Console.WriteLine("subsectionlist:" + subsectionlist.Count); //导入分段视频 foreach (var item in subsectionlist) { insertList = insertList.Except(item).ToList(); try { ct.ThrowIfCancellationRequested(); } catch (OperationCanceledException ex) { Logger.LogE(ex); break; } string subsection = ""; FileInfo fileinfo = new FileInfo(item[0]); id = IsEurope ? Identify.GetEuFanhao(fileinfo.Name) : Identify.GetFanhao(fileinfo.Name); if (IsEurope) { if (string.IsNullOrEmpty(id)) { continue; } else { vt = VedioType.欧美; } } else { vt = Identify.GetVedioType(id); } if (string.IsNullOrEmpty(id) | vt == 0) { continue; } //文件大小视为所有文件之和 double filesize = 0; for (int i = 0; i < item.Count; i++) { if (!File.Exists(item[i])) { continue; } FileInfo fi = new FileInfo(item[i]); subsection += item[i] + ";"; filesize += fi.Length; } //获取创建日期 string createDate = ""; try { createDate = fileinfo.CreationTime.ToString("yyyy-MM-dd HH:mm:ss"); } catch { } if (createDate == "") { createDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); } Movie movie = new Movie() { filepath = item[0], id = id, filesize = filesize, vediotype = (int)vt, subsection = subsection.Substring(0, subsection.Length - 1), scandate = createDate }; cdb.InsertScanMovie(movie); totalinsertnum += 1; } Console.WriteLine("insertList:" + insertList.Count); //导入所有视频 foreach (var item in insertList) { try { ct.ThrowIfCancellationRequested(); } catch (OperationCanceledException ex) { Logger.LogE(ex); break; } if (!File.Exists(item)) { continue; } FileInfo fileinfo = new FileInfo(item); string createDate = ""; try { createDate = fileinfo.CreationTime.ToString("yyyy-MM-dd HH:mm:ss"); } catch { } if (createDate == "") { createDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); } id = IsEurope ? Identify.GetEuFanhao(fileinfo.Name) : Identify.GetFanhao(fileinfo.Name); if (IsEurope) { if (string.IsNullOrEmpty(id)) { continue; } else { vt = VedioType.欧美; } } else { vt = Identify.GetVedioType(id); } Movie movie = new Movie() { filepath = item, id = id, filesize = fileinfo.Length, vediotype = (int)vt, scandate = createDate }; cdb.InsertScanMovie(movie); totalinsertnum += 1; } cdb.CloseDB(); Logger.LogScanInfo($"\n总计导入 => {totalinsertnum}个\n"); //从 主数据库中 复制信息 if (Properties.Settings.Default.DataBasePath.Split('\\').Last().Split('.').First().ToLower() != "info") { try { //待修复 的 bug CopyDatabaseInfo(Properties.Settings.Default.DataBasePath.Split('\\').Last().Split('.').First().ToLower()); } catch { } } return(totalinsertnum); }
private async void DownLoad(object o) { DownLoadInfo downLoadInfo = o as DownLoadInfo; try { if (downLoadInfo.id.ToUpper().IndexOf("FC2") >= 0) { SemaphoreFC2.WaitOne(); } else { Semaphore.WaitOne(); } if (Cancel) { return; } while (Pause & !Cancel) { Task.Delay(300).Wait(); } this.State = DownLoadState.DownLoading; Movie movie = DataBase.SelectMovieByID(downLoadInfo.id); string[] url = new string[] { Properties.Settings.Default.Bus, Properties.Settings.Default.BusEurope, Properties.Settings.Default.DB, Properties.Settings.Default.Library }; bool[] enableurl = new bool[] { Properties.Settings.Default.EnableBus, Properties.Settings.Default.EnableBusEu, Properties.Settings.Default.EnableDB, Properties.Settings.Default.EnableLibrary, Properties.Settings.Default.EnableFC2 }; string[] cookies = new string[] { Properties.Settings.Default.DBCookie }; if (movie.title == "" | movie.smallimageurl == "" | movie.bigimageurl == "" | movie.sourceurl == "") { await Task.Run(() => { return(Net.DownLoadFromNet(movie)); }); } movie = DataBase.SelectMovieByID(downLoadInfo.id); //更新总进度 List <string> extrapicurlList = new List <string>(); var list = movie.extraimageurl.Split(';'); foreach (var item in list) { if (!string.IsNullOrEmpty(item)) { extrapicurlList.Add(item); } } downLoadInfo.maximum = extrapicurlList.Count; downLoadInfo.maximum += 2; //小图 await DownLoadSmallPic(movie); downLoadInfo.progress += 1; InfoUpdate?.Invoke(this, new DownloadUpdateEventArgs() { DownLoadInfo = downLoadInfo }); //更新进度 //大图 await DownLoadBigPic(movie); downLoadInfo.progress += 1; InfoUpdate?.Invoke(this, new DownloadUpdateEventArgs() { DownLoadInfo = downLoadInfo }); //更新进度 //预览图 bool dlimageSuccess; string cookie = ""; for (int i = 0; i < extrapicurlList.Count(); i++) { if (!File.Exists(StaticVariable.BasePicPath + $"Extrapic\\{movie.id.ToUpper()}\\{movie.id.ToUpper()}.jpg")) { if (Cancel) { return; } while (Pause & !Cancel) { Task.Delay(300).Wait(); } if (extrapicurlList[i].Length > 0) { (dlimageSuccess, cookie) = await DownLoadExtraPic(movie.id, extrapicurlList[i], cookie); if (dlimageSuccess) { Task.Delay(1000).Wait(); } } } downLoadInfo.progress += 1; InfoUpdate?.Invoke(this, new DownloadUpdateEventArgs() { DownLoadInfo = downLoadInfo }); //更新进度 } } finally { if (downLoadInfo.id.ToUpper().IndexOf("FC2") >= 0) { SemaphoreFC2.Release(); } else { Semaphore.Release(); } } }
/// <summary> /// 分类视频并导入 /// </summary> /// <param name="MoviePaths"></param> /// <param name="ct"></param> /// <param name="IsEurope"></param> /// <returns></returns> public static double DistinctMovieAndInsert(List <string> MoviePaths, CancellationToken ct, bool IsEurope = false) { Logger.LogScanInfo(Environment.NewLine + "-----【" + DateTime.Now.ToString() + "】-----"); Logger.LogScanInfo(Environment.NewLine + $"{Jvedio.Language.Resources.ScanVideo} => {MoviePaths.Count} " + Environment.NewLine); List <string> result1 = new List <string>(); string log1 = ""; string id = ""; VedioType vt = 0; double totalinsertnum = 0; //总的导入数目 double unidentifynum = 0; //无法识别的数目 //检查未识别出番号的视频 foreach (var item in MoviePaths) { if (File.Exists(item)) { id = IsEurope ? Identify.GetEuFanhao(new FileInfo(item).Name) : Identify.GetFanhao(new FileInfo(item).Name); if (IsEurope) { if (string.IsNullOrEmpty(id)) { vt = 0; } else { vt = VedioType.欧美; } } else { vt = Identify.GetVedioType(id); } if (vt != 0) { result1.Add(item); } else { log1 += " " + item + Environment.NewLine; unidentifynum++; } } } Logger.LogScanInfo(Environment.NewLine + $"【{Jvedio.Language.Resources.NotRecognizeNumber} :{unidentifynum}】" + Environment.NewLine + log1); //检查 重复|分段 视频 Dictionary <string, List <string> > repeatlist = new Dictionary <string, List <string> >(); string log2 = ""; foreach (var item in result1) { if (File.Exists(item)) { id = IsEurope ? Identify.GetEuFanhao(new FileInfo(item).Name) : Identify.GetFanhao(new FileInfo(item).Name); if (!repeatlist.ContainsKey(id)) { List <string> pathlist = new List <string> { item }; repeatlist.Add(id, pathlist); } else { repeatlist[id].Add(item);//每个 id 对应一组视频路径,视频路径最多的视为分段视频 } } } List <string> removelist = new List <string>(); List <List <string> > subsectionlist = new List <List <string> >(); foreach (KeyValuePair <string, List <string> > kvp in repeatlist) { if (kvp.Value.Count > 1) { //路径个数大于1 才为分段视频 (bool issubsection, List <string> filepathlist, List <string> notsubsection) = IsSubSection(kvp.Value); if (issubsection) { subsectionlist.Add(filepathlist); if (filepathlist.Count < kvp.Value.Count) { //其中几个不是分段视频 log2 += $" {Jvedio.Language.Resources.ID} :{kvp.Key}" + Environment.NewLine; removelist.AddRange(notsubsection); log2 += $" {Jvedio.Language.Resources.ImportSubSection}: {filepathlist.Count} ,:{string.Join(";", filepathlist)}" + Environment.NewLine; notsubsection.ForEach(arg => { log2 += $" {Jvedio.Language.Resources.NotImport} :{arg}" + Environment.NewLine; }); } } else { log2 += $" {Jvedio.Language.Resources.ID}:{kvp.Key}" + Environment.NewLine; (string maxfilepath, List <string> Excludelsist) = ExcludeMaximumSize(kvp.Value); removelist.AddRange(Excludelsist); log2 += $" {Jvedio.Language.Resources.ImportFile} :{maxfilepath},{Jvedio.Language.Resources.FileSize} :{new FileInfo(maxfilepath).Length}" + Environment.NewLine; Excludelsist.ForEach(arg => { log2 += $" {Jvedio.Language.Resources.NotImport} :{arg},{Jvedio.Language.Resources.FileSize} :{new FileInfo(arg).Length}" + Environment.NewLine; }); } } } Logger.LogScanInfo(Environment.NewLine + $"【 {Jvedio.Language.Resources.RepeatVideo}:{removelist.Count + subsectionlist.Count}】" + Environment.NewLine + log2); List <string> insertList = result1.Except(removelist).ToList();//需要导入的视频 //导入分段视频 foreach (var item in subsectionlist) { insertList = insertList.Except(item).ToList(); ct.ThrowIfCancellationRequested(); string subsection = ""; FileInfo fileinfo = new FileInfo(item[0]);//获得第一个视频的文件信息 id = IsEurope ? Identify.GetEuFanhao(fileinfo.Name) : Identify.GetFanhao(fileinfo.Name); if (IsEurope) { if (string.IsNullOrEmpty(id)) { continue; } else { vt = VedioType.欧美; } } else { vt = Identify.GetVedioType(id); } if (string.IsNullOrEmpty(id) | vt == 0) { continue; } //文件大小视为所有文件之和 double filesize = 0; for (int i = 0; i < item.Count; i++) { if (!File.Exists(item[i])) { continue; } FileInfo fi = new FileInfo(item[i]); subsection += item[i] + ";"; filesize += fi.Length; } //获取创建日期 string createDate = ""; try { createDate = fileinfo.LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss"); } catch { } if (createDate == "") { createDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); } Movie movie = new Movie() { filepath = item[0], id = id, filesize = filesize, vediotype = (int)vt, subsection = subsection.Substring(0, subsection.Length - 1), otherinfo = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), scandate = createDate }; DataBase.InsertScanMovie(movie); totalinsertnum += 1; } //导入剩余的所有视频 foreach (var item in insertList) { ct.ThrowIfCancellationRequested(); if (!File.Exists(item)) { continue; } FileInfo fileinfo = new FileInfo(item); string createDate = ""; try { createDate = fileinfo.LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss"); } catch { } if (createDate == "") { createDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); } id = IsEurope ? Identify.GetEuFanhao(fileinfo.Name) : Identify.GetFanhao(fileinfo.Name); if (IsEurope) { if (string.IsNullOrEmpty(id)) { continue; } else { vt = VedioType.欧美; } } else { vt = Identify.GetVedioType(id); } Movie movie = new Movie() { filepath = item, id = id, filesize = fileinfo.Length, vediotype = (int)vt, otherinfo = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), scandate = createDate }; DataBase.InsertScanMovie(movie); totalinsertnum += 1; } Logger.LogScanInfo(Environment.NewLine + $"{Jvedio.Language.Resources.TotalImport} => {totalinsertnum},{Jvedio.Language.Resources.ImportAttention}" + Environment.NewLine); //从 主数据库中 复制信息 //if (Path.GetFileNameWithoutExtension(Properties.Settings.Default.DataBasePath).ToLower() != "info") //{ // try // { // string src = AppDomain.CurrentDomain.BaseDirectory + "DataBase\\info.sqlite"; // string dst = AppDomain.CurrentDomain.BaseDirectory + $"DataBase\\{Path.GetFileNameWithoutExtension(Properties.Settings.Default.DataBasePath).ToLower()}.sqlite"; ; // DataBase.CopyDatabaseInfo(src, dst); // } // catch { } //} return(totalinsertnum); }
public static double InsertWithNfo(List <string> filepaths, CancellationToken ct, Action <string> messageCallBack = null, bool IsEurope = false) { List <string> nfopaths = new List <string>(); List <string> vediopaths = new List <string>(); foreach (var item in filepaths) { if (item.ToLower().EndsWith(".nfo")) { nfopaths.Add(item); } else { vediopaths.Add(item); } } //先导入 nfo 再导入视频,避免路径覆盖 if (nfopaths.Count > 0 && Properties.Settings.Default.ScanNfo) { Logger.LogScanInfo(Environment.NewLine + "-----【" + DateTime.Now.ToString() + "】-----"); Logger.LogScanInfo(Environment.NewLine + $"{Jvedio.Language.Resources.ScanNFO} => {nfopaths.Count} " + Environment.NewLine); double total = 0; //导入 nfo 文件 nfopaths.ForEach(item => { if (File.Exists(item)) { Movie movie = FileProcess.GetInfoFromNfo(item); if (movie != null && !string.IsNullOrEmpty(movie.id)) { DataBase.InsertFullMovie(movie); total += 1; Logger.LogScanInfo(Environment.NewLine + $"{Jvedio.Language.Resources.SuccessImportToDataBase} => {item} "); } } }); Logger.LogScanInfo(Environment.NewLine + $"{Jvedio.Language.Resources.ImportNFONumber}: {total}" + Environment.NewLine); messageCallBack?.Invoke($"{Jvedio.Language.Resources.ImportNFONumber}: {total}"); } //导入视频 if (vediopaths.Count > 0) { try { double _num = Scan.DistinctMovieAndInsert(vediopaths, ct, IsEurope); messageCallBack?.Invoke($"{Jvedio.Language.Resources.ImportVideioNumber}:{_num},详情请看日志"); return(_num); }catch (OperationCanceledException ex) { Logger.LogF(ex); messageCallBack?.Invoke($"{Jvedio.Language.Resources.Cancel}"); } } return(0); }
private async void DownLoad(object o) { //下载信息=>下载图片 Movie movie = o as Movie; if (movie.id.ToUpper().StartsWith("FC2")) { SemaphoreFC2.WaitOne(); } else { Semaphore.WaitOne(); //阻塞 } if (Cancel || string.IsNullOrEmpty(movie.id)) { if (movie.id.ToUpper().StartsWith("FC2")) { SemaphoreFC2.Release(); } else { Semaphore.Release(); } return; } bool success; string resultMessage; //下载信息 State = DownLoadState.DownLoading; if (Net.IsToDownLoadInfo(movie) || enforce) { //满足一定条件才下载信息 (success, resultMessage) = await Task.Run(() => { return(Net.DownLoadFromNet(movie)); }); InfoUpdate?.Invoke(this, new InfoUpdateEventArgs() { Movie = movie, progress = downLoadProgress.value, Success = success }); //委托到主界面显示 if (!success) { MessageCallBack?.Invoke(this, new MessageCallBackEventArgs($" {movie.id} 信息下载失败,原因:{(resultMessage.ToStatusMessage())}")); } } DetailMovie dm = new DetailMovie(); dm = DataBase.SelectDetailMovieById(movie.id); if (!File.Exists(BasePicPath + $"BigPic\\{dm.id}.jpg") || enforce) { string message2 = ""; (bool success2, string cookie2) = await Net.DownLoadImage(dm.bigimageurl, ImageType.BigImage, dm.id, callback : (sc) => { message2 = sc.ToString(); });//下载大图 //if (!success2) MessageCallBack?.Invoke(this, new MessageCallBackEventArgs($" {dm.id} 海报图下载失败,原因:{message2.ToStatusMessage()}")); } //fc2 没有缩略图 if (dm.id.IndexOf("FC2") >= 0) { //复制海报图作为缩略图 if (File.Exists(BasePicPath + $"BigPic\\{dm.id}.jpg") && !File.Exists(BasePicPath + $"SmallPic\\{dm.id}.jpg")) { File.Copy(BasePicPath + $"BigPic\\{dm.id}.jpg", BasePicPath + $"SmallPic\\{dm.id}.jpg"); } } else { if (!File.Exists(BasePicPath + $"SmallPic\\{dm.id}.jpg") || enforce) { string message = ""; (bool success1, string cookie) = await Net.DownLoadImage(dm.smallimageurl, ImageType.SmallImage, dm.id, callback : (sc) => { message = sc.ToString(); }); //下载小图 //if (!success1) MessageCallBack?.Invoke(this, new MessageCallBackEventArgs($" {dm.id} 缩略图下载失败,原因:{message.ToStatusMessage()}")); } } dm.smallimage = ImageProcess.GetBitmapImage(dm.id, "SmallPic"); InfoUpdate?.Invoke(this, new InfoUpdateEventArgs() { Movie = dm, progress = downLoadProgress.value, state = State }); //委托到主界面显示 dm.bigimage = ImageProcess.GetBitmapImage(dm.id, "BigPic"); lock (downLoadProgress.lockobject) downLoadProgress.value += 1; //完全下载完一个影片 InfoUpdate?.Invoke(this, new InfoUpdateEventArgs() { Movie = dm, progress = downLoadProgress.value, state = State, Success = true }); //委托到主界面显示 Task.Delay(DelayInvterval).Wait(); //每个线程之间暂停 //取消阻塞 if (movie.id.ToUpper().IndexOf("FC2") >= 0) { SemaphoreFC2.Release(); } else { Semaphore.Release(); } }