private void SaveInfo(string filepath) { if (vieModel.DetailMovie == null) { return; } if (!string.IsNullOrEmpty(vieModel.DetailMovie.id)) { //视频类型、文件大小、创建时间 vieModel.DetailMovie.filepath = filepath; FileInfo fileInfo = new FileInfo(filepath); string id = Identify.GetFanhao(fileInfo.Name); int vt = (int)Identify.GetVedioType(id); if (vt > 0) { vieModel.DetailMovie.vediotype = vt; } if (File.Exists(filepath)) { vieModel.DetailMovie.filesize = fileInfo.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"); } vieModel.DetailMovie.otherinfo = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); vieModel.DetailMovie.scandate = createDate; } vieModel.SaveModel(); string table = ((Main)Jvedio.GetWindow.Get("Main")).GetCurrentList(); if (string.IsNullOrEmpty(table)) { vieModel.Query(vieModel.id); } else { vieModel.Query(vieModel.id, table); } HandyControl.Controls.Growl.Success("路径、视频类型、文件大小、创建时间、导入时间成功更新!", "EditGrowl"); } else { vieModel.Refresh(filepath); } }
public static async Task <bool> ParseSpecifiedInfo(WebSite webSite, string id, string url) { string content = ""; int StatusCode = 404; if (webSite == WebSite.DB) { (content, StatusCode) = await Net.Http(url, Cookie : Properties.Settings.Default.DBCookie); } if (webSite == WebSite.DMM) { (content, StatusCode) = await Net.Http(url, Cookie : Properties.Settings.Default.DMMCookie); } else { (content, StatusCode) = await Net.Http(url); } if (StatusCode != 200 || content == "") { return(false); } else { Dictionary <string, string> Info = new Dictionary <string, string>(); if (webSite == WebSite.Bus) { Info = new BusParse(id, content, Identify.GetVedioType(id)).Parse(); Info.Add("source", "javbus"); } else if (webSite == WebSite.BusEu) { Info = new BusParse(id, content, VedioType.欧美).Parse(); Info.Add("source", "javbus"); } else if (webSite == WebSite.DB) { Info = new JavDBParse(id, content, url.Split('/').Last()).Parse(); Info.Add("source", "javdb"); } else if (webSite == WebSite.Library) { Info = new LibraryParse(id, content).Parse(); Info.Add("source", "javlibrary"); } Info.Add("sourceurl", url); if (Info.Count > 2) { //保存信息 Info["id"] = id; DataBase.UpdateInfoFromNet(Info); DetailMovie detailMovie = DataBase.SelectDetailMovieById(id); //nfo 信息保存到视频同目录 if (Properties.Settings.Default.SaveInfoToNFO) { if (Directory.Exists(Properties.Settings.Default.NFOSavePath)) { //固定位置 nfo.SaveToNFO(detailMovie, Path.Combine(Properties.Settings.Default.NFOSavePath, $"{id}.nfo")); } else { //与视频同路径 string path = detailMovie.filepath; if (System.IO.File.Exists(path)) { nfo.SaveToNFO(detailMovie, Path.Combine(new FileInfo(path).DirectoryName, $"{id}.nfo")); } } } return(true); } } return(false); }
public Movie GetInfoFromNfo(string path) { XmlDocument doc = new XmlDocument(); try { doc.Load(path); } catch { return(null); } XmlNode rootNode = doc.SelectSingleNode("movie"); if (rootNode == null) { return(null); } Movie movie = new Movie(); foreach (XmlNode node in rootNode.ChildNodes) { try { switch (node.Name) { case "id": movie.id = node.InnerText.ToUpper(); break; case "title": movie.title = node.InnerText; break; case "release": movie.releasedate = node.InnerText; break; case "director": movie.director = node.InnerText; break; case "studio": movie.studio = node.InnerText; break; case "rating": movie.rating = node.InnerText == "" ? 0 : float.Parse(node.InnerText); break; case "plot": movie.plot = node.InnerText; break; case "outline": movie.outline = node.InnerText; break; case "year": movie.year = node.InnerText == "" ? 1970 : int.Parse(node.InnerText); break; case "runtime": movie.runtime = node.InnerText == "" ? 0 : int.Parse(node.InnerText); break; case "country": movie.country = node.InnerText; break; case "source": movie.sourceurl = node.InnerText; break; default: break; } } catch (Exception ex) { Console.WriteLine(ex.StackTrace); Console.WriteLine(ex.Message); continue; } } if (movie.id == "") { return(null); } //视频类型 movie.vediotype = (int)Identify.GetVedioType(movie.id); //扫描视频获得文件大小 if (File.Exists(path)) { string fatherpath = new FileInfo(path).DirectoryName; string[] files = null; try { files = Directory.GetFiles(fatherpath, "*.*", SearchOption.TopDirectoryOnly); } catch (Exception e) { Logger.LogE(e); } if (files != null) { var movielist = Scan.FirstFilter(files.ToList(), movie.id); if (movielist.Count == 1) { movie.filepath = movielist[0]; } else if (movielist.Count > 1) { //分段视频 movie.filepath = movielist[0]; string subsection = ""; movielist.ForEach(arg => { subsection += arg + ";"; }); movie.subsection = subsection; } } } //tag XmlNodeList tagNodes = doc.SelectNodes("/movie/tag"); if (tagNodes != null) { string tags = ""; foreach (XmlNode item in tagNodes) { if (item.InnerText != "") { tags += item.InnerText + " "; } } if (tags.Length > 0) { if (movie.id.IndexOf("FC2") >= 0) { movie.genre = tags.Substring(0, tags.Length - 1); } else { movie.tag = tags.Substring(0, tags.Length - 1); } } } //genre XmlNodeList genreNodes = doc.SelectNodes("/movie/genre"); if (genreNodes != null) { string genres = ""; foreach (XmlNode item in genreNodes) { if (item.InnerText != "") { genres += item.InnerText + " "; } } if (genres.Length > 0) { movie.genre = genres.Substring(0, genres.Length - 1); } } //actor XmlNodeList actorNodes = doc.SelectNodes("/movie/actor/name"); if (actorNodes != null) { string actors = ""; foreach (XmlNode item in actorNodes) { if (item.InnerText != "") { actors += item.InnerText + " "; } } if (actors.Length > 0) { movie.actor = actors.Substring(0, actors.Length - 1); } } //fanart XmlNodeList fanartNodes = doc.SelectNodes("/movie/fanart/thumb"); if (fanartNodes != null) { string extraimageurl = ""; foreach (XmlNode item in fanartNodes) { if (item.InnerText != "") { extraimageurl += item.InnerText + ";"; } } if (extraimageurl.Length > 0) { movie.extraimageurl = extraimageurl.Substring(0, extraimageurl.Length - 1); } } return(movie); }
/// <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); }
/// <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> 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); 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 + Environment.NewLine; unidentifynum++; } } } Logger.LogScanInfo(Environment.NewLine + $"【{Jvedio.Language.Resources.NotRecognizeNumber} :{unidentifynum}】" + Environment.NewLine + 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> { item }; repeatlist.Add(id, pathlist); } else { repeatlist[id].Add(item); } } } 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, List <string> filepathlist, List <string> notsubsection) = IsSubSection(kvp.Value); if (issubsection) { subsectionlist.Add(filepathlist); if (filepathlist.Count < kvp.Value.Count) { //其中几个不是分段视频 c2 += $" {Jvedio.Language.Resources.ID} :{kvp.Key}" + Environment.NewLine; removelist.AddRange(notsubsection); c2 += $" {Jvedio.Language.Resources.ImportSubSection}: {filepathlist.Count} ,:{string.Join(";",filepathlist)}" + Environment.NewLine; notsubsection.ForEach(arg => { c2 += $" {Jvedio.Language.Resources.NotImport} :{arg}" + Environment.NewLine; }); } } else { c2 += $" {Jvedio.Language.Resources.ID}:{kvp.Key}" + Environment.NewLine; (string maxfilepath, List <string> Excludelsist) = ExcludeMaximumSize(kvp.Value); removelist.AddRange(Excludelsist); c2 += $" {Jvedio.Language.Resources.ImportFile} :{maxfilepath},{Jvedio.Language.Resources.FileSize} :{new FileInfo(maxfilepath).Length}" + Environment.NewLine; Excludelsist.ForEach(arg => { c2 += $" {Jvedio.Language.Resources.NotImport} :{arg},{Jvedio.Language.Resources.FileSize} :{new FileInfo(arg).Length}" + Environment.NewLine; }); } } else { } } Logger.LogScanInfo(Environment.NewLine + $"【 {Jvedio.Language.Resources.RepeatVideo}:{removelist.Count + subsectionlist.Count}】" + Environment.NewLine + 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.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; } 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.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 { //待修复 的 bug string src = AppDomain.CurrentDomain.BaseDirectory + "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 async Task <bool> ParseSpecifiedInfo(WebSite webSite, string id, string url) { HttpResult httpResult = null; if (webSite == WebSite.Bus) { httpResult = await Net.Http(url, new CrawlerHeader() { Cookies = JvedioServers.Bus.Cookie }); } else if (webSite == WebSite.BusEu) { httpResult = await Net.Http(url, new CrawlerHeader() { Cookies = JvedioServers.BusEurope.Cookie }); } else if (webSite == WebSite.Library) { httpResult = await Net.Http(url, new CrawlerHeader() { Cookies = JvedioServers.Library.Cookie }); } else if (webSite == WebSite.Jav321) { httpResult = await Net.Http(url, new CrawlerHeader() { Cookies = JvedioServers.Jav321.Cookie }); } else if (webSite == WebSite.FC2) { httpResult = await Net.Http(url, new CrawlerHeader() { Cookies = JvedioServers.FC2.Cookie }); } else if (webSite == WebSite.DB) { httpResult = await Net.Http(url, new CrawlerHeader() { Cookies = JvedioServers.DB.Cookie }); } else if (webSite == WebSite.DMM) { httpResult = await Net.Http(url, new CrawlerHeader() { Cookies = JvedioServers.DMM.Cookie }); } else if (webSite == WebSite.MOO) { httpResult = await Net.Http(url, new CrawlerHeader() { Cookies = JvedioServers.MOO.Cookie }); } else { httpResult = await Net.Http(url); } if (httpResult != null && httpResult.StatusCode == HttpStatusCode.OK && httpResult.SourceCode != "") { string content = httpResult.SourceCode; Dictionary <string, string> Info = new Dictionary <string, string>(); if (webSite == WebSite.Bus) { Info = new BusParse(id, content, Identify.GetVedioType(id)).Parse(); Info.Add("source", "javbus"); } else if (webSite == WebSite.BusEu) { Info = new BusParse(id, content, VedioType.欧美).Parse(); Info.Add("source", "javbus"); } else if (webSite == WebSite.DB) { Info = new JavDBParse(id, content, url.Split('/').Last()).Parse(); Info.Add("source", "javdb"); } else if (webSite == WebSite.Library) { Info = new LibraryParse(id, content).Parse(); Info.Add("source", "javlibrary"); } else if (webSite == WebSite.Jav321) { Info = new LibraryParse(id, content).Parse(); Info.Add("source", "Jav321"); } else if (webSite == WebSite.DMM) { Info = new LibraryParse(id, content).Parse(); Info.Add("source", "DMM"); } else if (webSite == WebSite.MOO) { Info = new LibraryParse(id, content).Parse(); Info.Add("source", "MOO"); } else if (webSite == WebSite.FC2) { Info = new LibraryParse(id, content).Parse(); Info.Add("source", "FC2"); } Info.Add("sourceurl", url); if (Info.Count > 2) { FileProcess.SaveInfo(Info, id); return(true); } } return(false); }