private void button2_Click(object sender, EventArgs e) { if (!Directory.Exists(textBox1.Text)) { MessageBox.Show("请先选择路径"); return; } if (avs == null) { avs = new List <Av>(); } HashSet <string> IdSet; IdSet = new HashSet <string>(); string[] folders = Directory.GetDirectories(textBox1.Text); foreach (string folder in folders) { int fgg = folder.LastIndexOf("\\") + 1; string name = folder.Substring(fgg, folder.Length - fgg).Trim(); try { name = name.Split(' ')[1]; Av av = new Av(); av.Id = name; av.Path = folder; avs.Add(av); textBox2.AppendText("->" + name + "\r\n"); } catch { textBox3.AppendText(name + "\r\n"); } } //for } //method
private void button2_Click(object sender, EventArgs e) { if (!Directory.Exists(textBox1.Text)) { MessageBox.Show("请先选择路径"); return; } avs = new List <Av>(); string[] folders = Directory.GetDirectories(textBox1.Text); foreach (string folder in folders) { int fg = folder.LastIndexOf("\\") + 1; string name = folder.Substring(fg, folder.Length - fg).Trim(); //Match match = new Regex(@"([A-Za-z0-9]+[-_]*?[A-Za-z0-9]+)\s*").Match(name); //Match match = new Regex(@"([A-Za-z0-9]+[-_]*[A-Za-z0-9]+[-_]*[A-Za-z0-9]*)\s*").Match(name); Match match = match = new Regex(@"(?:[0-9]{4}-[0-9]{2}-[0-9]{2})?\s?([A-Za-z0-9]+[-_]*[A-Za-z0-9]+[-_]*[A-Za-z0-9]*)\s*").Match(name); if (match.Success) { string fhid = match.Groups[1].Value; textBox2.AppendText(fhid + "\r\n"); Av av = new Av(); av.Id = fhid.Trim(); av.Path = folder; avs.Add(av); } else { textBox3.AppendText(name + "\r\n"); } } //for } //method
void Director(string dir) { DirectoryInfo fdir = new DirectoryInfo(dir); FileSystemInfo[] fsinfos = fdir.GetFileSystemInfos(); foreach (FileSystemInfo fsinfo in fsinfos) { if (fsinfo is DirectoryInfo) //判断是否为文件夹 { Director(fsinfo.FullName); //递归调用 } else { if (extNames.ToUpper().IndexOf(fsinfo.Extension.ToUpper()) != -1) {//视频文件 FileInfo ff = new System.IO.FileInfo(fsinfo.FullName); //太小的视频文件 判断为损坏跳过 if (ff.Length < 1024) { textBox3.AppendText(fsinfo.Name + ":" + ff.Length + "\r\n"); ExeLog.WriteLog("nolist.txt", fsinfo.Name + "\r\n"); continue; } Av av = new Av(); av.Path = fsinfo.FullName; avs.Add(av); textBox2.AppendText(fsinfo.Name + "\r\n"); } //if 视频文件 } //if } //foreach } //method
private void button2_Click(object sender, EventArgs e) { if (!Directory.Exists(textBox1.Text)) { MessageBox.Show("请先选择路径"); return; } string extNames = ".ts.tp.m2ts.tod.m2t.mts.avi.mov.mpg.mpeg.divx.RA.RM.RMVB.WMV.mkv.mp4.asf.m4v.vob.flv"; DirectoryInfo fdir = new DirectoryInfo(textBox1.Text); FileSystemInfo[] fsinfos = fdir.GetFileSystemInfos(); foreach (FileSystemInfo fsinfo in fsinfos) { if (fsinfo is DirectoryInfo) //判断是否为文件夹 { continue; } if (extNames.ToUpper().IndexOf(fsinfo.Extension.ToUpper()) != -1) { Match match = new Regex(@"\d{6,}", RegexOptions.IgnoreCase).Match(fsinfo.Name); if (!match.Success) { continue; } string dirname = "f2cppv-" + fsinfo.Name.Replace(fsinfo.Extension, ""); if (!Directory.Exists(textBox1.Text + "\\" + dirname)) { Directory.CreateDirectory(textBox1.Text + "\\" + dirname); } File.Move(fsinfo.FullName, textBox1.Text + "\\" + dirname + "\\" + fsinfo.Name); } } avs = new List <Av>(); HashSet <string> IdSet; IdSet = new HashSet <string>(); string[] folders = Directory.GetDirectories(textBox1.Text); foreach (string folder in folders) { int fgg = folder.LastIndexOf("\\") + 1; string name = folder.Substring(fgg, folder.Length - fgg).Trim(); textBox2.AppendText(name + "\r\n"); Match match = new Regex(@"\d{6,}", RegexOptions.IgnoreCase).Match(name); if (!match.Success) { continue; } string matres = match.Value; Av av = new Av(); av.Id = matres; av.Path = folder; avs.Add(av); textBox2.AppendText("识别:" + matres + "\r\n"); } }//method
}//method public void DownloadFun(object o) { while (_avs.Count > 0) { Av a = _avs.Dequeue(); string coverpath = a.Path + "\\cover.jpg"; /* * if (File.Exists(coverpath)) * { * _syncContext.Post(OutLog, "曾经下载过:" + a.Id + " 跳过\r\n"); * continue; * } */ string url = basePath + "/" + a.Id; string html = ""; try { //html = client.GetStringAsync(url).Result; html = Download.GetHtml(url); } catch (Exception e) { _syncContext.Post(OutError, a.Id + " :查询网站异常"); continue; } if (html.IndexOf("404 Page Not Found") != -1) { // /search/111&parent=ce _syncContext.Post(OutError, a.Id + " :找不到该番号"); } else { a.Html = html; try { DownloadCover(a); } catch (Exception e) { _syncContext.Post(OutError, a.Id + " :采集封面失败"); continue; } } } //while _syncContext.Post(OutLog, "线程退出"); } //method
private void button4_Click(object sender, EventArgs e) { if (avs == null) { avs = new List <Av>(); } Av av = new Av(); av.Id = textBox5.Text; av.Path = textBox6.Text; avs.Add(av); textBox2.AppendText("->" + av.Id + "\r\n"); }
}//method public void DownloadFun(object o) { while (_avs.Count > 0) { Av a = _avs.Dequeue(); string url = basePath + "/" + a.Id; string html = ""; try { //html = client.GetStringAsync(url).Result; html = Download.GetHtml(url); } catch (Exception e) { _syncContext.Post(OutError, a.Id + " :查询网站异常"); continue; } if (html.IndexOf("404 Page Not Found") != -1) { // /search/111&parent=ce _syncContext.Post(OutError, a.Id + " :找不到该番号"); } else { int fg = a.Path.LastIndexOf("\\") + 1; string name = a.Path.Substring(fg, a.Path.Length - fg).Trim(); string apath = a.Path.Substring(0, fg); a.Html = html; string qb = "<li class=\"active\"><a href=\"" + basePath + "/\">"; if (html.IndexOf(qb) != -1) { apath += "骑兵"; } else { apath += "步兵"; } apath += "\\" + name; MoveFolder(a.Path, apath); Directory.Delete(a.Path, true); } } //while _syncContext.Post(OutLog, "线程退出"); } //method
}//method public void DownloadFun(object o) { while (_avs.Count > 0) { Av a = _avs.Dequeue(); string coverpath = a.Path + "\\cover.jpg"; string url = basePath + "/cn/vl_searchbyid.php?keyword=" + a.Id; string html = ""; try { html = Download.GetHtml(url); } catch (Exception e) { _syncContext.Post(OutError, a.Id + " :查询网站异常"); continue; } if (html.IndexOf("搜寻没有结果") != -1) { _syncContext.Post(OutError, a.Id + " :找不到该番号"); } else { a.Html = html; try { DownloadCover(a); } catch (Exception e) { _syncContext.Post(OutError, a.Id + " :采集封面失败"); continue; } } } //while _syncContext.Post(OutLog, "线程退出"); } //method
} //method public void DownloadCover(Av av) { Match match = new Regex(@"<a class=""bigImage"" href=""(?<url>.*?)"">").Match(av.Html); if (match.Success) { string url = match.Groups["url"].Value; if (!url.StartsWith("http")) { url = basePath + url; } Download.HttpDownloadFile(url, av.Path + "\\", "art.jpg"); //int fg = url.LastIndexOf("/") + 1; //string name = url.Substring(fg, url.Length - fg - 6).Trim(); url = url.Replace("_b", ""); string qb = "<li class=\"active\"><a href=\"" + basePath + "/\">"; if (av.Html.IndexOf(qb) != -1) { url = url.Replace("cover", "thumb"); } else { url = url.Replace("cover", "thumbs"); } Download.HttpDownloadFile(url, av.Path + "\\", "folder.jpg"); //修改文件夹名称 try { StringBuilder sb = new StringBuilder(); MatchCollection startNames = new Regex(@"<div class=""star-name""><a href="".*?"" title="".*?"">(?<name>.*?)</a></div>").Matches(av.Html); int i = 0; int x = 0; int y = 0; foreach (Match m in startNames) { sb.Append(m.Groups["name"].Value); i++; if (i < startNames.Count) { sb.Append(","); } if (++x > 20) { y++; x = 0; File.Create(av.Path + "\\" + av.Id + " " + sb.ToString() + ".star" + y + ".txt").Close(); sb.Clear(); } } if (sb.Length > 0) { File.Create(av.Path + "\\" + av.Id + " " + sb.ToString() + ".star" + (y == 0?"":y + 1 + "") + ".txt").Close(); } } catch (Exception e) { _syncContext.Post(OutError, av.Id + " :获取女优失败"); } try { //match = new Regex(@"<h3>(?<title>.*?)</h3>[\s\S]*?<p><span class=""header"">發行日期:</span>(?<date>.*?)</p>").Match(av.Html); match = new Regex(@"<h3>(?<title>[\s\S]*?)</h3>[\s\S]*?<p><span class=""header"">發行日期:</span>(?<date>.*?)</p>").Match(av.Html); string newPath = null; if (match.Success) { av.date = match.Groups["date"].Value.Trim(); av.title = match.Groups["title"].Value.Trim(); string newfolderName = match.Groups["date"].Value.Trim() + " " + match.Groups["title"].Value.Trim(); newfolderName = newfolderName.Replace("\\", "‖"); newfolderName = newfolderName.Replace("/", "‖"); newfolderName = newfolderName.Replace(":", ":"); newfolderName = newfolderName.Replace("*", "※"); newfolderName = newfolderName.Replace("?", "?"); newfolderName = newfolderName.Replace("<", "〈"); newfolderName = newfolderName.Replace(">", "〉"); newfolderName = newfolderName.Replace("\n", " "); newfolderName = newfolderName.Replace("\r", " "); //newfolderName = Regex.Replace(newfolderName, @"[/n/r]", " "); StringBuilder rBuilder = new StringBuilder(newfolderName); foreach (char rInvalidChar in Path.GetInvalidPathChars()) { rBuilder.Replace(rInvalidChar.ToString(), string.Empty); } int fg = av.Path.LastIndexOf("\\"); string baseFilePath = av.Path.Substring(0, fg).Trim(); System.IO.DirectoryInfo folder = new System.IO.DirectoryInfo(av.Path); string apath = ""; qb = "<li class=\"active\"><a href=\"" + basePath + "/\">"; if (av.Html.IndexOf(qb) != -1) { apath += "骑兵\\"; } else { apath += "步兵\\"; } MoveFolder(av.Path, baseFilePath + "\\" + apath + newfolderName); Directory.Delete(av.Path, true); //folder.MoveTo(); newPath = baseFilePath + "\\" + apath + newfolderName; av.Path = newPath; } else { ExeLog.WriteLog("获取AV名称失败:\r\n" + av.Html); _syncContext.Post(OutError, av.Id + " :获取AV名称失败"); return; } //修改视频名称 改为符合 emby的规则 string[] extNames = new string[] { ".avi", ".mov", ".mpg", ".RA", ".RM", ".RMVB", ".WMV", ".mkv", ".mp4", ".asf", ".m4v", ".VOB" }; DirectoryInfo fdir = new DirectoryInfo(newPath); FileInfo[] file = fdir.GetFiles(); if (file.Length != 0) { //当前目录文件或文件夹不为空 for (int i = 0; i < extNames.Length; i++) { int x = 0; foreach (FileInfo f in file) { if (extNames[i].ToLower().Equals(f.Extension.ToLower())) { x++; } } int y = 1; foreach (FileInfo f in file) //显示当前目录所有文件 { if (extNames[i].ToLower().Equals(f.Extension.ToLower())) { string newName = newPath + "\\" + av.Id + (x > 1 ? "-cd" + y : "") + f.Extension; av.CD1 = x > 1; try { //记录文件名称 ChangeNameLogTxt(f.Name, newName); File.Move(f.FullName, newName); //File.Create(folder + "\\"+ (x > 1 ? "-cd" + y : "") + f.Name + ".old.name").Close(); } catch (Exception ex) { _syncContext.Post(OutError, av.Id + "-修改视频文件名称错误 \r\n"); } y++; } //for files } } //for ext } //file } catch (Exception e) { _syncContext.Post(OutError, av.Id + " :修改AV名称失败" + e.Message); } _syncContext.Post(OutLog, av.Id); try { creNfo(av); } catch (Exception e) { _syncContext.Post(OutLog, av.Id + ":nfo 创建失败" + e.Message); } } }
public static void creNfo(Av av) { Match mat = null; string p = av.title.Replace(av.Id, "").Trim(); //string plot = "google:"+Translate.google(p) + " youdao:"+Translate.youdao(p); string fileStr = av.Path + "\\" + av.Id + (av.CD1 ? "-cd1" : "") + ".nfo"; FileStream fs1 = new FileStream(fileStr, FileMode.Create, FileAccess.Write);//创建写入文件 StreamWriter sw = new StreamWriter(fs1); sw.WriteLine("<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>"); sw.WriteLine("<movie>"); //sw.WriteLine("<plot>" + plot + "</plot>"); sw.WriteLine("<outline/>"); sw.WriteLine("<lockdata>false</lockdata>"); sw.WriteLine("<title>" + av.Id + "</title>"); sw.WriteLine("<originaltitle>" + p + "</originaltitle>"); mat = new Regex(@"<p><span class=""header"">導演:</span> <a href="".*?"">(.*?)</a></p>").Match(av.Html); if (mat.Success) { sw.WriteLine("<director>" + mat.Groups[1].Value.Trim() + "</director>"); } sw.WriteLine("<year>" + av.date.Substring(0, 4) + "</year>"); sw.WriteLine("<premiered>" + av.date + "</premiered>"); sw.WriteLine("<releasedate>" + av.date + "</releasedate>"); mat = new Regex(@"<p><span class=""header"">系列:</span> <a href="".*?"">(.*?)</a></p>").Match(av.Html); if (mat.Success) { sw.WriteLine("<genre>" + mat.Groups[1].Value.Trim() + "</genre>"); } mat = new Regex(@"<p><span class=""header"">長度:</span>\s*(\d*)分鐘</p>").Match(av.Html); if (mat.Success) { sw.WriteLine("<runtime>" + mat.Groups[1].Value.Trim() + "</runtime>"); } mat = new Regex(@"<p><span class=""header"">製作商:</span> <a href="".*?"">(.*?)</a>").Match(av.Html); if (mat.Success) { sw.WriteLine("<studio>" + mat.Groups[1].Value.Trim() + "</studio>"); } MatchCollection tags = new Regex(@"<span class=""genre""><a href="".*?"">(.*?)</a></span>").Matches(av.Html); foreach (Match m in tags) { sw.WriteLine("<tag>" + m.Groups[1].Value.Trim() + "</tag>"); } MatchCollection actors = new Regex(@"<div class=""photo-frame"">\s*<img src=""(.*?)"" title=""(.*?)"">\s*</div>\s*<span>(.*?)</span>").Matches(av.Html); foreach (Match m in actors) { sw.WriteLine("<actor>"); sw.WriteLine("<name>" + m.Groups[2].Value.Trim() + "</name>"); //sw.WriteLine("<role></role>"); sw.WriteLine("<type>Actor</type>"); sw.WriteLine("<thumb>" + m.Groups[1].Value.Trim() + "</thumb>"); sw.WriteLine("</actor>"); } sw.WriteLine("</movie>"); sw.Close(); fs1.Close(); }
} //method public void DownloadCover(Av av) { //MatchCollection matchs = new Regex(@"class=""responsive""\s+src=""(?<upload>.*?)""/>", RegexOptions.Multiline).Matches(av.Html); MatchCollection matchs = new Regex(@"class=""responsive""\s+src=""(?<upload>.*?)""\s*/>", RegexOptions.Multiline).Matches(av.Html); int s = 0; foreach (Match match in matchs) { string url = match.Groups["upload"].Value; Download.HttpDownloadFile(basePath + url, av.Path + "\\", s == 0 ? "poster.jpg" : "screenshot" + s + ".jpg"); s++; } Match m = new Regex(@"<a\shref=""(.*?)""\starget=""_blank""\s><img\sid=""thumbpic""").Match(av.Html); if (m.Success) { string url = m.Groups[1].Value; Download.HttpDownloadFile(basePath + url, av.Path + "\\", "screenshot.jpg"); } m = new Regex(@"<h5><strong style=""color:red;"">女优名字</strong>:<a href="".*?"">(.*?)</a></h5> ", RegexOptions.Singleline).Match(av.Html); if (m.Success) { string name = fileNameX(m.Groups[1].Value); File.Create(av.Path + "\\" + av.Id + " " + name + ".star.txt").Close(); } m = new Regex(@"<h5><strong style=""color:red;"">卖家信息</strong>:<a href="".*?"">(.*?)</a>", RegexOptions.Singleline).Match(av.Html); if (m.Success) { string name = fileNameX(m.Groups[1].Value); File.Create(av.Path + "\\" + av.Id + " " + name + ".seller.txt").Close(); } string newPath = null; try { Match nameMatch = new Regex(@"<div class=""col-sm-8"">\s+<h3>(.*?)</h3>", RegexOptions.Singleline).Match(av.Html); if (nameMatch.Success) { string newfolderName = fileNameX(nameMatch.Groups[1].Value); int fg = av.Path.LastIndexOf("\\"); string basePath = av.Path.Substring(0, fg).Trim(); System.IO.DirectoryInfo folder = new System.IO.DirectoryInfo(av.Path); if (!Directory.Exists(basePath + "\\ok")) { Directory.CreateDirectory(basePath + "\\ok"); } folder.MoveTo(basePath + "\\ok\\" + newfolderName); newPath = basePath + "\\ok\\" + newfolderName; } else { ExeLog.WriteLog("获取AV名称失败:\r\n" + av.Html); _syncContext.Post(OutError, av.Id + " :获取AV名称失败"); return; } //修改视频名称 改为符合 emby的规则 string[] extNames = new string[] { ".avi", ".mov", ".mpg", ".RA", ".RM", ".RMVB", ".WMV", ".mkv", ".mp4", ".asf", ".m4v", ".VOB" }; DirectoryInfo fdir = new DirectoryInfo(newPath); FileInfo[] file = fdir.GetFiles(); if (file.Length != 0) { //当前目录文件或文件夹不为空 for (int i = 0; i < extNames.Length; i++) { int x = 0; foreach (FileInfo f in file) { if (extNames[i].ToLower().Equals(f.Extension.ToLower())) { x++; } } int y = 1; foreach (FileInfo f in file) //显示当前目录所有文件 { if (extNames[i].ToLower().Equals(f.Extension.ToLower())) { string newName = newPath + "\\" + av.Id + (x > 1 ? "-cd" + y : "") + f.Extension; try { //记录文件名称 ChangeNameLogTxt(f.Name, newName); File.Move(f.FullName, newName); //File.Create(folder + "\\"+ (x > 1 ? "-cd" + y : "") + f.Name + ".old.name").Close(); } catch (Exception ex) { _syncContext.Post(OutError, av.Id + "-修改视频文件名称错误 \r\n"); } y++; } //for files } } //for ext } //file } catch (Exception e) { _syncContext.Post(OutError, av.Id + " :修改AV名称失败" + e.Message); } //_syncContext.Post(OutLog, av.Id); //} }
} //method public void DownloadCover(Av av) { Match match = new Regex(@"<img id=""video_jacket_img"" src=""//(?<url>.*?)""").Match(av.Html); if (match.Success) { string url = match.Groups["url"].Value; url = "http://" + url; Download.HttpDownloadFile(url, av.Path + "\\", "art.jpg"); url = url.Replace("pl.jpg", "ps.jpg"); Download.HttpDownloadFile(url, av.Path + "\\", "folder.jpg"); //修改文件夹名称 try { StringBuilder sb = new StringBuilder(); Match startNameMatch = new Regex(@"<td class=""header"">演员:</td>\s*<td class=""text"">(?<name>.*?)</td>").Match(av.Html); if (startNameMatch.Success) { string startName = ReplaceHtmlTag(startNameMatch.Groups["name"].Value); if (startName.Length > 100) { string[] startNames = startName.Trim().Split(' '); int x = 0; int y = 0; foreach (string n in startNames) { if (++x > 20) { y++; x = 0; File.Create(av.Path + "\\" + av.Id + " " + sb.ToString() + ".star" + y + ".txt").Close(); sb.Clear(); } } if (sb.Length > 0) { File.Create(av.Path + "\\" + av.Id + " " + sb.ToString() + ".star" + (y == 0 ? "" : y + 1 + "") + ".txt").Close(); } } else { File.Create(av.Path + "\\" + av.Id + " " + startName.Trim().Replace(' ', ',') + ".star.txt").Close(); } } } catch (Exception e) { _syncContext.Post(OutError, av.Id + " :获取女优失败"); } try { //match = new Regex(@"<h3>(?<title>.*?)</h3>[\s\S]*?<p><span class=""header"">發行日期:</span>(?<date>.*?)</p>").Match(av.Html); match = new Regex(@"<div id=""video_title""><h3 class=""post-title text""><a.*?>(?<title>.*?)</a></h3>[.\s\S]*<td class=""header"">发行日期:</td>\s*<td class=""text"">(?<date>.*?)</td> ").Match(av.Html); if (match.Success) { string newfolderName = match.Groups["date"].Value.Trim() + " " + match.Groups["title"].Value.Trim(); newfolderName = newfolderName.Replace("\\", "‖"); newfolderName = newfolderName.Replace("/", "‖"); newfolderName = newfolderName.Replace(":", ":"); newfolderName = newfolderName.Replace("*", "※"); newfolderName = newfolderName.Replace("?", "?"); newfolderName = newfolderName.Replace("<", "〈"); newfolderName = newfolderName.Replace(">", "〉"); newfolderName = newfolderName.Replace("\n", " "); newfolderName = newfolderName.Replace("\r", " "); //newfolderName = Regex.Replace(newfolderName, @"[/n/r]", " "); StringBuilder rBuilder = new StringBuilder(newfolderName); foreach (char rInvalidChar in Path.GetInvalidPathChars()) { rBuilder.Replace(rInvalidChar.ToString(), string.Empty); } int fg = av.Path.LastIndexOf("\\"); string basePath = av.Path.Substring(0, fg).Trim(); System.IO.DirectoryInfo folder = new System.IO.DirectoryInfo(av.Path); folder.MoveTo(basePath + "\\" + newfolderName); } else { ExeLog.WriteLog("获取AV名称失败:\r\n" + av.Html); _syncContext.Post(OutError, av.Id + " :获取AV名称失败"); } } catch (Exception e) { _syncContext.Post(OutError, av.Id + " :修改AV名称失败"); } _syncContext.Post(OutLog, av.Id); } }
void Director(string dir) { DirectoryInfo fdir = new DirectoryInfo(dir); FileSystemInfo[] fsinfos = fdir.GetFileSystemInfos(); HashSet <string> IdSet; foreach (FileSystemInfo fsinfo in fsinfos) { if (fsinfo is DirectoryInfo) //判断是否为文件夹 { Director(fsinfo.FullName); //递归调用 } else { IdSet = new HashSet <string>(); if (extNames.ToUpper().IndexOf(fsinfo.Extension.ToUpper()) != -1) {//视频文件 FileInfo ff = new System.IO.FileInfo(fsinfo.FullName); //太小的视频文件 判断为损坏跳过 /*if (ff.Length < 1024) { * textBox3.AppendText(fsinfo.Name + ":"+ff.Length+"\r\n"); * continue; * }*/ //视频文件 被整理过 /* if (fsinfo.Name.IndexOf("-cd") != -1) * { * textBox3.AppendText(fsinfo.Name + ":" + ff.Length + "\r\n"); * continue; * }*/ textBox2.AppendText(fsinfo.Name + "\r\n"); string spName = fsinfo.Name.Replace(fsinfo.Extension, ""); MatchCollection matchs = new Regex("[A-Za-z0-9]+[-_]?[A-Za-z0-9]+([-_]?[0-9])*").Matches(spName); foreach (Match match in matchs) { string fh = match.Groups[0].Value.Trim(); if (fh.Length < 5) { continue; } //Match mat = new Regex(@"^[A-Za-z0-9-_;]+$").Match(fh); //if (!mat.Success) continue; int numIndex = getNumberIndex(fh); if (numIndex == -1) { continue; } Av av = new Av(); av.Oname = fsinfo.Name; av.file = true; av.Id = fh; av.Path = fsinfo.FullName; av.ToPath = textBox5.Text; avs.Add(av); textBox2.AppendText("->" + fh + "\r\n"); IdSet.Add(fh); if (fh.IndexOf("-1") != -1 || fh.IndexOf("-2") != -1) { int fg = fh.LastIndexOf("-"); fh = fh.Substring(0, fg).Trim(); if (fh.Length < 6) { continue; } if (IdSet.Contains(fh)) { continue; } av = new Av(); av.Oname = fsinfo.Name; av.Id = fh; av.Path = fsinfo.FullName; av.ToPath = textBox5.Text; avs.Add(av); textBox2.AppendText("->" + fh + "\r\n"); IdSet.Add(fh); } else if (fh.IndexOf("-") == -1 && fh.IndexOf("_") == -1) { fh = fh.Substring(0, numIndex) + "-" + fh.Substring(numIndex, fh.Length - numIndex); if (IdSet.Contains(fh)) { continue; } av = new Av(); av.Oname = fsinfo.Name; av.Id = fh; av.Path = fsinfo.FullName; av.ToPath = textBox5.Text; avs.Add(av); textBox2.AppendText("->" + fh + "\r\n"); IdSet.Add(fh); } else if (fh.IndexOf("_") != -1) { fh = fh.Replace("_", "-"); if (IdSet.Contains(fh)) { continue; } av = new Av(); av.Oname = fsinfo.Name; av.Id = fh; av.Path = fsinfo.FullName; av.ToPath = textBox5.Text; avs.Add(av); textBox2.AppendText("->" + fh + "\r\n"); IdSet.Add(fh); } else if (fh.IndexOf("-") != -1) { fh = fh.Replace("-", "_"); if (IdSet.Contains(fh)) { continue; } av = new Av(); av.Oname = fsinfo.Name; av.Id = fh; av.Path = fsinfo.FullName; av.ToPath = textBox5.Text; avs.Add(av); textBox2.AppendText("->" + fh + "\r\n"); IdSet.Add(fh); } }//foreach match Match mat = new Regex(@"[Nn]\d{3,5}").Match(spName); if (mat.Success) { string fh = mat.Groups[0].Value; if (!IdSet.Contains(fh)) { Av av = new Av(); av.Oname = fsinfo.Name; av.Id = fh; av.Path = fsinfo.FullName; av.ToPath = textBox5.Text; avs.Add(av); textBox2.AppendText("->" + fh + "\r\n"); IdSet.Add(fh); } } mat = new Regex("[A-Za-z]+-[A-Za-z0-9]+").Match(spName); if (mat.Success) { string fh = mat.Groups[0].Value; if (!IdSet.Contains(fh)) { Av av = new Av(); av.Oname = fsinfo.Name; av.Id = fh; av.Path = fsinfo.FullName; av.ToPath = textBox5.Text; avs.Add(av); textBox2.AppendText("->" + fh + "\r\n"); IdSet.Add(fh); } } mat = new Regex("[A-Za-z]+[0-9]{3,8}").Match(spName); if (mat.Success) { string fh = mat.Groups[0].Value; int numIndex = getNumberIndex(fh); fh = fh.Substring(0, numIndex) + "-" + fh.Substring(numIndex, fh.Length - numIndex); if (!IdSet.Contains(fh)) { Av av = new Av(); av.Oname = fsinfo.Name; av.Id = fh; av.Path = fsinfo.FullName; av.ToPath = textBox5.Text; avs.Add(av); textBox2.AppendText("->" + fh + "\r\n"); IdSet.Add(fh); } } mat = new Regex("[0-9]+-[0-9]+[-]?[0-9]+").Match(spName); if (mat.Success) { string fh = mat.Groups[0].Value; if (!IdSet.Contains(fh)) { Av av = new Av(); av.Oname = fsinfo.Name; av.Id = fh; av.Path = fsinfo.FullName; av.ToPath = textBox5.Text; avs.Add(av); textBox2.AppendText("->" + fh + "\r\n"); IdSet.Add(fh); } } mat = new Regex("[A-Za-z]+[-_]?[0-9]{3,8}").Match(spName); if (mat.Success) { string fh = mat.Groups[0].Value; fh = fh.Replace("_", "-"); if (!IdSet.Contains(fh)) { Av av = new Av(); av.Oname = fsinfo.Name; av.Id = fh; av.Path = fsinfo.FullName; av.ToPath = textBox5.Text; avs.Add(av); textBox2.AppendText("->" + fh + "\r\n"); IdSet.Add(fh); } } } //if 视频文件 } //foreach } //if } //method
private void button2_Click(object sender, EventArgs e) { if (!Directory.Exists(textBox1.Text)) { MessageBox.Show("请先选择路径"); return; } avs = new List <Av>(); HashSet <string> IdSet; IdSet = new HashSet <string>(); string[] folders = Directory.GetDirectories(textBox1.Text); foreach (string folder in folders) { int fgg = folder.LastIndexOf("\\") + 1; string name = folder.Substring(fgg, folder.Length - fgg).Trim(); //Match match = new Regex(@"([A-Za-z0-9]+[-_]*?[A-Za-z0-9]+)\s*").Match(name); //Match match = new Regex(@"([A-Za-z0-9]+[-_]*[A-Za-z0-9]+[-_]*[A-Za-z0-9]*)\s*").Match(name); /*Match match = new Regex("[0-9]{4}-[0-9]{2}-[0-9]{2}").Match(name); * //if (match.Success) continue; * match = new Regex(@"(?:[0-9]{4}-[0-9]{2}-[0-9]{2})?\s?([A-Za-z0-9]+[-_]*[A-Za-z0-9]+[-_]*[A-Za-z0-9]*)\s*").Match(name); * if (match.Success) { * string matRes = match.Groups[1].Value; * textBox2.AppendText(matRes + "\r\n"); * Av av = new Av(); * av.Id = matRes.Trim(); * av.Path = folder; * avs.Add(av); * }//match sucess * else * textBox3.AppendText(name + "-无法解析番号\r\n");*/ textBox2.AppendText(name + "\r\n"); MatchCollection matchs = new Regex("[A-Za-z0-9]+[-_]?[A-Za-z0-9]+([-_]?[0-9])*").Matches(name); foreach (Match match in matchs) { string fh = match.Groups[0].Value.Trim(); if (fh.Length < 5) { continue; } //Match mat = new Regex(@"^[A-Za-z0-9-_;]+$").Match(fh); //if (!mat.Success) continue; int numIndex = getNumberIndex(fh); if (numIndex == -1) { continue; } Av av = new Av(); av.Id = fh; av.Path = folder; avs.Add(av); textBox2.AppendText("->" + fh + "\r\n"); IdSet.Add(fh); if (fh.IndexOf("-1") != -1 || fh.IndexOf("-2") != -1) { int fg = fh.LastIndexOf("-"); fh = fh.Substring(0, fg).Trim(); if (fh.Length < 6) { continue; } if (IdSet.Contains(fh)) { continue; } av = new Av(); av.Id = fh; av.Path = folder; avs.Add(av); textBox2.AppendText("->" + fh + "\r\n"); IdSet.Add(fh); } else if (fh.IndexOf("-") == -1 && fh.IndexOf("_") == -1) { fh = fh.Substring(0, numIndex) + "-" + fh.Substring(numIndex, fh.Length - numIndex); if (IdSet.Contains(fh)) { continue; } av = new Av(); av.Id = fh; av.Path = folder; avs.Add(av); textBox2.AppendText("->" + fh + "\r\n"); IdSet.Add(fh); } else if (fh.IndexOf("_") != -1) { fh = fh.Replace("_", "-"); if (IdSet.Contains(fh)) { continue; } av = new Av(); av.Id = fh; av.Path = folder; avs.Add(av); textBox2.AppendText("->" + fh + "\r\n"); IdSet.Add(fh); } else if (fh.IndexOf("-") != -1) { fh = fh.Replace("-", "_"); if (IdSet.Contains(fh)) { continue; } av = new Av(); av.Id = fh; av.Path = folder; avs.Add(av); textBox2.AppendText("->" + fh + "\r\n"); IdSet.Add(fh); } }//foreach match Match mat = new Regex(@"[Nn]\d{3,5}").Match(name); if (mat.Success) { string fh = mat.Groups[0].Value; if (!IdSet.Contains(fh)) { Av av = new Av(); av.Id = fh; av.Path = folder; avs.Add(av); textBox2.AppendText("->" + fh + "\r\n"); IdSet.Add(fh); } } mat = new Regex("[A-Za-z]+-[A-Za-z0-9]+").Match(name); if (mat.Success) { string fh = mat.Groups[0].Value; if (!IdSet.Contains(fh)) { Av av = new Av(); av.Id = fh; av.Path = folder; avs.Add(av); textBox2.AppendText("->" + fh + "\r\n"); IdSet.Add(fh); } } mat = new Regex("[A-Za-z]+[0-9]{3,8}").Match(name); if (mat.Success) { string fh = mat.Groups[0].Value; int numIndex = getNumberIndex(fh); fh = fh.Substring(0, numIndex) + "-" + fh.Substring(numIndex, fh.Length - numIndex); if (!IdSet.Contains(fh)) { Av av = new Av(); av.Id = fh; av.Path = folder; avs.Add(av); textBox2.AppendText("->" + fh + "\r\n"); IdSet.Add(fh); } } mat = new Regex("[0-9]+-[0-9]+[-]?[0-9]+").Match(name); if (mat.Success) { string fh = mat.Groups[0].Value; if (!IdSet.Contains(fh)) { Av av = new Av(); av.Id = fh; av.Path = folder; avs.Add(av); textBox2.AppendText("->" + fh + "\r\n"); IdSet.Add(fh); } } mat = new Regex("[A-Za-z]+[-_]?[0-9]{3,8}").Match(name); if (mat.Success) { string fh = mat.Groups[0].Value; fh = fh.Replace("_", "-"); if (!IdSet.Contains(fh)) { Av av = new Av(); av.Id = fh; av.Path = folder; avs.Add(av); textBox2.AppendText("->" + fh + "\r\n"); IdSet.Add(fh); } } } //for } //method
private void button2_Click(object sender, EventArgs e) { if (!Directory.Exists(textBox1.Text)) { MessageBox.Show("请先选择路径"); return; } avs = new List <Av>(); string[] folders = Directory.GetDirectories(textBox1.Text); foreach (string folder in folders) { int fg = folder.LastIndexOf("\\") + 1; string name = folder.Substring(fg, folder.Length - fg).Trim(); //Match match = new Regex(@"([A-Za-z0-9]+[-_]*?[A-Za-z0-9]+)\s*").Match(name); //Match match = new Regex(@"([A-Za-z0-9]+[-_]*[A-Za-z0-9]+[-_]*[A-Za-z0-9]*)\s*").Match(name); Match match = new Regex("[0-9]{4}-[0-9]{2}-[0-9]{2}").Match(name); if (match.Success) { continue; } match = new Regex(@"(?:[0-9]{4}-[0-9]{2}-[0-9]{2})?\s?([A-Za-z0-9]+[-_]*[A-Za-z0-9]+[-_]*[A-Za-z0-9]*)\s*").Match(name); if (match.Success) { string matRes = match.Groups[1].Value; textBox2.AppendText(matRes + "\r\n"); Av av = new Av(); av.Id = matRes.Trim(); av.Path = folder; avs.Add(av); //修改视频名称 改为符合 emby的规则 string[] extNames = new string[] { ".avi", ".mov", ".mpg", ".RA", ".RM", ".RMVB", ".WMV", ".mkv", ".mp4", ".asf", ".m4v" }; DirectoryInfo fdir = new DirectoryInfo(folder); FileInfo[] file = fdir.GetFiles(); if (file.Length != 0) //当前目录文件或文件夹不为空 { for (int i = 0; i < extNames.Length; i++) { int x = 0; foreach (FileInfo f in file) { if (extNames[i].ToLower().Equals(f.Extension.ToLower())) { x++; } } int y = 1; foreach (FileInfo f in file) //显示当前目录所有文件 { if (extNames[i].ToLower().Equals(f.Extension.ToLower())) { string newName = folder + "\\" + av.Id + (x > 1 ? "-cd" + y : "") + f.Extension; try { //记录文件名称 ChangeNameLogTxt(f.Name, newName); File.Move(f.FullName, newName); //File.Create(folder + "\\"+ (x > 1 ? "-cd" + y : "") + f.Name + ".old.name").Close(); } catch (Exception ex) { textBox3.AppendText(av.Id + "-修改视频文件名称错误 \r\n"); } y++; } //for files } } //for ext } //file } //match sucess else { textBox3.AppendText(name + "-无法解析番号\r\n"); } } //for } //method