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.GetVideoType(id); if (vt > 0) { vieModel.DetailMovie.vediotype = vt; } if (File.Exists(filepath)) { 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"); } vieModel.DetailMovie.otherinfo = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); vieModel.DetailMovie.scandate = createDate; } vieModel.SaveModel(); string table = ((Main)GetWindowByName("Main")).GetCurrentList(); if (string.IsNullOrEmpty(table)) { vieModel.Query(vieModel.id); } else { vieModel.Query(vieModel.id, table); } HandyControl.Controls.Growl.Success(Jvedio.Language.Resources.Message_EditUpdateSuccess, "EditGrowl"); } else { vieModel.Refresh(filepath); } }
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.GetVideoType(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); }
public static Movie GetInfoFromNfo(string path) { XmlDocument doc = new XmlDocument(); try { doc.Load(path); } catch (Exception ex) { Logger.LogE(ex); Console.WriteLine(ex.Message); 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 "num": movie.id = node.InnerText.ToUpper(); break; case "title": movie.title = node.InnerText; break; case "release": movie.releasedate = node.InnerText; break; case "releasedate": 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 (string.IsNullOrEmpty(movie.id)) { return(null); } //视频类型 movie.vediotype = (int)Identify.GetVideoType(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 && !movielist[0].ToLower().EndsWith(".nfo")) { 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"); List <string> tags = new List <string>(); if (tagNodes != null) { foreach (XmlNode item in tagNodes) { if (item.InnerText != "") { tags.Add(item.InnerText.Replace(" ", "")); } } if (movie.id.IndexOf("FC2") >= 0) { movie.genre = string.Join(" ", tags); } else { movie.tag = string.Join(" ", tags); } } //genre XmlNodeList genreNodes = doc.SelectNodes("/movie/genre"); List <string> genres = new List <string>(); if (genreNodes != null) { foreach (XmlNode item in genreNodes) { if (item.InnerText != "") { genres.Add(item.InnerText); } } movie.genre = string.Join(" ", genres); } //actor XmlNodeList actorNodes = doc.SelectNodes("/movie/actor/name"); List <string> actors = new List <string>(); if (actorNodes != null) { foreach (XmlNode item in actorNodes) { if (item.InnerText != "") { actors.Add(item.InnerText); } } movie.actor = string.Join(" ", actors); } //fanart XmlNodeList fanartNodes = doc.SelectNodes("/movie/fanart/thumb"); List <string> extraimageurls = new List <string>(); if (fanartNodes != null) { foreach (XmlNode item in fanartNodes) { if (item.InnerText != "") { extraimageurls.Add(item.InnerText); } } movie.extraimageurl = string.Join(" ", extraimageurls); } 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(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.GetVideoType(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.GetVideoType(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.GetVideoType(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); }